This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RedBoot: Saner date command


Hi,

This patch makes the RedBoot date command saner.

2003-12-03 David Vrabel <dvrabel@arcom.com>

	* src/time_date.cxx (do_time_date): Use YYYY/MM/DD HH:MM:SS format
	throughout (instead of the American specific format).  Expand
	range of valid years to 1970 - 2034 (instead of 2000 -
	2034).

David Vrabel
--
David Vrabel, Design Engineer

Arcom, Clifton Road           Tel: +44 (0)1223 411200 ext. 3233
Cambridge CB1 7EA, UK         Web: http://www.arcom.com/


_____________________________________________________________________ The message in this transmission is sent in confidence for the attention of the addressee only and should not be disclosed to any other party. Unauthorised recipients are requested to preserve this confidentiality. Please advise the sender if the addressee is not resident at the receiving end.

This message has been checked for all viruses by MessageLabs Virus Control Centre.
Index: src/time_date.cxx
===================================================================
RCS file: /var/cvs/ecos/packages/redboot/current/src/time_date.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -B -p -r1.1 -r1.2
--- src/time_date.cxx	20 Nov 2003 09:24:15 -0000	1.1
+++ src/time_date.cxx	3 Dec 2003 17:56:54 -0000	1.2
@@ -57,7 +57,7 @@
 
 RedBoot_cmd("date", 
             "Show/Set the time of day", 
-            "[HH:MM:SS MM/DD/YY]",
+            "[YYYY/MM/DD HH:MM:SS]",
             do_time_date
     );
 
@@ -82,30 +82,30 @@ do_time_date(int argc, char *argv[])
     if (argc == 1) {
         // Just show the current time/date
         _simple_mkdate(now, &year, &month, &mday, &hour, &minute, &second);
-        diag_printf("%02d:%02d:%02d %d/%02d/%d\n", 
-                    hour, minute, second, month, mday, year);
+        diag_printf("%04d/%02d/%02d %02d:%02d:%02d\n", 
+                    year, month, mday, hour, minute, second);
     } else if (argc == 3) {
         sp = argv[1];
-        if (!parse_num(sp, (unsigned long *)&hour, &sp, ":") ||
-            !parse_num(sp, (unsigned long *)&minute, &sp, ":") ||
-            !parse_num(sp, (unsigned long *)&second, &sp, ":")) {
+        if (!parse_num(sp, (unsigned long *)&year, &sp, "/") ||
+            !parse_num(sp, (unsigned long *)&month, &sp, "/") ||
+            !parse_num(sp, (unsigned long *)&mday, &sp, "/")) {
             ok = false;
         }
         sp = argv[2];
-        if (!parse_num(sp, (unsigned long *)&month, &sp, "/") ||
-            !parse_num(sp, (unsigned long *)&mday, &sp, "/") ||
-            !parse_num(sp, (unsigned long *)&year, &sp, "/")) {
+        if (!parse_num(sp, (unsigned long *)&hour, &sp, ":") ||
+            !parse_num(sp, (unsigned long *)&minute, &sp, ":") ||
+            !parse_num(sp, (unsigned long *)&second, &sp, ":")) {
             ok = false;
         }
         if (ok) {
             // Verify values make some sense, then set the hardware
+            if (year < 100) year += 2000;
+            ok = ok && verify(year, 1970, 2034, "year");
+            ok = ok && verify(month, 1, 12, "month");
+            ok = ok && verify(mday, 1, 31, "day");
             ok = ok && verify(hour, 0, 23, "hour");
             ok = ok && verify(minute, 0, 59, "minute");
             ok = ok && verify(second, 0, 59, "second");
-            ok = ok && verify(month, 1, 12, "month");
-            ok = ok && verify(mday, 1, 31, "day");
-            if (year < 100) year += 2000;
-            ok = ok && verify(year, 2000, 2034, "year");
             if (ok) {
                 now = _simple_mktime(year, month, mday, hour, minute, second);
                 Cyg_WallClock::wallclock->set_current_time(now);
@@ -115,7 +115,7 @@ do_time_date(int argc, char *argv[])
         ok = false;
     }
     if (!ok) {
-        diag_printf("usage: date [HH:MM:SS MM/DD/YY]\n");
+        diag_printf("usage: date [YYYY/MM/DD HH:MM:SS]\n");
     }
 
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]