diff options
author | James Buren <braewoods+rb@braewoods.net> | 2021-07-07 17:26:24 +0000 |
---|---|---|
committer | James Buren <braewoods+rb@braewoods.net> | 2021-07-07 17:31:00 +0000 |
commit | 49ca4b3e5e8876bf34d86eb0970385848d4a167e (patch) | |
tree | 42e6b4771f16b88b2446654a54ea13649cfb6cc4 | |
parent | bce6771730d88f52fbb2e756bda457b0ce35d36b (diff) | |
download | rockbox-49ca4b3e5e.tar.gz rockbox-49ca4b3e5e.zip |
timefuncs: add dostime_localtime function
This does the opposite of dostime_mktime, converting time_t back to
the two dos date time values. We use gmtime_r for native because that
is what is available and acts the same as localtime_r on other platforms
with a regular libc available.
Change-Id: If79469d0aae2d7c5dcdd905fbf04963669aa1138
-rw-r--r-- | firmware/common/timefuncs.c | 17 | ||||
-rw-r--r-- | firmware/include/timefuncs.h | 1 |
2 files changed, 18 insertions, 0 deletions
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 |