Issue2736
Created on 2008-05-01 21:03 by tebeka, last changed 2008-05-11 08:25 by Neil Muller.
| msg66045 (view) |
Author: Miki Tebeka (tebeka) |
Date: 2008-05-01 21:03 |
|
If you try to convert datetime objects to seconds since epoch and back
it will not work since the microseconds get lost:
>>> dt = datetime(2008, 5, 1, 13, 35, 41, 567777)
>>> seconds = mktime(dt.timetuple())
>>> datetime.fromtimestamp(seconds) == dt
False
Current fix is to do
>>> seconds += (dt.microsecond / 1000000.0)
>>> datetime.fromtimestamp(seconds) == dt
True
|
| msg66140 (view) |
Author: Pedro Werneck (werneck) |
Date: 2008-05-03 02:18 |
|
That's expected as mktime is just a thin wrapper over libc mktime() and
it does not expect microseconds. Changing time.mktime doesn't seems an
option, so the best alternative is to implement a method in datetime
type. Is there a real demand for C code implementing this to justify it?
|
| msg66532 (view) |
Author: Simon Cross (hodgestar) |
Date: 2008-05-10 14:55 |
|
Attached a patch which adds a .totimetuple(...) method to
datetime.datetime and tests for it.
The intention is that the dt.totimetuple(...) method is equivalent to:
mktime(dt.timetuple()) + (dt.microsecond / 1000000.0)
|
| msg66539 (view) |
Author: Simon Cross (hodgestar) |
Date: 2008-05-10 15:54 |
|
Patch adding documentation for datetime.totimestamp(...).
|
| msg66601 (view) |
Author: Miki Tebeka (tebeka) |
Date: 2008-05-11 06:12 |
|
I think the name is not good, should be "toepoch" or something like that.
|
| msg66610 (view) |
Author: Neil Muller (Neil Muller) |
Date: 2008-05-11 08:25 |
|
datetime has fromtimestamp already, so using totimestamp keeps naming
consistency (see toordinal and fromordinal).
|
|
| Date |
User |
Action |
Args |
| 2008-05-11 08:25:30 | Neil Muller | set | nosy:
+ Neil Muller messages:
+ msg66610 |
| 2008-05-11 06:12:39 | tebeka | set | messages:
+ msg66601 |
| 2008-05-10 20:48:17 | davidfraser | set | nosy:
+ davidfraser |
| 2008-05-10 15:54:41 | hodgestar | set | files:
+ add-datetime-totimestamp-method-docs.diff messages:
+ msg66539 |
| 2008-05-10 14:55:39 | hodgestar | set | files:
+ add-datetime-totimestamp-method.diff keywords:
+ patch messages:
+ msg66532 nosy:
+ hodgestar |
| 2008-05-03 02:18:59 | werneck | set | nosy:
+ werneck messages:
+ msg66140 |
| 2008-05-01 21:03:25 | tebeka | create | |
|