diff options
-rwxr-xr-x | apps/ChangeLog.txt | 2 | ||||
-rw-r--r-- | apps/nshlib/README.txt | 12 | ||||
-rw-r--r-- | apps/nshlib/nsh_timcmds.c | 6 | ||||
-rw-r--r-- | nuttx/ChangeLog | 2 | ||||
-rw-r--r-- | nuttx/Documentation/NuttShell.html | 164 | ||||
-rw-r--r-- | nuttx/lib/time/lib_gmtimer.c | 20 | ||||
-rw-r--r-- | nuttx/lib/time/lib_mktime.c | 2 |
7 files changed, 134 insertions, 74 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index b3b50ca19..73eada367 100755 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -102,3 +102,5 @@ of circles. * apps/system/i2c: Add an I2C test tool that should help to bring up I2C devices (when it is fully functional). + * apps/nshlib/nsh_timcmds.c: Add the date command that can be used to + show or set the time (only if CONFIG_RTC is set). diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt index 8435f6317..fad1ac104 100644 --- a/apps/nshlib/README.txt +++ b/apps/nshlib/README.txt @@ -262,6 +262,18 @@ o cp <source-path> <dest-path> Copy of the contents of the file at <source-path> to the location in the filesystem indicated by <path-path> +o date [-s "MMM DD HH:MM:SS YYYY"] + + Show or set the current date and time. This command is only supported + if the platform supported RTC hardware (CONFIG_RTC=y). + + Only one format is used both on display and when setting the date/time: + MMM DD HH:MM:SS YYYY. For example, + + data -s "Sep 1 11:30:00 2011" + + 24-hour time format is assumed. + o dd if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>] Copy blocks from <infile> to <outfile>. <nfile> or <outfile> may diff --git a/apps/nshlib/nsh_timcmds.c b/apps/nshlib/nsh_timcmds.c index bf5e6cd5d..04a79e77d 100644 --- a/apps/nshlib/nsh_timcmds.c +++ b/apps/nshlib/nsh_timcmds.c @@ -124,7 +124,7 @@ 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); + (void)gmtime_r((FAR const time_t*)&ts.tv_sec, &tm); /* Show the current time in the requested format */ @@ -166,7 +166,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name /* Get the day of the month. NOTE: Accepts day-of-month up to 31 for all months */ - token = strtok_r(newtime, " \t",&saveptr); + token = strtok_r(NULL, " \t",&saveptr); if (token == NULL) { goto errout_bad_parm; @@ -237,7 +237,7 @@ static inline int date_settime(FAR struct nsh_vtbl_s *vtbl, FAR const char *name { goto errout_bad_parm; } - tm.tm_year = (int)result; + tm.tm_year = (int)result - 1900; /* Convert this to the right form, then set the timer */ diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 69ac0a8a3..661ba99d9 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -2049,3 +2049,5 @@ crashes on Cortex-M3 if the ARM libgcc is used, for example. The fix is to include ARCHCPUFLAGS on the gcc command line when asking it to -print-libgcc-file-name. + * lib/time/lib_gmtimer.c: Correct several calculations that could lead + to errors in dates. diff --git a/nuttx/Documentation/NuttShell.html b/nuttx/Documentation/NuttShell.html index 56dcfdde2..693105166 100644 --- a/nuttx/Documentation/NuttShell.html +++ b/nuttx/Documentation/NuttShell.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1> - <p>Last Updated: July 4, 2011</p> + <p>Last Updated: September 1, 2011</p> </td> </tr> </table> @@ -107,187 +107,193 @@ <tr> <td><br></td> <td> - <a href="#cmddd">2.5 Copy and Convert Files (dd)</a> + <a href="#cmddate">2.5 Show or set the date and time (date)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdecho">2.6 Echo Strings and Variables (echo)</a> + <a href="#cmddd">2.6 Copy and Convert Files (dd)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdexec">2.7 Execute User Code (exec)</a> + <a href="#cmdecho">2.7 Echo Strings and Variables (echo)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdexit">2.8 Exit NSH (exit)</a> + <a href="#cmdexec">2.8 Execute User Code (exec)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdfree">2.9 Show Memory Manager Status (free)</a> + <a href="#cmdexit">2.9 Exit NSH (exit)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdget">2.10 Get File Via TFTP (get)</a> + <a href="#cmdfree">2.10 Show Memory Manager Status (free)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdhelp">2.11 Show Usage Command Usage (help)</a> + <a href="#cmdget">2.11 Get File Via TFTP (get)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdifconfig">2.12 Show Network Configuration (ifconfig)</a> + <a href="#cmdhelp">2.12 Show Usage Command Usage (help)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdkill">2.13 Send a signal to a task (kill)</a> + <a href="#cmdifconfig">2.13 Show Network Configuration (ifconfig)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdlosetup">2.14 Setup/teardown the Loop Device (losetup)</a> + <a href="#cmdkill">2.14 Send a signal to a task (kill)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdls">2.15 List Directory Contents (ls)</a> + <a href="#cmdlosetup">2.15 Setup/teardown the Loop Device (losetup)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdmbhw">2.16 Access Memory (mb, mh, and mw)</a> + <a href="#cmdls">2.16 List Directory Contents (ls)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdps">2.17 Show Current Tasks and Threads (ps)</a> + <a href="#cmdmbhw">2.17 Access Memory (mb, mh, and mw)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdmkdir">2.18 Create a Directory (mkdir)</a> + <a href="#cmdps">2.18 Show Current Tasks and Threads (ps)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdmkfatfs">2.19 Create a FAT Filesystem (mkfatfs)</a> + <a href="#cmdmkdir">2.19 Create a Directory (mkdir)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdmkfifo">2.20 Create a FIFO (mkfifo)</a> + <a href="#cmdmkfatfs">2.20 Create a FAT Filesystem (mkfatfs)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdmkrd">2.21 Create a RAMDISK (mkrd)</a> + <a href="#cmdmkfifo">2.21 Create a FIFO (mkfifo)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdmount">2.22 Mount a File System (mount)</a> + <a href="#cmdmkrd">2.22 Create a RAMDISK (mkrd)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdping">2.23 Check Network Peer (ping)</a> + <a href="#cmdmount">2.23 Mount a File System (mount)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdput">2.24 Send File Via TFTP (put)</a> + <a href="#cmdping">2.24 Check Network Peer (ping)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdpwd">2.25 Show Current Working Directory (pwd)</a> + <a href="#cmdput">2.25 Send File Via TFTP (put)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdrm">2.26 Remove a File (rm)</a> + <a href="#cmdpwd">2.26 Show Current Working Directory (pwd)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdrmdir">2.27 Remove a Directory (rmdir)</a> + <a href="#cmdrm">2.27 Remove a File (rm)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdset">2.28 Set an Environment Variable (set)</a> + <a href="#cmdrmdir">2.28 Remove a Directory (rmdir)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdsh">2.29 Execute an NSH Script (sh)</a> + <a href="#cmdset">2.29 Set an Environment Variable (set)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdsleep">2.30 Wait for Seconds (sleep)</a> + <a href="#cmdsh">2.30 Execute an NSH Script (sh)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdunmount">2.31 Unmount a File System (umount)</a> + <a href="#cmdsleep">2.31 Wait for Seconds (sleep)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdunset">2.32 Unset an Environment Variable (unset)</a> + <a href="#cmdunmount">2.32 Unmount a File System (umount)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdusleep">2.33 Wait for Microseconds (usleep)</a> + <a href="#cmdunset">2.33 Unset an Environment Variable (unset)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdwget">2.34 Get File Via HTTP (wget)</a> + <a href="#cmdusleep">2.34 Wait for Microseconds (usleep)</a> </td> </tr> <tr> <td><br></td> <td> - <a href="#cmdxd">2.35 Hexadecimal Dump (xd)</a> + <a href="#cmdwget">2.35 Get File Via HTTP (wget)</a> + </td> +</tr> +<tr> + <td><br></td> + <td> + <a href="#cmdxd">2.36 Hexadecimal Dump (xd)</a> </td> </tr> <tr> @@ -769,11 +775,37 @@ cp <source-path> <dest-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmddd"><h2>2.5 Copy and Convert Files (dd)</h2></a> + <a name="cmddate"><h2>2.5 Show or set the date and time (date)</h2></a> </td> </tr> </table> +<p><b>Command Syntax:</b></p> +<ul><pre> +date [-s "MMM DD HH:MM:SS YYYY"] +</pre></ul> +<p> + <b>Synopsis</b>. + Show or set the current date and time. + This command is only supported if the platform supported RTC hardware (<code>CONFIG_RTC=y</code>). +</p> +<p> + Only one format is used both on display and when setting the date/time: + <code>MMM DD HH:MM:SS YYYY</code>. For example, +<ul><pre> +data -s "Sep 1 11:30:00 2011" +</pre></ul> +</p> +<p> + 24-hour time is used. +</p> +<table width ="100%"> + <tr bgcolor="#e4e4e4"> + <td> + <a name="cmddd"><h2>2.6 Copy and Convert Files (dd)</h2></a> + </td> + </tr> +</table> <p><b>Command Syntax:</b></p> <ul><pre> dd if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>] @@ -828,7 +860,7 @@ nsh> dd if=/dev/ram0 of=/dev/null <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdecho"><h2>2.6 Echo Strings and Variables (echo)</h2></a> + <a name="cmdecho"><h2>2.7 Echo Strings and Variables (echo)</h2></a> </td> </tr> </table> @@ -846,7 +878,7 @@ echo [<string|$name> [<string|$name>...]] <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdexec"><h2>2.7 Execute User Code (exec)</h2></a> + <a name="cmdexec"><h2>2.8 Execute User Code (exec)</h2></a> </td> </tr> </table> @@ -865,7 +897,7 @@ exec <hex-address> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdexit"><h2>2.8 Exit NSH (exit)</h2></a> + <a name="cmdexit"><h2>2.9 Exit NSH (exit)</h2></a> </td> </tr> </table> @@ -884,7 +916,7 @@ exit <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdfree"><h2>2.9 Show Memory Manager Status (free)</h2></a> + <a name="cmdfree"><h2>2.10 Show Memory Manager Status (free)</h2></a> </td> </tr> </table> @@ -926,7 +958,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdget"><h2>2.10 Get File Via TFTP (get)</h2></a> + <a name="cmdget"><h2>2.11 Get File Via TFTP (get)</h2></a> </td> </tr> </table> @@ -961,7 +993,7 @@ get [-b|-n] [-f <local-path>] -h <ip-address> <remote-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdhelp"><h2>2.11 Show Usage Command Usage (help)</h2></a> + <a name="cmdhelp"><h2>2.12 Show Usage Command Usage (help)</h2></a> </td> </tr> </table> @@ -978,7 +1010,7 @@ help <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdifconfig"><h2>2.12 Show Network Configuration (ifconfig)</h2></a> + <a name="cmdifconfig"><h2>2.13 Show Network Configuration (ifconfig)</h2></a> </td> </tr> </table> @@ -1029,7 +1061,7 @@ ifconfig nic_name ip_address <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdkill"><h2>2.13 Send a signal to a task (kill)</h2></a> + <a name="cmdkill"><h2>2.14 Send a signal to a task (kill)</h2></a> </td> </tr> </table> @@ -1070,7 +1102,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdlosetup"><h2>2.14 Setup/teardown the Loop Device (losetup)</h2></a> + <a name="cmdlosetup"><h2>2.15 Setup/teardown the Loop Device (losetup)</h2></a> </td> </tr> </table> @@ -1123,7 +1155,7 @@ losetup d <dev-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdls"><h2>2.15 List Directory Contents (ls)</h2></a> + <a name="cmdls"><h2>2.16 List Directory Contents (ls)</h2></a> </td> </tr> </table> @@ -1160,7 +1192,7 @@ ls [-lRs] <dir-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdmbhw"><h2>2.16 Access Memory (mb, mh, and mw)</h2></a> + <a name="cmdmbhw"><h2>2.17 Access Memory (mb, mh, and mw)</h2></a> </td> </tr> </table> @@ -1214,7 +1246,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdps"><h2>2.17 Show Current Tasks and Threads (ps)</h2></a> + <a name="cmdps"><h2>2.18 Show Current Tasks and Threads (ps)</h2></a> </td> </tr> </table> @@ -1240,7 +1272,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdmkdir"><h2>2.18 Create a Directory (mkdir)</h2></a> + <a name="cmdmkdir"><h2>2.19 Create a Directory (mkdir)</h2></a> </td> </tr> </table> @@ -1275,7 +1307,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdmkfatfs"><h2>2.19 Create a FAT Filesystem (mkfatfs)</h2></a> + <a name="cmdmkfatfs"><h2>2.20 Create a FAT Filesystem (mkfatfs)</h2></a> </td> </tr> </table> @@ -1295,7 +1327,7 @@ mkfatfs <path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdmkfifo"><h2>2.20 Create a FIFO (mkfifo)</h2></a> + <a name="cmdmkfifo"><h2>2.21 Create a FIFO (mkfifo)</h2></a> </td> </tr> </table> @@ -1333,7 +1365,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdmkrd"><h2>2.21 Create a RAMDISK (mkrd)</h2></a> + <a name="cmdmkrd"><h2>2.22 Create a RAMDISK (mkrd)</h2></a> </td> </tr> </table> @@ -1384,7 +1416,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdmount"><h2>2.22 Mount a File System (mount)</h2></a> + <a name="cmdmount"><h2>2.23 Mount a File System (mount)</h2></a> </td> </tr> </table> @@ -1451,7 +1483,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdping"><h2>2.23 Check Network Peer (ping)</h2></a> + <a name="cmdping"><h2>2.24 Check Network Peer (ping)</h2></a> </td> </tr> </table> @@ -1484,7 +1516,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdput"><h2>2.24 Send File Via TFTP (put)</h2></a> + <a name="cmdput"><h2>2.25 Send File Via TFTP (put)</h2></a> </td> </tr> </table> @@ -1519,7 +1551,7 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdpwd"><h2>2.25 Show Current Working Directory (pwd)</h2></a> + <a name="cmdpwd"><h2>2.26 Show Current Working Directory (pwd)</h2></a> </td> </tr> </table> @@ -1549,7 +1581,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdrm"><h2>2.26 Remove a File (rm)</h2></a> + <a name="cmdrm"><h2>2.27 Remove a File (rm)</h2></a> </td> </tr> </table> @@ -1583,7 +1615,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdrmdir"><h2>2.27 Remove a Directory (rmdir)</h2></a> + <a name="cmdrmdir"><h2>2.28 Remove a Directory (rmdir)</h2></a> </td> </tr> </table> @@ -1618,7 +1650,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdset"><h2>2.28 Set an Environment Variable (set)</h2></a> + <a name="cmdset"><h2>2.29 Set an Environment Variable (set)</h2></a> </td> </tr> </table> @@ -1644,7 +1676,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdsh"><h2>2.29 Execute an NSH Script (sh)</h2></a> + <a name="cmdsh"><h2>2.30 Execute an NSH Script (sh)</h2></a> </td> </tr> </table> @@ -1662,7 +1694,7 @@ sh <script-path> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdsleep"><h2>2.30 Wait for Seconds (sleep)</h2></a> + <a name="cmdsleep"><h2>2.31 Wait for Seconds (sleep)</h2></a> </td> </tr> </table> @@ -1679,7 +1711,7 @@ sleep <sec> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdunmount"><h2>2.31 Unmount a File System (umount)</h2></a> + <a name="cmdunmount"><h2>2.32 Unmount a File System (umount)</h2></a> </td> </tr> </table> @@ -1709,7 +1741,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdunset"><h2>2.32 Unset an Environment Variable (unset)</h2></a> + <a name="cmdunset"><h2>2.33 Unset an Environment Variable (unset)</h2></a> </td> </tr> </table> @@ -1735,7 +1767,7 @@ nsh> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdusleep"><h2>2.33 Wait for Microseconds (usleep)</h2></a> + <a name="cmdusleep"><h2>2.34 Wait for Microseconds (usleep)</h2></a> </td> </tr> </table> @@ -1752,7 +1784,7 @@ usleep <usec> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdwget">2.34 Get File Via HTTP (wget)</a> + <a name="cmdwget">2.35 Get File Via HTTP (wget)</a> </td> </tr> </table> @@ -1779,7 +1811,7 @@ wget [-o <local-path>] <url> <table width ="100%"> <tr bgcolor="#e4e4e4"> <td> - <a name="cmdxd"><h2>2.35 Hexadecimal dump (xd)</h2></a> + <a name="cmdxd"><h2>2.36 Hexadecimal dump (xd)</h2></a> </td> </tr> </table> @@ -1863,6 +1895,11 @@ nsh> <td><code>CONFIG_NSH_DISABLE_CP</code></td> </tr> <tr> + <td><b><code>date</code></b></td> + <td>!<code>CONFIG_DISABLE_CLOCK</code> && <code>CONFIG_RTC</code></td> + <td><code>CONFIG_NSH_DISABLE_DATE</code></td> + </tr> + <tr> <td><b><code>dd</code></b></td> <td><code>CONFIG_NFILE_DESCRIPTORS</code> > 0</td> <td><code>CONFIG_NSH_DISABLE_DD</code></td> @@ -2428,6 +2465,7 @@ nsh> <li><a href="#nshconfiguration">Configuration settings, NSH-specific</a></li> <li><a href="#cmdcp"><code>cp</code></a></li> <li><a href="#currentwd">Current working directory</a></li> + <li><a href="#cmddate"><code>date</code></a></li> <li><a href="#cmddd"><code>dd</code></a></li> <li><a href="#cmdecho"><code>echo</code></a></li> <li><a href="#environvars">Environment Variables</a></li> diff --git a/nuttx/lib/time/lib_gmtimer.c b/nuttx/lib/time/lib_gmtimer.c index b410a74f2..082bd8cf8 100644 --- a/nuttx/lib/time/lib_gmtimer.c +++ b/nuttx/lib/time/lib_gmtimer.c @@ -191,7 +191,7 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day) { /* Is this year a leap year (we'll need this later too) */ - leapyear = clock_isleapyear(value + 1900); + leapyear = clock_isleapyear(value + 1970); /* Get the number of days in the year */ @@ -239,14 +239,14 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day) * number of days we have remaining? */ - if (tmp >= days) + if (tmp > days) { /* Yes.. then the month we want is somewhere from 'min' and to the * midpoint, 'value'. Could it be the midpoint? */ tmp = clock_daysbeforemonth(value, leapyear); - if (tmp >= days) + if (tmp > days) { /* No... The one we want is somewhere between min and value-1 */ @@ -265,21 +265,27 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day) min = value + 1; } + + /* If we break out of the loop because min == max, then we want value + * to be equal to min == max. + */ + + value = min; } while (min < max); - /* The selected month number is in min (and max). Subtract the number of days in the + /* The selected month number is in value. Subtract the number of days in the * selected month */ - days -= clock_daysbeforemonth(min, leapyear); + days -= clock_daysbeforemonth(value, leapyear); /* At this point, value has the month into this year (zero based) and days has * number of days into this month (zero based) */ - *month = min + 1; /* 1-based */ - *day = days + 1; /* 1-based */ + *month = value + 1; /* 1-based */ + *day = days + 1; /* 1-based */ } #endif /* CONFIG_GREGORIAN_TIME */ diff --git a/nuttx/lib/time/lib_mktime.c b/nuttx/lib/time/lib_mktime.c index f0168aa6b..2e8cfc119 100644 --- a/nuttx/lib/time/lib_mktime.c +++ b/nuttx/lib/time/lib_mktime.c @@ -109,7 +109,7 @@ time_t mktime(const struct tm *tp) #else /* Simple version that only works for dates within a (relatively) small range - * from the epoch. It does not handle earlier days on longer days where leap + * from the epoch. It does not handle earlier days or longer days where leap * seconds, etc. apply. */ |