From 5a110d08d92d2d7a5c0f75ff214861f390d4073e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 11 Apr 2015 12:13:18 -0600 Subject: [PATCH] Allow NSH date command with no RTC. This command is useful without an RTC too. Also, this permits testing on the simulator which never has an RTC --- Documentation/NuttShell.html | 5 ++--- libc/Kconfig | 1 + libc/time/lib_localtime.c | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index ff55c0655a..244a7889a3 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -8,7 +8,7 @@

NuttShell (NSH)

-

Last Updated: August 7, 2014

+

Last Updated: April 11, 2015

@@ -1181,7 +1181,6 @@ 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: @@ -2568,7 +2567,7 @@ nsh> date - CONFIG_RTC +
CONFIG_NSH_DISABLE_DATE diff --git a/libc/Kconfig b/libc/Kconfig index 967a9f4d4a..0ee8e6b5a3 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -288,6 +288,7 @@ endif config TIME_EXTENDED bool "Add day of week, year support" default "n" + depends on !LIBC_LOCALTIME ---help--- Selecting TIME_EXTENDED adds tm_wday, tm_yday and tm_isdst to the tm struct. This allows integration with 3rd party libraries diff --git a/libc/time/lib_localtime.c b/libc/time/lib_localtime.c index 26f0c17ce0..646b3e6df4 100644 --- a/libc/time/lib_localtime.c +++ b/libc/time/lib_localtime.c @@ -2158,6 +2158,7 @@ static time_t time2sub(struct tm *const tmp, li = y + (1 < yourtm.tm_mon); yourtm.tm_mday += year_lengths[isleap(li)]; } + while (yourtm.tm_mday > DAYSPERLYEAR) { li = y + (1 < yourtm.tm_mon); @@ -2167,6 +2168,7 @@ static time_t time2sub(struct tm *const tmp, return -1; } } + for (;;) { i = mon_lengths[isleap(y)][yourtm.tm_mon];