[ python-Patches-1665292 ] Datetime enhancements

"SourceForge.net" <[email protected]>
Newsgroups gmane.comp.python.patches
Message-ID <[email protected]>
Patches item #1665292, was opened at 2007-02-21 15:55
Message generated for change (Comment added) made by sonderblade
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1665292&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Christian Heimes (tiran)
Assigned to: Nobody/Anonymous (nobody)
Summary: Datetime enhancements

Initial Comment:
I'm proposing some small enhancements to the datetime module:

Add a totimestamp() method to datetime.datetime that returns the seconds since 1/1/1970 00:00:00. The datetime class has already a fromtimestamp() factory but is missing a totimestamp() method.

Add a __int__() and __float__() method to datetime.timedelta which return the seconds (seconds + 86400 * days) as int and seconds + miliseconds as float. It would save some typing if somebody needs an integer representation of a timedelta object :]

The datetime module is implemented in C. I've never written a Python C extension so I can't help with a patch.

Thx

----------------------------------------------------------------------

Comment By: Björn Lindqvist (sonderblade)
Date: 2007-06-06 18:52

Message:
Logged In: YES 
user_id=51702
Originator: NO

Seems like it is safe to close this patch. If you need a timedelta in
seconds it isn't that much work to write td.days*86400+td.seconds to
convert it to an int. Converting it to a float doesn't seem useful enough.

----------------------------------------------------------------------

Comment By: Jason Orendorff (jorend)
Date: 2007-04-21 00:19

Message:
Logged In: YES 
user_id=18139
Originator: NO

tiran, having timedelta objects comparable with numbers is going a bit too
far.  You end up with:

timedelta(0, 1) == 1   but   hash(timedelta(0, 1)) != hash(1)

This breaks dictionaries.


----------------------------------------------------------------------

Comment By: Christian Heimes (tiran)
Date: 2007-03-23 03:38

Message:
Logged In: YES 
user_id=560817
Originator: YES

Here is a new patch. I've updated the documentation and enhanced the
compare function to compare with ints, longs and floats. This part of the
patch should be complete. I'm going to submit a different patch for the
other features later. Shall I start a new tracker entry?
File Added: timedelta_intfloat.diff

----------------------------------------------------------------------

Comment By: Johann C. Rocholl (jcrocholl)
Date: 2007-03-09 17:33

Message:
Logged In: YES 
user_id=656137
Originator: NO

The patch confuses microseconds with milliseconds.
The divisor in delta_float should be 1000000.0, not 1000.0.
The result of the last test should be 86401.000001, not 86401.001.

----------------------------------------------------------------------

Comment By: Christian Heimes (tiran)
Date: 2007-02-21 17:16

Message:
Logged In: YES 
user_id=560817
Originator: YES

File Added: timedelta.patch

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1665292&group_id=5470

_______________________________________________
Patches mailing list
[email protected]
http://mail.python.org/mailman/listinfo/patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.