diff options
author | est31 <MTest31@outlook.com> | 2015-06-06 05:35:38 +0200 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-06-06 05:57:33 +0200 |
commit | c5338fd6c40d08472b680809cfa04d47826bdcf5 (patch) | |
tree | d9cbdebd87b97616e0cbd52e46ad6887f01d90e1 /platform/nacl | |
parent | 803069886ebca492c0d5f47133ccf7833c716e5a (diff) |
Add OS.get_time_zone_info function
The returned dictionary maps "name" to the
name of the current time zone, and "bias" to
a bias from UTC in minutes.
Diffstat (limited to 'platform/nacl')
-rw-r--r-- | platform/nacl/os_nacl.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/platform/nacl/os_nacl.cpp b/platform/nacl/os_nacl.cpp index ecace58801..b282209d72 100644 --- a/platform/nacl/os_nacl.cpp +++ b/platform/nacl/os_nacl.cpp @@ -273,6 +273,32 @@ OS::Time OSNacl::get_time(bool utc) const { return ret; }; +OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { + time_t t = time(NULL); + struct tm *lt = localtime(&t); + char name[16]; + strftime(name, 16, "%Z", lt); + name[15] = 0; + TimeZoneInfo ret; + ret.name = name; + + char bias_buf[16]; + strftime(bias_buf, 16, "%z", lt); + int bias; + bias_buf[15] = 0; + sscanf(bias_buf, "%d", &bias); + + // convert from ISO 8601 (1 minute=1, 1 hour=100) to minutes + int hour = (int)bias / 100; + int minutes = bias % 100; + if (bias < 0) + ret.bias = hour * 60 - minutes; + else + ret.bias = hour * 60 + minutes; + + return ret; +}; + void OSNacl::delay_usec(uint32_t p_usec) const { //usleep(p_usec); |