Skip to content

Parser should set fold attribute in ambiguous times with time zone information if possible #320

@pganssle

Description

@pganssle

Running this with the TZ environment set to US/Eastern:

>>> from dateutil import parser, tz
>>> dt = parser.parse('2011-11-06 01:30:00 EST')
>>> dt.tzname()
'EDT'
>>> tz.enfold(dt, fold=1).tzname()
'EST'

This is a situation where we start with an unambiguous date but because of how the tzlocal() parsing works, end up with an ambiguous date. Right now this mainly affects tzlocal() but it may also be useful in this situation:

>>> from dateutil import parser, tz
>>> tzinfos = {'EDT': tz.gettz('US/Eastern'), 'EST': tz.gettz('US/Eastern')}
>>> dt = parser.parse('2011-11-06 01:03:00 EST', tzinfos=tzinfos)
>>> dt.tzname()
'EDT'

This last one is dubious because it's not guaranteed that the tzname is going to match one of the keywords, but it's probably worth trying when the date is ambiguous, just in case. That said, if you're specifying tzinfos, you might as well just specify tzoffset values and then use .astimezone() to convert to whatever time zone you actually want to be in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions