Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 2ce1edc | 1999-10-12 15:42:48 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini date implementation for busybox |
| 4 | * |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 5 | * by Matthew Grant <grantma@anathoth.gen.nz> |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 6 | * |
Robert Griebl | 6859d76 | 2002-08-05 02:57:12 +0000 | [diff] [blame] | 7 | * iso-format handling added by Robert Griebl <griebl@gmx.de> |
Eric Andersen | 2ce1edc | 1999-10-12 15:42:48 +0000 | [diff] [blame] | 8 | * |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | 2ce1edc | 1999-10-12 15:42:48 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 12 | #include <stdlib.h> |
| 13 | #include <errno.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 14 | #include <unistd.h> |
| 15 | #include <time.h> |
| 16 | #include <stdio.h> |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 17 | #include <string.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 18 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 19 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 20 | /* This 'date' command supports only 2 time setting formats, |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 21 | all the GNU strftime stuff (its in libc, lets use it), |
| 22 | setting time using UTC and displaying int, as well as |
| 23 | an RFC 822 complient date output for shell scripting |
| 24 | mail commands */ |
| 25 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 26 | /* Input parsing code is always bulky - used heavy duty libc stuff as |
| 27 | much as possible, missed out a lot of bounds checking */ |
| 28 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 29 | /* Default input handling to save surprising some people */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 30 | |
Eric Andersen | 3e6ff90 | 2001-03-09 21:24:12 +0000 | [diff] [blame] | 31 | static struct tm *date_conv_time(struct tm *tm_time, const char *t_string) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 32 | { |
| 33 | int nr; |
Eric Andersen | 9315842 | 2004-10-11 20:52:16 +0000 | [diff] [blame] | 34 | char *cp; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 35 | |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 36 | nr = sscanf(t_string, "%2d%2d%2d%2d%d", &(tm_time->tm_mon), |
| 37 | &(tm_time->tm_mday), &(tm_time->tm_hour), &(tm_time->tm_min), |
| 38 | &(tm_time->tm_year)); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 39 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 40 | if (nr < 4 || nr > 5) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 41 | bb_error_msg_and_die(bb_msg_invalid_date, t_string); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 42 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 43 | |
Eric Andersen | 9315842 | 2004-10-11 20:52:16 +0000 | [diff] [blame] | 44 | cp = strchr(t_string, '.'); |
| 45 | if (cp) { |
| 46 | nr = sscanf(cp + 1, "%2d", &(tm_time->tm_sec)); |
| 47 | if (nr != 1) { |
| 48 | bb_error_msg_and_die(bb_msg_invalid_date, t_string); |
| 49 | } |
| 50 | } |
| 51 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 52 | /* correct for century - minor Y2K problem here? */ |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 53 | if (tm_time->tm_year >= 1900) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 54 | tm_time->tm_year -= 1900; |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 55 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 56 | /* adjust date */ |
| 57 | tm_time->tm_mon -= 1; |
| 58 | |
| 59 | return (tm_time); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 60 | |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /* The new stuff for LRP */ |
| 65 | |
Eric Andersen | 3e6ff90 | 2001-03-09 21:24:12 +0000 | [diff] [blame] | 66 | static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 67 | { |
Eric Andersen | 7b5d594 | 2000-11-29 22:01:42 +0000 | [diff] [blame] | 68 | struct tm t; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 69 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 70 | /* Parse input and assign appropriately to tm_time */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 71 | |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 72 | if (t = *tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min, |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 73 | &t.tm_sec) == 3) { |
| 74 | /* no adjustments needed */ |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 75 | } else if (t = *tm_time, sscanf(t_string, "%d:%d", &t.tm_hour, |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 76 | &t.tm_min) == 2) { |
| 77 | /* no adjustments needed */ |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 78 | } else if (t = *tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 79 | &t.tm_mday, &t.tm_hour, |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 80 | &t.tm_min, &t.tm_sec) == 5) { |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 81 | /* Adjust dates from 1-12 to 0-11 */ |
| 82 | t.tm_mon -= 1; |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 83 | } else if (t = *tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 84 | &t.tm_mday, |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 85 | &t.tm_hour, &t.tm_min) == 4) { |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 86 | /* Adjust dates from 1-12 to 0-11 */ |
| 87 | t.tm_mon -= 1; |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 88 | } else if (t = *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 89 | &t.tm_mon, &t.tm_mday, |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 90 | &t.tm_hour, &t.tm_min, |
| 91 | &t.tm_sec) == 6) { |
Eric Andersen | 7b5d594 | 2000-11-29 22:01:42 +0000 | [diff] [blame] | 92 | t.tm_year -= 1900; /* Adjust years */ |
| 93 | t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 94 | } else if (t = *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year, |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 95 | &t.tm_mon, &t.tm_mday, |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 96 | &t.tm_hour, &t.tm_min) == 5) { |
Eric Andersen | 7b5d594 | 2000-11-29 22:01:42 +0000 | [diff] [blame] | 97 | t.tm_year -= 1900; /* Adjust years */ |
| 98 | t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ |
Eric Andersen | 7b5d594 | 2000-11-29 22:01:42 +0000 | [diff] [blame] | 99 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 100 | bb_error_msg_and_die(bb_msg_invalid_date, t_string); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 101 | } |
Eric Andersen | 7b5d594 | 2000-11-29 22:01:42 +0000 | [diff] [blame] | 102 | *tm_time = t; |
| 103 | return (tm_time); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Glenn L McGrath | 5f11541 | 2004-02-17 07:51:31 +0000 | [diff] [blame] | 106 | #define DATE_OPT_RFC2822 0x01 |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 107 | #define DATE_OPT_SET 0x02 |
| 108 | #define DATE_OPT_UTC 0x04 |
| 109 | #define DATE_OPT_DATE 0x08 |
Glenn L McGrath | 01cdb66 | 2004-02-17 12:22:21 +0000 | [diff] [blame] | 110 | #define DATE_OPT_REFERENCE 0x10 |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 111 | #define DATE_OPT_TIMESPEC 0x20 |
| 112 | #define DATE_OPT_HINT 0x40 |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 113 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 114 | int date_main(int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 115 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 116 | char *date_str = NULL; |
| 117 | char *date_fmt = NULL; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 118 | int set_time; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 119 | int utc; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 120 | time_t tm; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 121 | unsigned long opt; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 122 | struct tm tm_time; |
Glenn L McGrath | 01cdb66 | 2004-02-17 12:22:21 +0000 | [diff] [blame] | 123 | char *filename = NULL; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 124 | |
Robert Griebl | df03932 | 2002-07-30 23:11:00 +0000 | [diff] [blame] | 125 | int ifmt = 0; |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 126 | char *isofmt_arg; |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 127 | char *hintfmt_arg; |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 128 | |
"Vladimir N. Oleynik" | f704b27 | 2005-10-14 09:56:52 +0000 | [diff] [blame] | 129 | bb_opt_complementally = "?:d--s:s--d"; |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 130 | opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" |
| 131 | USE_FEATURE_DATE_ISOFMT("I::D:"), |
Glenn L McGrath | 01cdb66 | 2004-02-17 12:22:21 +0000 | [diff] [blame] | 132 | &date_str, &date_str, &filename |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 133 | USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg)); |
Glenn L McGrath | 5f11541 | 2004-02-17 07:51:31 +0000 | [diff] [blame] | 134 | set_time = opt & DATE_OPT_SET; |
| 135 | utc = opt & DATE_OPT_UTC; |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 136 | if (utc && putenv("TZ=UTC0") != 0) { |
Glenn L McGrath | 5f11541 | 2004-02-17 07:51:31 +0000 | [diff] [blame] | 137 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 138 | } |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 139 | |
| 140 | if(ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_TIMESPEC)) { |
Glenn L McGrath | 5f11541 | 2004-02-17 07:51:31 +0000 | [diff] [blame] | 141 | if (!isofmt_arg) { |
| 142 | ifmt = 1; |
| 143 | } else { |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 144 | char *isoformats[]={"date","hours","minutes","seconds"}; |
| 145 | for(ifmt = 4; ifmt;) |
| 146 | if(!strcmp(isofmt_arg,isoformats[--ifmt])) |
| 147 | break; |
Glenn L McGrath | 5f11541 | 2004-02-17 07:51:31 +0000 | [diff] [blame] | 148 | } |
Eric Andersen | 8876fb2 | 2003-06-20 09:01:58 +0000 | [diff] [blame] | 149 | if (!ifmt) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 150 | bb_show_usage(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 151 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 152 | } |
Robert Griebl | df03932 | 2002-07-30 23:11:00 +0000 | [diff] [blame] | 153 | |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 154 | /* XXX, date_fmt == NULL from this always */ |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 155 | if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) { |
| 156 | date_fmt = &argv[optind][1]; /* Skip over the '+' */ |
| 157 | } else if (date_str == NULL) { |
Eric Andersen | add09fd | 2000-07-14 18:39:08 +0000 | [diff] [blame] | 158 | set_time = 1; |
| 159 | date_str = argv[optind]; |
Eric Andersen | add09fd | 2000-07-14 18:39:08 +0000 | [diff] [blame] | 160 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 161 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 162 | /* Now we have parsed all the information except the date format |
| 163 | which depends on whether the clock is being set or read */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 164 | |
Glenn L McGrath | 01cdb66 | 2004-02-17 12:22:21 +0000 | [diff] [blame] | 165 | if(filename) { |
| 166 | struct stat statbuf; |
Rob Landley | c5b1d4d | 2006-03-13 15:45:16 +0000 | [diff] [blame] | 167 | xstat(filename,&statbuf); |
Glenn L McGrath | 01cdb66 | 2004-02-17 12:22:21 +0000 | [diff] [blame] | 168 | tm=statbuf.st_mtime; |
| 169 | } else time(&tm); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 170 | memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); |
| 171 | /* Zero out fields - take her back to midnight! */ |
| 172 | if (date_str != NULL) { |
| 173 | tm_time.tm_sec = 0; |
| 174 | tm_time.tm_min = 0; |
| 175 | tm_time.tm_hour = 0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 176 | |
Glenn L McGrath | 5f11541 | 2004-02-17 07:51:31 +0000 | [diff] [blame] | 177 | /* Process any date input to UNIX time since 1 Jan 1970 */ |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 178 | if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_HINT)) { |
| 179 | strptime(date_str, hintfmt_arg, &tm_time); |
| 180 | } else if (strchr(date_str, ':') != NULL) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 181 | date_conv_ftime(&tm_time, date_str); |
| 182 | } else { |
| 183 | date_conv_time(&tm_time, date_str); |
| 184 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 185 | |
Eric Andersen | 77d9268 | 2001-05-23 20:32:09 +0000 | [diff] [blame] | 186 | /* Correct any day of week and day of year etc. fields */ |
Manuel Novoa III | b511f9c | 2003-07-23 23:24:31 +0000 | [diff] [blame] | 187 | tm_time.tm_isdst = -1; /* Be sure to recheck dst. */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 188 | tm = mktime(&tm_time); |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 189 | if (tm < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 190 | bb_error_msg_and_die(bb_msg_invalid_date, date_str); |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 191 | } |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 192 | if (utc && putenv("TZ=UTC0") != 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 193 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
Eric Andersen | a683ee8 | 2000-11-17 18:51:45 +0000 | [diff] [blame] | 194 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 195 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 196 | /* if setting time, set it */ |
"Vladimir N. Oleynik" | 3ade65f | 2005-10-12 14:36:42 +0000 | [diff] [blame] | 197 | if (set_time && stime(&tm) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 198 | bb_perror_msg("cannot set date"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 201 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 202 | /* Display output */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 203 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 204 | /* Deal with format string */ |
| 205 | if (date_fmt == NULL) { |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 206 | /* Start with the default case */ |
| 207 | |
| 208 | date_fmt = (opt & DATE_OPT_RFC2822 ? |
Eric Andersen | 39396b9 | 2004-04-06 09:38:18 +0000 | [diff] [blame] | 209 | (utc ? "%a, %d %b %Y %H:%M:%S GMT" : |
| 210 | "%a, %d %b %Y %H:%M:%S %z") : |
| 211 | "%a %b %e %H:%M:%S %Z %Y"); |
Glenn L McGrath | 03195fc | 2002-08-23 05:58:38 +0000 | [diff] [blame] | 212 | |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 213 | if (ENABLE_FEATURE_DATE_ISOFMT) { |
| 214 | if (ifmt == 4) |
| 215 | date_fmt = utc ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%dT%H:%M:%S%z"; |
| 216 | else if (ifmt == 3) |
| 217 | date_fmt = utc ? "%Y-%m-%dT%H:%MZ" : "%Y-%m-%dT%H:%M%z"; |
| 218 | else if (ifmt == 2) |
| 219 | date_fmt = utc ? "%Y-%m-%dT%HZ" : "%Y-%m-%dT%H%z"; |
| 220 | else if (ifmt == 1) |
| 221 | date_fmt = "%Y-%m-%d"; |
Robert Griebl | df03932 | 2002-07-30 23:11:00 +0000 | [diff] [blame] | 222 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 223 | } |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 224 | |
| 225 | if (*date_fmt == '\0') { |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 226 | |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 227 | /* With no format string, just print a blank line */ |
| 228 | |
| 229 | *bb_common_bufsiz1=0; |
| 230 | } else { |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 231 | |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 232 | /* Handle special conversions */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 233 | |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 234 | if (strncmp(date_fmt, "%f", 2) == 0) { |
| 235 | date_fmt = "%Y.%m.%d-%H:%M:%S"; |
| 236 | } |
| 237 | |
| 238 | /* Generate output string */ |
"Vladimir N. Oleynik" | a2eec60 | 2005-10-15 13:45:32 +0000 | [diff] [blame] | 239 | strftime(bb_common_bufsiz1, 200, date_fmt, &tm_time); |
Rob Landley | f7662da | 2005-05-28 23:55:26 +0000 | [diff] [blame] | 240 | } |
Rob Landley | c5789a6 | 2006-02-21 05:06:42 +0000 | [diff] [blame] | 241 | puts(bb_common_bufsiz1); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 242 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 243 | return EXIT_SUCCESS; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 244 | } |