diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c index d87e6b67f2..66854dea13 100644 --- a/firmware/common/timefuncs.c +++ b/firmware/common/timefuncs.c @@ -46,6 +46,23 @@ time_t dostime_mktime(uint16_t dosdate, uint16_t dostime) return mktime(&tm); } +void dostime_localtime(time_t time, uint16_t* dosdate, uint16_t* dostime) +{ + struct tm tm; +#if (CONFIG_PLATFORM & PLATFORM_NATIVE) + gmtime_r(&time, &tm); +#else + localtime_r(&time, &tm); +#endif + + *dostime = ((tm.tm_sec / 2) << 0)| + ((tm.tm_min ) << 5)| + ((tm.tm_hour ) << 11); + *dosdate = ((tm.tm_mday ) << 0)| + ((tm.tm_mon + 1) << 5)| + ((tm.tm_year - 80) << 9); +} + #if !CONFIG_RTC static inline bool rtc_dirty(void) { diff --git a/firmware/include/timefuncs.h b/firmware/include/timefuncs.h index 2e8ef01ca6..25e041b576 100644 --- a/firmware/include/timefuncs.h +++ b/firmware/include/timefuncs.h @@ -28,6 +28,7 @@ #include "time.h" time_t dostime_mktime(uint16_t dosdate, uint16_t dostime); +void dostime_localtime(time_t time, uint16_t* dosdate, uint16_t* dostime); struct tm *get_time(void); int set_time(const struct tm *tm); #if CONFIG_RTC