From 10fc3ed1ac1e9c4c8b5e28600176466590d4590f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 15 Apr 2015 11:00:40 -0600 Subject: [PATCH] configs/sim/src: Add logic to test localtime and TZ database. See apps/system/README.txt for info --- nshlib/nsh_timcmds.c | 15 +++++++++++-- system/zoneinfo/README.txt | 45 ++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/nshlib/nsh_timcmds.c b/nshlib/nsh_timcmds.c index 992cd8ecb..a6fbc1656 100644 --- a/nshlib/nsh_timcmds.c +++ b/nshlib/nsh_timcmds.c @@ -125,11 +125,22 @@ static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl, FAR const char *nam /* Break the current time up into the format needed by strftime */ - (void)gmtime_r((FAR const time_t*)&ts.tv_sec, &tm); + ret = gmtime_r((FAR const time_t*)&ts.tv_sec, &tm); + if (ret < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, name, "gmtime_r", NSH_ERRNO); + return ERROR; + } /* Show the current time in the requested format */ - (void)strftime(timbuf, MAX_TIME_STRING, format, &tm); + ret = strftime(timbuf, MAX_TIME_STRING, format, &tm); + if (ret < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, name, "strftime", NSH_ERRNO); + return ERROR; + } + nsh_output(vtbl, "%s\n", timbuf); return OK; } diff --git a/system/zoneinfo/README.txt b/system/zoneinfo/README.txt index f8e11be89..a4cd25aa0 100644 --- a/system/zoneinfo/README.txt +++ b/system/zoneinfo/README.txt @@ -1,8 +1,11 @@ apps/system/zoninfo/README.txt Author: Gregory Nutt +Contents +======= + This directory contains logic to create a version of the TZ/Olson database. -This base is required if localtime() support is selected via +This database is required if localtime() support is selected via CONFIG_LIBC_LOCALTIME. This logic in this directory does the following: - It downloads the current TZ database from the IANA website @@ -11,6 +14,9 @@ CONFIG_LIBC_LOCALTIME. This logic in this directory does the following: - It will then, optionally, build a ROMFS filesystem image containing the data base. +Creating and Mounting a ROMFS TZ Database +========================================= + The ROMFS filesystem image can that be mounted during the boot-up sequence so that it is available for the localtime logic. There are two steps to doing this: @@ -27,12 +33,43 @@ doing this: - The second step is to mount the file system. This step can be performed either in your board configuration logic or by your application using the mount() interface described in - uttx/include/sys/mount.h. + nuttx/include/sys/mount.h. - This steps, however, must be done very early in initialization, + These steps, however, must be done very early in initialization, before there is any need for time-related services. -Both of these steps are shown together in the following code sample: +Both of these steps are shown together in the following code sample at the +end of this README file. + +Example Configuration +===================== + +I have tested this using the sim/nsh configuration. Here are the +modifications to the configuration that I used for testing: + + CONFIG_BOARD_INITIALIZE=y + + CONFIG_LIBC_LOCALTIME=y + CONFIG_LIBC_TZDIR="/share/zoneinfo" + CONFIG_LIBC_TZ_MAX_TIMES=370 + CONFIG_LIBC_TZ_MAX_TYPES=20 + + CONFIG_SYSTEM_ZONEINFO=y + CONFIG_SYSTEM_ZONEINFO_ROMFS=y + +Here is a sample run. I have not seen any errors but neither am I +certain that everything is working properly: + + NuttShell (NSH) + nsh> date + Jul 01 00:00:02 2008 + nsh> set TZ US/Mountain + nsh> date -s "Apr 11 11:53:00 2015" + nsh> date + Apr 11 17:53:00 2015 + +Sample Code to Mount the ROMFS Filesystem +========================================= /**************************************************************************** * Included Files