[Patches] [ python-Patches-1665292 ] Datetime enhancements

SourceForge.net noreply at sourceforge.net
Sat Apr 21 00:19:16 CEST 2007


Patches item #1665292, was opened at 2007-02-21 09:55
Message generated for change (Comment added) made by jorend
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: Jason Orendorff (jorend)
Date: 2007-04-20 18: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-22 22: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 11: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 11: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


More information about the Patches mailing list