Django time zone: how to compare the time difference in days between 2 days via DST

I am currently working on a calendar project using django that requires some time calculation, and I ran into a problem when I try to calculate the time difference between two datetime objects. When I create time, I do:

tz = timezone.get_default_timezone()
curr_day = timezone.make_aware(datetime.datetime(curr_day.year,
                                                 curr_day.month,
                                                 curr_day.day,
                                                 0, 0, 0), tz)

When I create it, only the date is important, but since the object must use the date and time for historical reasons, I added three 0 for the hour, minute, second.

My program is trying to compare if 2 datetime has a difference of 1 in days, so I do

if (event1 - event2).days == 1:
    # do something

The problem occurs when I try to compare 03/12/2017 and 03/13/2017 (03/12/2017 - DST).

event1
datetime.datetime(2017, 3, 13, 4, 0, tzinfo=<UTC>)

event2
datetime.datetime(2017, 3, 12, 5, 0, tzinfo=<UTC>)

(event1-event2).days
0

, , , , 1. , ? !

+4
1

, , 0, :

In [79]: import datetime as DT
In [80]: (DT.datetime.combine(event1, DT.time(0)) - DT.datetime.combine(event2, DT.time(0))).days
Out[80]: 1

, "" , , 1 0 .

+3

All Articles