diff options
| author | Noralf Trønnes <noralf@tronnes.org> | 2018-08-25 18:11:10 +0200 |
|---|---|---|
| committer | Noralf Trønnes <noralf@tronnes.org> | 2018-08-25 20:43:02 +0200 |
| commit | 39ee12d1ac6ffb105f6ac0994f6169a7bb327cbd (patch) | |
| tree | e380f4c5259194f9dcf56c9c0618051d1fa97317 /lib/timeutils | |
| parent | d1b588375be0812f6e8d58f1eba1a6c82f91a931 (diff) | |
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().
Diffstat (limited to 'lib/timeutils')
| -rw-r--r-- | lib/timeutils/timeutils.c | 13 | ||||
| -rw-r--r-- | lib/timeutils/timeutils.h | 7 |
2 files changed, 19 insertions, 1 deletions
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); } diff --git a/lib/timeutils/timeutils.h b/lib/timeutils/timeutils.h index 9b1abeb8f..0ca6bb167 100644 --- a/lib/timeutils/timeutils.h +++ b/lib/timeutils/timeutils.h @@ -27,6 +27,8 @@ #ifndef MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H #define MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H +#define EPOCH1970_EPOCH2000_DIFF_SECS 946684800 + typedef struct _timeutils_struct_time_t { uint16_t tm_year; // i.e. 2014 uint8_t tm_mon; // 1..12 @@ -48,6 +50,11 @@ void timeutils_seconds_since_2000_to_struct_time(mp_uint_t t, mp_uint_t timeutils_seconds_since_2000(mp_uint_t year, mp_uint_t month, mp_uint_t date, mp_uint_t hour, mp_uint_t minute, mp_uint_t second); +void timeutils_seconds_since_epoch_to_struct_time(mp_uint_t t, timeutils_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 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); |
