Skip to content

Commit 0712c95

Browse files
committed
fix mtime on file creation
1 parent 19ac8ae commit 0712c95

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ports/nrf/fatfs_port.c

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

2727
#include "py/runtime.h"
2828
#include "lib/oofatfs/ff.h"
29+
#include "lib/timeutils/timeutils.h"
30+
31+
extern void common_hal_rtc_get_time(timeutils_struct_time_t *tm);
32+
extern void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm);
2933

3034
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);
35+
#if CIRCUITPY_RTC
36+
timeutils_struct_time_t tm;
37+
common_hal_rtc_get_time(&tm);
38+
return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) |
39+
(tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1);
40+
#else
41+
return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2);
42+
#endif
3343
}

0 commit comments

Comments
 (0)