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.
Created on 2017年01月22日 17:47 by Eli Collins, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| dump_timestamp_output.py | Eli Collins, 2017年01月22日 17:47 | |||
| Messages (5) | |||
|---|---|---|---|
| msg286021 - (view) | Author: Eli Collins (Eli Collins) * | Date: 2017年01月22日 17:47 | |
I've found an odd behavior when passing very large values to ``datetime.datetime.utcfromtimestamp()`` and ``.fromtimestamp()`` under python 3.6. Under python 3.5, ``utcfromtimestamp(1<<40)`` would throw a ValueError that the year was out of range. Under python 3.6, this now returns a datetime in year 36812 (which seems reasonable given the input). The unexpected behavior occurs when increasing the bits passed: ``utcfromtimestamp(1<<41)`` returns a datetime with a *smaller* year (6118). This pattern proceeds as the bits are increased, with the years increasing & then wrapping around again, up to the point where it exceeds time_t (at that point, python 3.6 throws the same OSError as 3.5). It looks to me like 3.6 dropped a bounds check somewhere, and is now truncating high bits off the resulting year? --- Attached is the "dump_timestamp_output.py" script that I was using to examine boundary behavior of utctimestamp() when I found this bug. System was running Linux Mint 18.1 x86_64, using the python 3.6.0 build from https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes (ubuntu's python 3.6.0 build also shows this behavior). |
|||
| msg286025 - (view) | Author: Marc-Andre Lemburg (lemburg) * (Python committer) | Date: 2017年01月22日 18:52 | |
According to the datetime.h file, the valid range for year is 1-9999, so it's a bit surprising that Python 3.6 allows dates outside this range. Internally, the year is represented using 2 bytes, so you could represent years outside the range and up to 65535 as well. Here's what mxDateTime outputs for the given timestamps: >>> from mx.DateTime import * >>> DateTimeFromTicks(1<<40) <mx.DateTime.DateTime object for '36812-02-20 01:36:16.00' at 7f17a38a2390> >>> DateTimeFromTicks(1<<41) <mx.DateTime.DateTime object for '71654-04-10 03:12:32.00' at 7f17a1bdf858> |
|||
| msg286034 - (view) | Author: Alexander Belopolsky (belopolsky) * (Python committer) | Date: 2017年01月22日 23:45 | |
This looks like a duplicate of issue #29100 ("datetime.fromtimestamp() doesn't check min/max year anymore: regression of Python 3.6"). |
|||
| msg286091 - (view) | Author: Eli Collins (Eli Collins) * | Date: 2017年01月23日 15:16 | |
My apologies, I think Alexander is right, this is a duplicate of #29100 I'd seen the first message in that issue talking about a core dump, and thought this was different problem; but I see the scope of the issue broadened to cover general bounds issues in later messages. Reviewing the fix & the tests from that issue's patches, it looks like exactly this case. |
|||
| msg286360 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2017年01月27日 14:58 | |
Since it's a duplicate, I close this issue. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:42 | admin | set | github: 73532 |
| 2017年01月27日 14:58:10 | vstinner | set | status: open -> closed superseder: datetime.fromtimestamp() doesn't check min/max year anymore: regression of Python 3.6 messages: + msg286360 |
| 2017年01月27日 14:57:37 | vstinner | set | title: datetime.utcfromtimestamp() returns strange result for very large values -> datetime doesn't check for min/max dates anymore in Python 3.6.0 => crash |
| 2017年01月23日 15:16:59 | Eli Collins | set | resolution: duplicate messages: + msg286091 |
| 2017年01月22日 23:45:01 | belopolsky | set | keywords:
+ 3.6regression nosy: + vstinner messages: + msg286034 |
| 2017年01月22日 18:52:42 | lemburg | set | messages: + msg286025 |
| 2017年01月22日 18:24:57 | serhiy.storchaka | set | nosy:
+ lemburg, belopolsky |
| 2017年01月22日 17:47:34 | Eli Collins | create | |