This patch adds the ability to specify time as seconds from epoch using 
the @integer syntax. It's a (poorly-documented) gnu-ism (and has been 
for a number of years) that is really handy for a couple things. 
Examples: Replace ntpdate with a short script, or calculate "when is now 
plus 45,100 seconds?".

Please consider applying.

Index: busybox/coreutils/date.c
===================================================================
--- busybox/coreutils/date.c    (revision 23570)
+++ busybox/coreutils/date.c    (working copy)
@@ -146,6 +146,14 @@
                                                end = '\0';
                                        /* else end != NUL and we error out 
*/
                                }
+                       } else if (date_str[0] == '@') {
+                               /* The format '@SECONDS' is a poorly-documented 
GNU-ism. */
+                               /* The 'SECONDS' counts from 1 Jan 1970 - just 
like time_t. */
+                               int seconds; /* Avoiding casting time_t */
+                               if (sscanf(date_str, "@%d%c", &seconds, &end) < 
1)
+                                       
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
+                               tm = seconds;
+                               memcpy(&tm_time, localtime(&tm), 
sizeof(tm_time));
                        } else {
                                if (sscanf(date_str, "%2u%2u%2u%2u%u%c", 
&tm_time.tm_mon,
                                                        &tm_time.tm_mday, 
&tm_time.tm_hour, &tm_time.tm_min,
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to