From 39ee12d1ac6ffb105f6ac0994f6169a7bb327cbd Mon Sep 17 00:00:00 2001 From: Noralf Trønnes Date: Sat, 25 Aug 2018 18:11:10 +0200 Subject: Fix os.stat() to use 1970 epoch Commit 95e70cd0ea6d 'time: Use 1970 epoch' changed epoch for the time module, but not for other users. This patch does the same for the only other core timeutils user: extmod/vfs_fat.c:fat_vfs_stat(). Other timeutils users: cc3200, esp8266 and stm32, are not changed. Ports that don't use long ints, will still get wrong time values from os.stat(). --- lib/timeutils/timeutils.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/timeutils/timeutils.c') diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index eb3dc80d4..b93a85dee 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -158,6 +158,17 @@ mp_uint_t timeutils_seconds_since_2000(mp_uint_t year, mp_uint_t month, + (year - 2000) * 31536000; } +void timeutils_seconds_since_epoch_to_struct_time(mp_uint_t t, timeutils_struct_time_t *tm) { + t -= EPOCH1970_EPOCH2000_DIFF_SECS; + timeutils_seconds_since_2000_to_struct_time(t, tm); +} + +mp_uint_t timeutils_seconds_since_epoch(mp_uint_t year, mp_uint_t month, mp_uint_t date, + mp_uint_t hour, mp_uint_t minute, mp_uint_t second) { + mp_uint_t t = timeutils_seconds_since_2000(year, month, date, hour, minute, second); + return t + EPOCH1970_EPOCH2000_DIFF_SECS; +} + mp_uint_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday, mp_int_t hours, mp_int_t minutes, mp_int_t seconds) { @@ -211,5 +222,5 @@ mp_uint_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday, year++; } } - return timeutils_seconds_since_2000(year, month, mday, hours, minutes, seconds); + return timeutils_seconds_since_epoch(year, month, mday, hours, minutes, seconds); } -- cgit v1.2.3