summaryrefslogtreecommitdiff
path: root/firmware/common/timefuncs.c
diff options
context:
space:
mode:
authorJames Buren <braewoods+rb@braewoods.net>2021-07-07 17:26:24 +0000
committerJames Buren <braewoods+rb@braewoods.net>2021-07-07 17:31:00 +0000
commit49ca4b3e5e8876bf34d86eb0970385848d4a167e (patch)
tree42e6b4771f16b88b2446654a54ea13649cfb6cc4 /firmware/common/timefuncs.c
parentbce6771730d88f52fbb2e756bda457b0ce35d36b (diff)
downloadrockbox-49ca4b3e5e8876bf34d86eb0970385848d4a167e.tar.gz
rockbox-49ca4b3e5e8876bf34d86eb0970385848d4a167e.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
Diffstat (limited to 'firmware/common/timefuncs.c')
-rw-r--r--firmware/common/timefuncs.c17
1 files changed, 17 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)
46 return mktime(&tm); 46 return mktime(&tm);
47} 47}
48 48
49void dostime_localtime(time_t time, uint16_t* dosdate, uint16_t* dostime)
50{
51 struct tm tm;
52#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
53 gmtime_r(&time, &tm);
54#else
55 localtime_r(&time, &tm);
56#endif
57
58 *dostime = ((tm.tm_sec / 2) << 0)|
59 ((tm.tm_min ) << 5)|
60 ((tm.tm_hour ) << 11);
61 *dosdate = ((tm.tm_mday ) << 0)|
62 ((tm.tm_mon + 1) << 5)|
63 ((tm.tm_year - 80) << 9);
64}
65
49#if !CONFIG_RTC 66#if !CONFIG_RTC
50static inline bool rtc_dirty(void) 67static inline bool rtc_dirty(void)
51{ 68{