Skip to content

[BUG] ZoneInfo does not support datetime.Time and utcoffset can't be retrieved #117598

Description

@07pepa

Bug report

Bug description:

this function does not support datetime.time

(dt.toordinal() -EPOCHORDINAL) *86400

deftest():
fromzoneinfoimportZoneInfofromdatetimeimporttimet=time(12, 4, 5, 123456, tzinfo=ZoneInfo("Europe/Prague"), fold=1)
ift.tzinfo.utcoffset(None) isNone:
# if prevuous does not work this should but fails with# AttributeError: 'datetime.time' object has no attribute 'toordinal't.tzinfo.utcoffset(t)

i propose checking if instance is time and then skip to ordinal like so

def_get_local_timestamp(self, dt):
return (
(dt.toordinal() -EPOCHORDINAL) *86400ifnotisinstance(dt, time) else0+dt.hour*3600+dt.minute*60+dt.second
)

this issue is blocker for pydantic/speedate#62

if this is confirmed i am open to do PR or leave it to someone else Maybe there is something more i am not seeing

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions