[Python-Dev] Issue 2736: datetimes and Unix timestamps

Guido van Rossum guido at python.org
Mon Jun 4 21:05:10 CEST 2012


On Mon, Jun 4, 2012 at 11:46 AM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> On Mon, Jun 4, 2012 at 1:12 PM, Guido van Rossum <guido at python.org> wrote:
>> ...  I heard
>> a colleague complain that he'd lost several hours trying to figure out
>> how to determine whether two datetimes were within 24h of each other,
>> getting confused by what was happening when the two were on different
>> sides of a DST transition (or worse, in the middle of one).
>
> I don't think this is a problem that a general purpose module such as
> datetime can resolve.  Assuming that all instances are timezone aware,
> either of the following tests may be appropriate for a given
> application:
>
> 1) dt1 - dt2 == timedelta(1)
>
> 2) dt1.date() - dt2.date() == timedelta(1) and dt1.time() == dt2.time()
>
> If your application deals with physical processes - (1) may be
> appropriate, but if it deals with human schedules - (2) may be
> appropriate.

You seem to have misread -- I don't want to check if they are exactly
24 hours apart. I want to check if they are at most 24 hours apart.
The timezone can be assumed to be the same on dt1 and dt2.

A variant of (1) was what was needed -- the user had just confused
themselves into thinking they needed to convert to UTC first, and done
a poor job of that. This is a common situation.

> The only right solution is to lobby your government to abandon the DST.

That's not helping.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list