Alexander Belopolsky <belopol...@users.sourceforge.net> added the comment:

Let me state my position on this issue once again.  Converting datetime values 
to float is easy.   If your dt is a naive instance representing UTC time:

   timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)

If your dt is an aware instance:

   timestamp = (dt - datetime(1970, 1, 1, tzinfo=timezone.utc)) / 
timedelta(seconds=1)

These recipes are easy to adjust for your application needs.  One application 
may want millisecond or microsecond ticks, another might want to carry 
subsecond presision in a separate integer, third may want to avoid timestamps 
before 1970 or after 2038 or ignore microseconds altogether.  No matter what a 
hypothetical datetime.epoch() will provide, most of applications will need to 
add a line or two to its code to serve their needs. Applications that will use 
dt.epoch() naively without thinking what dt represents (say local or UTC) will 
be buggy.

The only related feature that I think is missing from datetime module is the 
ability to obtain local time as an aware datetime instance and to convert a 
naive datetime instance assumed to represent local time to an aware one.

This is the subject of #9527, but there is a resistance to adding that feature.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue2736>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to