3 ms·
...negative timezone offsets allow a date to always be true, but positive ones allow it to be false at UTC midnight. I haven't had my tea yet, but is this true
by jessaustin 13y ago
...negative timezone offsets allow a date to always be true, but positive ones allow it to be false at UTC midnight.
I haven't had my tea yet, but is this true? ISTM that if a positive offset can be false in the AM, a negative one might be false in the PM.
- plorkyeran 13y agoThe actual check is for if time_in_minutes == tz_offset_in_minutes. The problem is that times are always positive, so this check doesn't work if the offset is negative. The correct implementation would be time_in_minutes == (tz_offset_in_minutes + minutes_in_day) % minutes_in_day.
- jessaustin 13y agoThanks for the info. I've confirmed this for myself now: class Offset(tzinfo): def __init__(self, offset): self.offset = offset def utcoffset(self, dt): return self.offset >>> bool(time(1, 0, tzinfo=Offset(timedelta(hours=1)))) False >>> bool(time(23, 0, tzinfo=Offset(timedelta(hours=-1)))) True Although this is kind of funny, because for time.hour, 23 and -1 should be the same thing: >>> bool(time(23, 0, tzinfo=Offset(timedelta(hours=23)))) False I'm convinced: legacy behavior is wrong and should be changed.