Issue2256

classification
Title: os.stat returns wrong mtime and atime if these times are in DST on Windows
Type: Severity: normal
Components: Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: pekka.klarck, zyasoft
Priority: Keywords:

Created on 2015-01-16.01:19:34 by pekka.klarck, last changed 2015-02-09.23:31:38 by zyasoft.

Messages
msg9407 (view) Author: Pekka Klärck (pekka.klarck) Date: 2015-01-16.01:19:32
It seems that with Jython 27b4 preview on Windows os.stat returns wrong mtime and atime if these times are in DST. This problem doesn't occur on Linux, with Jython 2.5, or with files with mtime and atime 

To reproduce:
1) Create a new file and verify that Python and Jython 2.7 return same mtime and atime:
E:\>python -c "open('test.txt', 'w').close()"

E:\>python -c "import os; print os.stat('test.txt')"
nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size=0L, st_atime=1421370960L, st_mtime=1421370960L, st_ctime=1421370960L)

E:\>jython -c "import os; print os.stat('test.txt')"
posix.stat_result(st_mode=33188, st_ino=0, st_dev=4L, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1421370960, st_mtime=1421370960, st_ctime=1421370960)


2) Set mtime and atime to some time in June, 2015 and verify that Python returns those times:
E:\>python -c "import os; os.utime('test.txt', (1433109600, 1433109600))"

E:\>python -c "import os; print os.stat('test.txt')"
nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=
0, st_size=0L, st_atime=1433109600L, st_mtime=1433109600L, st_ctime=1421370375L)


3) Jython returns different mtime and atime:
E:\>jython -c "import os; print os.stat('test.txt')"
posix.stat_result(st_mode=33188, st_ino=0, st_dev=4L, st_nlink=1, st_uid=0, st_g
id=0, st_size=0, st_atime=1433106000, st_mtime=1433106000, st_ctime=1421370375)


The difference between times returned by Jython and times set and verified with Python is 3600s i.e. 1h. I guess this has something to do with DST, especially because files created now in standard time have correct mtime and atime.
msg9410 (view) Author: Jim Baker (zyasoft) Date: 2015-01-16.15:14:38
Related to http://bugs.jython.org/issue1658, with same solution
msg9412 (view) Author: Pekka Klärck (pekka.klarck) Date: 2015-01-16.16:10:58
Are you certain this is related to #1658? The problem occurs regardless the file name.
msg9465 (view) Author: Jim Baker (zyasoft) Date: 2015-01-29.13:50:51
This is worked around in CPython posixmodule.c, per the source:

#ifdef MS_WINDOWS
/* The CRT of Windows has a number of flaws wrt. its stat() implementation:
   - time stamps are restricted to second resolution
   - file modification times suffer from forth-and-back conversions between
     UTC and local time
   Therefore, we implement our own stat, based on the Win32 API directly.
*/

Other than using Java 7's DosFileAttributes instead of the Win32 API directly, our fix for this and #1658 will follow what is done in CPython.
msg9472 (view) Author: Jim Baker (zyasoft) Date: 2015-02-02.20:11:39
Fixed as of https://hg.python.org/jython/rev/e04fa277ce19
History
Date User Action Args
2015-02-09 23:31:38zyasoftsetstatus: pending -> closed
2015-02-02 20:11:39zyasoftsetstatus: open -> pending
assignee: zyasoft
resolution: fixed
messages: + msg9472
2015-01-29 13:50:52zyasoftsetmessages: + msg9465
2015-01-16 16:10:58pekka.klarcksetmessages: + msg9412
2015-01-16 15:14:38zyasoftsetnosy: + zyasoft
messages: + msg9410
2015-01-16 01:19:34pekka.klarckcreate