scrapinghub / dateparser

python parser for human readable dates
BSD 3-Clause "New" or "Revised" License
2.55k stars 465 forks source link

Daylight Saving Time (DST) not observed for US/Central (CST) #443

Open deangoodmanson opened 6 years ago

deangoodmanson commented 6 years ago

CST DST UTC offset is -5 in summer, -6 in winter. -6 is being used in summer.

In [1]: import dateparser
In [2]: st="Aug 16, 2018, 4:20:18 PM CST"
In [3]: start = dateparser.parse(st)
In [4]: start
Out[4]: datetime.datetime(2018, 8, 16, 16, 20, 18, tzinfo=<StaticTzInfo 'CST'>)
In [5]: start.isoformat()
Out[5]: '2018-08-16T16:20:18-06:00'
In [20]: start.tzname()
Out[20]: 'CST'
deangoodmanson commented 6 years ago

Potentially related https://github.com/scrapinghub/dateparser/blob/master/dateparser/utils/__init__.py#L93

via Stack Overflow "pytz.astimezone not accounting for daylight savings?" http://pytz.sourceforge.net/#localized-times-and-date-arithmetic

saml-dev commented 5 years ago

That's because you're using CST (central standard time) in the string, which is specifically not CDT (central daylight time). I would test removing the timezone from your string, then changing

start = dateparser.parse(st)

to

start = dateparser.parse(st, settings={'TIMEZONE': 'US/Central'})

That should give you the results you're looking for. I think using US/Central (and therefore not specifying CST vs CDT) will account for daylight savings automatically.