Skip to content

Commit 8d629a9

Browse files
authored
Merge pull request #2367 from iot49/mtime
fix mtime on file creation
2 parents 817c4af + 73b6e5d commit 8d629a9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ports/nrf/fatfs_port.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@
2626

2727
#include "py/runtime.h"
2828
#include "lib/oofatfs/ff.h"
29+
#include "lib/timeutils/timeutils.h"
30+
#include "shared-bindings/rtc/RTC.h"
31+
#include "shared-bindings/time/__init__.h"
2932

3033
DWORD get_fattime(void) {
31-
// TODO: Implement this function. For now, fake it.
32-
return ((2016 - 1980) << 25) | ((12) << 21) | ((4) << 16) | ((00) << 11) | ((18) << 5) | (23 / 2);
34+
#if CIRCUITPY_RTC
35+
timeutils_struct_time_t tm;
36+
common_hal_rtc_get_time(&tm);
37+
return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) |
38+
(tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1);
39+
#else
40+
return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2);
41+
#endif
3342
}

0 commit comments

Comments
 (0)