diff options
| author | Meco Man <[email protected]> | 2023-08-12 13:29:26 -0400 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2023-08-13 22:51:58 -0400 |
| commit | 23eb6319e279d497f7d835e09fc8cd07b53061c4 (patch) | |
| tree | b7152978b6ea83f6f696ed900ed2b3a9664cc915 /components/drivers/rtc | |
| parent | 432c2f38fce3eacc5925d79c81f7792929ad6832 (diff) | |
[device][rtc] support output UTC minutes level
Diffstat (limited to 'components/drivers/rtc')
| -rw-r--r-- | components/drivers/rtc/rtc.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/components/drivers/rtc/rtc.c b/components/drivers/rtc/rtc.c index b421fcbef8..4f4fbc61b0 100644 --- a/components/drivers/rtc/rtc.c +++ b/components/drivers/rtc/rtc.c @@ -284,14 +284,22 @@ static void date(int argc, char **argv) if (argc == 1) { struct timeval tv = { 0 }; - struct timezone tz = { 0 }; + int32_t tz_offset_sec = 0; + uint32_t abs_tz_offset_sec = 0U; - gettimeofday(&tv, &tz); +#if defined(RT_LIBC_USING_LIGHT_TZ_DST) + tz_offset_sec = rt_tz_get(); +#endif /* RT_LIBC_USING_LIGHT_TZ_DST */ + + gettimeofday(&tv, RT_NULL); now = tv.tv_sec; + + abs_tz_offset_sec = tz_offset_sec > 0 ? tz_offset_sec : -tz_offset_sec; /* output current time */ - rt_kprintf("local time: %.*s", 25, ctime(&now)); + rt_kprintf("local time: %.*s", 25U, ctime(&now)); rt_kprintf("timestamps: %ld\n", (long)tv.tv_sec); - rt_kprintf("timezone: UTC%c%d\n", -tz.tz_minuteswest > 0 ? '+' : '-', -tz.tz_minuteswest / 60); + rt_kprintf("timezone: UTC%c%02d:%02d:%02d\n", + tz_offset_sec > 0 ? '+' : '-', abs_tz_offset_sec / 3600U, abs_tz_offset_sec % 3600U / 60U, abs_tz_offset_sec % 3600U % 60U); } else if (argc >= 7) { |
