MYNEWT-4: Need the concept of wallclock time Add shell command "date" to set and get wallclock time.
The wallclock time is specified as per RFC 3339. For example: date 2016-03-02T22:44:00 # set time to Mar 2 2016 10:44 PM UTC date 2016-03-02T22:44:00Z # with explicit Zulu time zone (UTC + 0) date 2016-03-02T22:44:00z # with explicit Zulu time zone (UTC + 0) date 2016-03-02T22:44:00-08:00 # pacific standard time (UTC - 0800) date 2016-03-02T22:44:00+05:30 # indian standard time (UTC + 0530) date 2016-03-02T22:44:00.000031 # time is 22:44:00 + 31 usec date 2016-03-02T22:44:00.1 # time is 22:44:00 + 100 msec date 2016-03-02T22:44:00.013 # time is 22:44:00 + 13 msec 'os_settimeofday()' and 'os_gettimeofday()' can be used to set and get the time of day. 'parse_datetime()' and 'format_datetime()' are available to parse and format the RFC 3339 compliant datetime strings. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/bae36a76 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/bae36a76 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/bae36a76 Branch: refs/heads/master Commit: bae36a7605dd3d97754df8188210e5dc304e1a6b Parents: 22c393a Author: neel <n...@neels-air.attlocal.net> Authored: Wed Mar 2 23:01:16 2016 -0800 Committer: wes3 <w...@micosa.io> Committed: Sun Mar 6 10:53:53 2016 -0800 ---------------------------------------------------------------------- LICENSE | 1 + libs/os/src/os_time.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bae36a76/LICENSE ---------------------------------------------------------------------- diff --git a/LICENSE b/LICENSE index 4948bfb..1ec8ffb 100644 --- a/LICENSE +++ b/LICENSE @@ -305,3 +305,4 @@ This product bundles parts of mbed, which is available under the * hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_bitfields.h * hw/mcu/nordic/nrf51xxx/include/mcu/nrf51_deprecated.h * hw/mcu/nordic/nrf51xxx/include/mcu/system_nrf51.h + http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/bae36a76/libs/os/src/os_time.c ---------------------------------------------------------------------- diff --git a/libs/os/src/os_time.c b/libs/os/src/os_time.c index 1b703e0..520747c 100644 --- a/libs/os/src/os_time.c +++ b/libs/os/src/os_time.c @@ -45,6 +45,27 @@ os_deltatime(os_time_t delta, const struct os_timeval *base, os_timeradd(base, &tvdelta, result); } +/* + * Time-of-day collateral. + */ +static struct { + os_time_t ostime; + struct os_timeval uptime; + struct os_timeval utctime; + struct os_timezone timezone; +} basetod; + +static void +os_deltatime(os_time_t delta, const struct os_timeval *base, + struct os_timeval *result) +{ + struct os_timeval tvdelta; + + tvdelta.tv_sec = delta / OS_TICKS_PER_SEC; + tvdelta.tv_usec = (delta % OS_TICKS_PER_SEC) * OS_USEC_PER_TICK; + os_timeradd(base, &tvdelta, result); +} + os_time_t os_time_get(void) {