Skip to content

Commit 2a72e90

Browse files
committed
extmod/vfs: Add option to use 1970 as Epoch.
By setting MICROPY_EPOCH_IS_1970 a port can opt to use 1970/1/1 as the Epoch for timestamps returned by stat(). And this setting is enabled on the unix and windows ports because that's what they use. Signed-off-by: Damien George <[email protected]>
1 parent 0385b21 commit 2a72e90

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

extmod/vfs_fat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
319319
(fno.ftime >> 5) & 0x3f,
320320
2 * (fno.ftime & 0x1f)
321321
);
322+
#if MICROPY_EPOCH_IS_1970
323+
seconds += TIMEUTILS_SECONDS_1970_TO_2000;
324+
#endif
322325
t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode
323326
t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
324327
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev

extmod/vfs_lfsx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) {
366366
ns = ns << 8 | mtime_buf[i - 1];
367367
}
368368
mtime = timeutils_seconds_since_2000_from_nanoseconds_since_1970(ns);
369+
#if MICROPY_EPOCH_IS_1970
370+
mtime += TIMEUTILS_SECONDS_1970_TO_2000;
371+
#endif
369372
}
370373
#endif
371374

ports/unix/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@
176176
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
177177
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
178178

179+
// VFS stat functions should return time values relative to 1970/1/1
180+
#define MICROPY_EPOCH_IS_1970 (1)
181+
179182
extern const struct _mp_print_t mp_stderr_print;
180183

181184
#if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__))

ports/windows/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
#define MICROPY_WARNINGS (1)
124124
#define MICROPY_PY_STR_BYTES_CMP_WARN (1)
125125

126+
// VFS stat functions should return time values relative to 1970/1/1
127+
#define MICROPY_EPOCH_IS_1970 (1)
128+
126129
extern const struct _mp_print_t mp_stderr_print;
127130

128131
#ifdef _MSC_VER

0 commit comments

Comments
 (0)