aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-11-28 21:44:58 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-28 21:44:58 +0100
commit900eae17384e52cd31d166c09d038cc6e1b64019 (patch)
tree824f4b796813801993e0095070485146ebdfb201
parentab6991c6f59ff2960885bbdec57892e9d0f89598 (diff)
downloadbusybox-w32-900eae17384e52cd31d166c09d038cc6e1b64019.tar.gz
busybox-w32-900eae17384e52cd31d166c09d038cc6e1b64019.tar.bz2
busybox-w32-900eae17384e52cd31d166c09d038cc6e1b64019.zip
date: support -Ins, more compatible timezone display in -I
function old new delta date_main 941 1016 +75 static.isoformats 28 31 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 78/0) Total: 78 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/date.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index d8a2e8618..7fead01bd 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -208,7 +208,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
208 ifmt = 0; /* default is date */ 208 ifmt = 0; /* default is date */
209 if (isofmt_arg) { 209 if (isofmt_arg) {
210 static const char isoformats[] ALIGN1 = 210 static const char isoformats[] ALIGN1 =
211 "date\0""hours\0""minutes\0""seconds\0"; /* ns? */ 211 "date\0""hours\0""minutes\0""seconds\0ns\0";
212 ifmt = index_in_substrings(isoformats, isofmt_arg); 212 ifmt = index_in_substrings(isoformats, isofmt_arg);
213 if (ifmt < 0) 213 if (ifmt < 0)
214 bb_show_usage(); 214 bb_show_usage();
@@ -315,21 +315,33 @@ int date_main(int argc UNUSED_PARAM, char **argv)
315 int i; 315 int i;
316 fmt_dt2str = buf_fmt_dt2str; 316 fmt_dt2str = buf_fmt_dt2str;
317 if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) { 317 if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
318 /* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds */ 318 /* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds 4:ns*/
319 strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S"); 319 strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S");
320 i = 8 + 3 * ifmt; 320 i = 8 + 3 * ifmt;
321 if (ifmt != 0) { 321 if (ifmt != 0) {
322 /* TODO: if (ifmt==4) i += sprintf(&fmt_dt2str[i], ",%09u", nanoseconds); */ 322 int n;
323 fmt_dt2str[i++] = '%'; 323 if (ifmt == 4) {
324 fmt_dt2str[i++] = 'z'; 324 i -= 3;
325 /* FIXME: %z prints "+hhmm" timezone, but coreutils-8.30 prints "+hh:mm" */ 325 i += sprintf(&fmt_dt2str[i], ",%09u", (unsigned)ts.tv_nsec);
326 }
327 /* %z prints "+hhmm" timezone, but coreutils-8.30 prints "+hh:mm"! */
328 /* ...therefore this atrocity: */
329 n = strftime(&fmt_dt2str[i], 8, "%z", &tm_time);
330 i += n;
331 if (n == 5 && (fmt_dt2str[i-5] == '+' || fmt_dt2str[i-5] == '-')) {
332 /* "mm" -> ":mm" */
333 fmt_dt2str[i ] = fmt_dt2str[i - 1];
334 fmt_dt2str[i - 1] = fmt_dt2str[i - 2];
335 fmt_dt2str[i - 2] = ':';
336 i++;
337 }
326 } 338 }
327 fmt_dt2str[i] = '\0'; 339 fmt_dt2str[i] = '\0';
328 } else if (opt & OPT_RFC2822) { 340 } else if (opt & OPT_RFC2822) {
329 /* -R. undo busybox.c setlocale */ 341 /* -R. undo busybox.c setlocale */
330 if (ENABLE_LOCALE_SUPPORT) 342 if (ENABLE_LOCALE_SUPPORT)
331 setlocale(LC_TIME, "C"); 343 setlocale(LC_TIME, "C");
332 strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S %z"); 344 fmt_dt2str = (char*)"%a, %d %b %Y %H:%M:%S %z";
333 } else { /* default case */ 345 } else { /* default case */
334 fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y"; 346 fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
335 } 347 }