From 3c10cc381d430cac50581bd70533ce5766b52c9d Mon Sep 17 00:00:00 2001 From: John Polstra Date: Thu, 11 Jul 2019 18:32:59 -0700 Subject: [PATCH 1/2] Set the FAT filesystem timestamps of Blackbox files based on the local timezone, where possible. See issue #8539. On aircraft that have a valid real-time clock, "timezone_offset_minutes" can be set appropriately to record real times in the local timezone. It affects, for example, the real time displayed in the OSD and the log start time recorded in Blackbox files. This commit extends that functionality to the FAT filesystem timestamps of Blackbox files. According to Microsoft, FAT timestamps are supposed to reflect the local time where the files were created or modified. See, for example: https://docs.microsoft.com/en-us/windows/win32/sysinfo/file-times Both Windows and Mac OS adhere to the local timezone convention. Linux does not; however, I believe this is best viewed as a bug in Linux, since Microsoft owns the FAT filesystem. --- src/main/io/asyncfatfs/asyncfatfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/io/asyncfatfs/asyncfatfs.c b/src/main/io/asyncfatfs/asyncfatfs.c index 71d91f99b8..c8662aa327 100644 --- a/src/main/io/asyncfatfs/asyncfatfs.c +++ b/src/main/io/asyncfatfs/asyncfatfs.c @@ -2633,11 +2633,12 @@ static void afatfs_createFileContinue(afatfsFile_t *file) #ifdef USE_RTC_TIME // rtcGetDateTime will fill dt with 0000-01-01T00:00:00 // when time is not known. - dateTime_t dt; + dateTime_t dt, local_dt; rtcGetDateTime(&dt); if (dt.year != 0) { - fileDate = FAT_MAKE_DATE(dt.year, dt.month, dt.day); - fileTime = FAT_MAKE_TIME(dt.hours, dt.minutes, dt.seconds); + dateTimeUTCToLocal(&dt, &local_dt); + fileDate = FAT_MAKE_DATE(local_dt.year, local_dt.month, local_dt.day); + fileTime = FAT_MAKE_TIME(local_dt.hours, local_dt.minutes, local_dt.seconds); } #endif From 5293b0551765d01da93501017ff4eea419be03e5 Mon Sep 17 00:00:00 2001 From: John Polstra Date: Wed, 24 Jul 2019 10:20:31 -0700 Subject: [PATCH 2/2] Add a comment explaining the use of local time for FAT timestamps. --- src/main/io/asyncfatfs/asyncfatfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/io/asyncfatfs/asyncfatfs.c b/src/main/io/asyncfatfs/asyncfatfs.c index c8662aa327..6f8413f108 100644 --- a/src/main/io/asyncfatfs/asyncfatfs.c +++ b/src/main/io/asyncfatfs/asyncfatfs.c @@ -2636,6 +2636,7 @@ static void afatfs_createFileContinue(afatfsFile_t *file) dateTime_t dt, local_dt; rtcGetDateTime(&dt); if (dt.year != 0) { + // By tradition, FAT filesystem timestamps use local time. dateTimeUTCToLocal(&dt, &local_dt); fileDate = FAT_MAKE_DATE(local_dt.year, local_dt.month, local_dt.day); fileTime = FAT_MAKE_TIME(local_dt.hours, local_dt.minutes, local_dt.seconds);