summaryrefslogtreecommitdiffstatshomepage
path: root/extmod
diff options
context:
space:
mode:
Diffstat (limited to 'extmod')
-rw-r--r--extmod/vfs_fat.c5
-rw-r--r--extmod/vfs_lfs.c4
-rw-r--r--extmod/vfs_lfsx.c6
3 files changed, 6 insertions, 9 deletions
diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c
index ace5ba5b65..95b7ad9944 100644
--- a/extmod/vfs_fat.c
+++ b/extmod/vfs_fat.c
@@ -311,7 +311,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
} else {
mode |= MP_S_IFREG;
}
- mp_int_t seconds = timeutils_seconds_since_2000(
+ mp_int_t seconds = timeutils_seconds_since_epoch(
1980 + ((fno.fdate >> 9) & 0x7f),
(fno.fdate >> 5) & 0x0f,
fno.fdate & 0x1f,
@@ -319,9 +319,6 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
(fno.ftime >> 5) & 0x3f,
2 * (fno.ftime & 0x1f)
);
- #if MICROPY_EPOCH_IS_1970
- seconds += TIMEUTILS_SECONDS_1970_TO_2000;
- #endif
t->items[0] = MP_OBJ_NEW_SMALL_INT(mode); // st_mode
t->items[1] = MP_OBJ_NEW_SMALL_INT(0); // st_ino
t->items[2] = MP_OBJ_NEW_SMALL_INT(0); // st_dev
diff --git a/extmod/vfs_lfs.c b/extmod/vfs_lfs.c
index a53f66f2d6..9cf3eb1108 100644
--- a/extmod/vfs_lfs.c
+++ b/extmod/vfs_lfs.c
@@ -26,6 +26,7 @@
#include "py/runtime.h"
#include "py/mphal.h"
+#include "lib/timeutils/timeutils.h"
#include "extmod/vfs.h"
#include "extmod/vfs_lfs.h"
@@ -126,7 +127,8 @@ const char *mp_vfs_lfs2_make_path(mp_obj_vfs_lfs2_t *self, mp_obj_t path_in);
mp_obj_t mp_vfs_lfs2_file_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in);
STATIC void lfs_get_mtime(uint8_t buf[8]) {
- uint64_t ns = mp_hal_time_ns();
+ // On-disk storage of timestamps uses 1970 as the Epoch, so convert from host's Epoch.
+ uint64_t ns = timeutils_nanoseconds_since_epoch_to_nanoseconds_since_1970(mp_hal_time_ns());
// Store "ns" to "buf" in little-endian format (essentially htole64).
for (size_t i = 0; i < 8; ++i) {
buf[i] = ns;
diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c
index d00df53104..35d5f03c59 100644
--- a/extmod/vfs_lfsx.c
+++ b/extmod/vfs_lfsx.c
@@ -365,10 +365,8 @@ STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) {
for (size_t i = sizeof(mtime_buf); i > 0; --i) {
ns = ns << 8 | mtime_buf[i - 1];
}
- mtime = timeutils_seconds_since_2000_from_nanoseconds_since_1970(ns);
- #if MICROPY_EPOCH_IS_1970
- mtime += TIMEUTILS_SECONDS_1970_TO_2000;
- #endif
+ // On-disk storage of timestamps uses 1970 as the Epoch, so convert to host's Epoch.
+ mtime = timeutils_seconds_since_epoch_from_nanoseconds_since_1970(ns);
}
#endif