diff --git a/ChangeLog b/ChangeLog
index 69ac0a8a3b9..661ba99d9f7 100644
--- a/ChangeLog
+++ b/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/Documentation/NuttShell.html b/Documentation/NuttShell.html
index 56dcfdde2e2..69310516691 100644
--- a/Documentation/NuttShell.html
+++ b/Documentation/NuttShell.html
@@ -8,7 +8,7 @@
NuttShell (NSH)
- Last Updated: July 4, 2011
+ Last Updated: September 1, 2011
|
@@ -107,187 +107,193 @@
|
- 2.5 Copy and Convert Files (dd)
+ 2.5 Show or set the date and time (date)
|
|
- 2.6 Echo Strings and Variables (echo)
+ 2.6 Copy and Convert Files (dd)
|
|
- 2.7 Execute User Code (exec)
+ 2.7 Echo Strings and Variables (echo)
|
|
- 2.8 Exit NSH (exit)
+ 2.8 Execute User Code (exec)
|
|
- 2.9 Show Memory Manager Status (free)
+ 2.9 Exit NSH (exit)
|
|
- 2.10 Get File Via TFTP (get)
+ 2.10 Show Memory Manager Status (free)
|
|
- 2.11 Show Usage Command Usage (help)
+ 2.11 Get File Via TFTP (get)
|
|
- 2.12 Show Network Configuration (ifconfig)
+ 2.12 Show Usage Command Usage (help)
|
|
- 2.13 Send a signal to a task (kill)
+ 2.13 Show Network Configuration (ifconfig)
|
|
- 2.14 Setup/teardown the Loop Device (losetup)
+ 2.14 Send a signal to a task (kill)
|
|
- 2.15 List Directory Contents (ls)
+ 2.15 Setup/teardown the Loop Device (losetup)
|
|
- 2.16 Access Memory (mb, mh, and mw)
+ 2.16 List Directory Contents (ls)
|
|
- 2.17 Show Current Tasks and Threads (ps)
+ 2.17 Access Memory (mb, mh, and mw)
|
|
- 2.18 Create a Directory (mkdir)
+ 2.18 Show Current Tasks and Threads (ps)
|
|
- 2.19 Create a FAT Filesystem (mkfatfs)
+ 2.19 Create a Directory (mkdir)
|
|
- 2.20 Create a FIFO (mkfifo)
+ 2.20 Create a FAT Filesystem (mkfatfs)
|
|
- 2.21 Create a RAMDISK (mkrd)
+ 2.21 Create a FIFO (mkfifo)
|
|
- 2.22 Mount a File System (mount)
+ 2.22 Create a RAMDISK (mkrd)
|
|
- 2.23 Check Network Peer (ping)
+ 2.23 Mount a File System (mount)
|
|
- 2.24 Send File Via TFTP (put)
+ 2.24 Check Network Peer (ping)
|
|
- 2.25 Show Current Working Directory (pwd)
+ 2.25 Send File Via TFTP (put)
|
|
- 2.26 Remove a File (rm)
+ 2.26 Show Current Working Directory (pwd)
|
|
- 2.27 Remove a Directory (rmdir)
+ 2.27 Remove a File (rm)
|
|
- 2.28 Set an Environment Variable (set)
+ 2.28 Remove a Directory (rmdir)
|
|
- 2.29 Execute an NSH Script (sh)
+ 2.29 Set an Environment Variable (set)
|
|
- 2.30 Wait for Seconds (sleep)
+ 2.30 Execute an NSH Script (sh)
|
|
- 2.31 Unmount a File System (umount)
+ 2.31 Wait for Seconds (sleep)
|
|
- 2.32 Unset an Environment Variable (unset)
+ 2.32 Unmount a File System (umount)
|
|
- 2.33 Wait for Microseconds (usleep)
+ 2.33 Unset an Environment Variable (unset)
|
|
- 2.34 Get File Via HTTP (wget)
+ 2.34 Wait for Microseconds (usleep)
|
|
- 2.35 Hexadecimal Dump (xd)
+ 2.35 Get File Via HTTP (wget)
+ |
+
+
+
|
+
+ 2.36 Hexadecimal Dump (xd)
|
@@ -769,11 +775,37 @@ cp <source-path> <dest-path>
+Command Syntax:
+
+date [-s "MMM DD HH:MM:SS YYYY"]
+
+
+ Synopsis.
+ 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 is used.
+
+
Command Syntax:
dd if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]
@@ -828,7 +860,7 @@ nsh> dd if=/dev/ram0 of=/dev/null
@@ -846,7 +878,7 @@ echo [<string|$name> [<string|$name>...]]
@@ -865,7 +897,7 @@ exec <hex-address>
@@ -884,7 +916,7 @@ exit
@@ -926,7 +958,7 @@ nsh>
@@ -961,7 +993,7 @@ get [-b|-n] [-f <local-path>] -h <ip-address> <remote-path>
@@ -978,7 +1010,7 @@ help
@@ -1029,7 +1061,7 @@ ifconfig nic_name ip_address
@@ -1070,7 +1102,7 @@ nsh>
@@ -1123,7 +1155,7 @@ losetup d <dev-path>
@@ -1160,7 +1192,7 @@ ls [-lRs] <dir-path>
@@ -1214,7 +1246,7 @@ nsh>
@@ -1240,7 +1272,7 @@ nsh>
@@ -1275,7 +1307,7 @@ nsh>
@@ -1295,7 +1327,7 @@ mkfatfs <path>
@@ -1333,7 +1365,7 @@ nsh>
@@ -1384,7 +1416,7 @@ nsh>
@@ -1451,7 +1483,7 @@ nsh>
@@ -1484,7 +1516,7 @@ nsh>
@@ -1519,7 +1551,7 @@ put [-b|-n] [-f <remote-path>] -h <ip-address> <local-path>
@@ -1549,7 +1581,7 @@ nsh>
@@ -1583,7 +1615,7 @@ nsh>
@@ -1618,7 +1650,7 @@ nsh>
@@ -1644,7 +1676,7 @@ nsh>
@@ -1662,7 +1694,7 @@ sh <script-path>
@@ -1679,7 +1711,7 @@ sleep <sec>
@@ -1709,7 +1741,7 @@ nsh>
@@ -1735,7 +1767,7 @@ nsh>
@@ -1752,7 +1784,7 @@ usleep <usec>
@@ -1779,7 +1811,7 @@ wget [-o <local-path>] <url>
@@ -1862,6 +1894,11 @@ nsh>
CONFIG_NFILE_DESCRIPTORS > 0 |
CONFIG_NSH_DISABLE_CP |
+
+ date |
+ !CONFIG_DISABLE_CLOCK && CONFIG_RTC |
+ CONFIG_NSH_DISABLE_DATE |
+
dd |
CONFIG_NFILE_DESCRIPTORS > 0 |
@@ -2428,6 +2465,7 @@ nsh>
Configuration settings, NSH-specific
cp
Current working directory
+ date
dd
echo
Environment Variables
diff --git a/lib/time/lib_gmtimer.c b/lib/time/lib_gmtimer.c
index b410a74f206..082bd8cf8d2 100644
--- a/lib/time/lib_gmtimer.c
+++ b/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/lib/time/lib_mktime.c b/lib/time/lib_mktime.c
index f0168aa6bcd..2e8cfc119e4 100644
--- a/lib/time/lib_mktime.c
+++ b/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.
*/