-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mtime incorrect in fatfs during daylight saving time (IDFGH-7467) #9039
Comments
Thanks for reporting this @lbernstone. I vaguely remember there being some discussion on this before, and some reason why the filesystem works the way it does, but I can't find it right now. We'll investigate this. The difference is probably indeed one hour (3600 seconds), but FATFS keeps time at 2-second precision, so instead of mtime=1653641641 (exactly 3600 seconds difference) you got 1653641640. |
Only thing I see in the history is this #1369 |
mktime function uses tm_isdst member as an indicator whether the time stamp is expected to be in daylight saving time (1) or not (0). FAT filesystem uses local time as mtime, so no information about DST is available from the filesystem. According to mktime documentation, tm_isdst can be set to -1, in which case the C library will try to determine if DST was or wasn't in effect at that time, and will set UTC time accordingly. Note that the conversion from UTC to local time and then back to UTC (time_t -> localtime_r -> FAT timestamp -> mktime -> time_t) does not always recover the same UTC time. In particular, the local time in the hour before DST comes into effect can be interpreted as "before DST" or "after DST", which would correspond to different UTC values. In this case which option the C library chooses is undefined. Closes #9039 Originally reported in espressif/arduino-esp32#6786
mktime function uses tm_isdst member as an indicator whether the time stamp is expected to be in daylight saving time (1) or not (0). FAT filesystem uses local time as mtime, so no information about DST is available from the filesystem. According to mktime documentation, tm_isdst can be set to -1, in which case the C library will try to determine if DST was or wasn't in effect at that time, and will set UTC time accordingly. Note that the conversion from UTC to local time and then back to UTC (time_t -> localtime_r -> FAT timestamp -> mktime -> time_t) does not always recover the same UTC time. In particular, the local time in the hour before DST comes into effect can be interpreted as "before DST" or "after DST", which would correspond to different UTC values. In this case which option the C library chooses is undefined. Closes #9039 Originally reported in espressif/arduino-esp32#6786
Environment
git describe --tags
to find it): v4.4.1xtensa-esp32-elf-gcc --version
to find it): riscv32-esp-elf-gcc8_4_0-esp-2021r2-patch3-linux-amd64Problem Description
When a timezone is set with DST, and time is set inside DST, file modified time (mtime) is 3599 seconds off. Weird number, maybe something is supposed to be one hour diff, but isn't multiplied?
Expected Behavior
System time and file written time should be identical
Actual Behavior
Steps to reproduce
The text was updated successfully, but these errors were encountered: