New submission from Jim Carroll <j...@carroll.com>:
We encountered an interesting mtime problem in the field, that I believe represents a bug in python's datetime timestamp handling. A file stored on a windows server had the last-modified date '1/1/4501' (that's the year 4501). os.path.getmtime() returns a valid timestamp, but when we try to pass this back into datetime.datetime.fromtimestamp() we get an OSError. I understand that generating an OSError when the date exceeds the epoch support on Windows is consistent with the python docs. In our case, the date is clearly supported by Windows as evidenced by it's storage in the filesystem. Further, we can reproduce the situation using the cygwin touch utility. >>> import os, datetime >>> os.system('touch -d "4501-01-01" file.txt') >>> t = os.path.getmtime('file.txt') >>> datetime.datetime.fromtimestamp(t) Traceback (most recent call last): File "<stdin>", line 1, in <module> OSError: [Errno 22] Invalid argument What's interesting is we can manually convert it with reference to the epoch >>> datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=t) datetime.datetime(4501, 1, 1, 5, 0) We used Windows 10-Pro for our tests running python 3.8.1. ---------- components: Library (Lib) messages: 369895 nosy: jamercee priority: normal severity: normal status: open title: python3 fromtimestamp generates OSError versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40771> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com