Problem working with localized timezones.

Issue #6 resolved
Hans Peter Hagblom
created an issue

I have a problem with that the offset gets wrong when working with timezones.

Below is a snippet that shows the problem, there is a date which is considered to be CEST and thus have an offset of 2 hours. When printing this I get the offset of 1 hour.

In [47]: tz_sthlm.localize(datetime.datetime.strptime('2017-05-01', '%Y-%m-%d')) Out[47]: datetime.datetime(2017, 5, 1, 0, 0, tzinfo=<DstTzInfo 'Europe/Stockholm' CEST+2:00:00 DST>)

In [48]: rfc3339.format(tz_sthlm.localize(datetime.datetime.strptime('2017-05-01', '%Y-%m-%d'))) Out[48]: '2017-05-01T00:00:00+01:00'

I looked into the code and found (row 79) return _timedelta_to_seconds(date.dst() or date.utcoffset())

Where the utc delta, is the value of the daylight savings adjustment and not the actual utc offset.

return _timedelta_to_seconds(date.utcoffset())

Might work better I think?

I might be able to supply a fix for this.

Comments (2)

  1. Henry PrĂȘcheur repo owner

    I did what you suggested, I don't see any reason to keep the or date.dts(). I made a new release on PyPi with the change.

    Thank-you for this report, and sorry it took me so long.

  2. Log in to comment