This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bug in datetime.datetime.timestamp
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, kliano
Priority: normal Keywords:

Created on 2017-09-29 22:21 by kliano, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg303362 - (view) Author: Kadir Liano (kliano) Date: 2017-09-29 22:21
datetime.datetime(2014,3,9,2).timestamp() returns 1394352000.0
datetime.datetime(2014,3,9,3).timestamp() returns 1394352000.0
msg303380 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-09-30 00:40
This is a daylight savings time folding problem. Without a timezone, those are in fact the same point in time, at least in my timezone (US Eastern).

If you specify a timezone, you'll see the difference:

datetime.datetime(2014,3,9,2,tzinfo=datetime.timezone(datetime.timedelta(0))).timestamp() -> 1394330400.0

datetime.datetime(2014,3,9,3,tzinfo=datetime.timezone(datetime.timedelta(0))).timestamp() -> 1394334000.0

These are 3600 seconds, or one hour, apart.
msg303385 - (view) Author: Kadir Liano (kliano) Date: 2017-09-30 01:32
The datetime object returned by strptime() does not have tzinfo.  Whatever default timezone that was chosen should produce consistent timestamp.  Reading a sequential datetime string and converting it to a sequence of timestamp results in expected time folding.

datetime.datetime.strptime(dtstr,fmt).timestamp()
History
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75825
2017-09-30 01:32:44klianosetmessages: + msg303385
2017-09-30 00:40:40eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg303380

resolution: not a bug
stage: resolved
2017-09-29 22:21:28klianocreate