[Python-Dev] Issue 2736: datetimes and Unix timestamps
Alexander Belopolsky
alexander.belopolsky at gmail.com
Mon Jun 4 20:46:25 CEST 2012
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.
The only right solution is to lobby your government to abandon the DST.
More information about the Python-Dev
mailing list