[ python-Bugs-878424 ] Difference between two datetimes does not account for DST

SourceForge.net noreply at sourceforge.net
Fri Jan 16 13:22:28 EST 2004


Bugs item #878424, was opened at 2004-01-16 12:58
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=878424&group_id=5470

Category: Extension Modules
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Kirill Lapshin (llirik)
>Assigned to: Tim Peters (tim_one)
Summary: Difference between two datetimes does not account for DST

Initial Comment:
Hello,

I am having problems with using timezone aware datetime
objects across DST shift within the same timezone.

Citing documentation:

------
If both are naive, or both are aware and have the same
tzinfo  member, the tzinfo members are ignored, and the
result is a timedelta object t such that datetime2 + t
== datetime1. No time zone adjustments are done in this
case.

If both are aware and have different tzinfo members,
a-b acts as if a and b were first converted to naive
UTC datetimes first. The result is
(a.replace(tzinfo=None) - a.utcoffset()) -
(b.replace(tzinfo=None) - b.utcoffset()) except that
the implementation never overflows. 
-------

The problem is that if both datetimes have the same
tzinfo, they still may be in different "timezones" --
one in DST and the other in standard time. 

Suppose I am using US/Eastern timezone, then 4-Apr-04
is the date when DST starts. Lets create two datetimes
one (lets call it d1) for 00:00 and the other (d2) for
05:00. Now lets print the

print d1, d2, d2-d1, d2.astimezone(UTC)-d1.astimezone(UTC)

The result is 

2004-04-04 00:00:00-05:00 2004-04-04 05:00:00-04:00
5:00:00 4:00:00

Which is _very_ confusing! I think even if both
datetimes share the same tzinfo object you still have
to calculate it in "aware", not "naive" way.

Kind regards,
Kirill Lapshin

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=878424&group_id=5470



More information about the Python-bugs-list mailing list