Issue1665292
Created on 2007-02-21 14:55 by christian.heimes, last changed 2007-07-12 14:46 by christian.heimes.
| File name |
Uploaded |
Description |
Edit |
Remove |
|
timedelta_intfloat.diff
|
christian.heimes,
2007-03-23 02:38
|
timedelta cast to and compare with int, long, float |
|
|
|
msg51905 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2007-02-21 14:55 |
|
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
|
|
msg51906 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2007-02-21 16:16 |
|
File Added: timedelta.patch
|
|
msg51907 - (view) |
Author: Johann C. Rocholl (jcrocholl) |
Date: 2007-03-09 16:33 |
|
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.
|
|
msg51908 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2007-03-23 02:38 |
|
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
|
|
msg51909 - (view) |
Author: Jason Orendorff (jorend) |
Date: 2007-04-20 22:19 |
|
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.
|
|
msg51910 - (view) |
Author: Björn Lindqvist (sonderblade) |
Date: 2007-06-06 16:52 |
|
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.
|
|
msg51911 - (view) |
Author: Georg Brandl (georg.brandl) |
Date: 2007-07-12 08:22 |
|
Agreed. (A separate patch can be submitted for totimestamp().)
|
|
msg51912 - (view) |
Author: Christian Heimes (christian.heimes) |
Date: 2007-07-12 14:46 |
|
Oh, I didn't know that hash() *AND* == are used in dictionaries. Well, you are the experts and I'm just a noob. :)
I'm going to remove the compare part from my patch. I still like to get int(td) and float(td) into Python. I find it very useful.
|
|
| Date |
User |
Action |
Args |
| 2007-02-21 14:55:01 | christian.heimes | create | |
|