aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-11-28 23:04:09 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-28 23:04:09 +0100
commit4dee01605996be88ec247256eb47d2686f6b7104 (patch)
treec063398407e4d3984815d76495e46896a3247fb6
parent56a5731a1a06ab785fc327b2a864466325fd262e (diff)
downloadbusybox-w32-4dee01605996be88ec247256eb47d2686f6b7104.tar.gz
busybox-w32-4dee01605996be88ec247256eb47d2686f6b7104.tar.bz2
busybox-w32-4dee01605996be88ec247256eb47d2686f6b7104.zip
date: tweak --help: -D FMT is used for -s TIME as well
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/date.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index 585866fd2..dfc1c7663 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -93,23 +93,21 @@
93 */ 93 */
94 94
95//usage:#define date_trivial_usage 95//usage:#define date_trivial_usage
96//usage: "[OPTIONS] [+FMT] [TIME]" 96//usage: "[OPTIONS] [+FMT] [[-s] TIME]"
97//usage:#define date_full_usage "\n\n" 97//usage:#define date_full_usage "\n\n"
98//usage: "Display time (using +FMT), or set time\n" 98//usage: "Display time (using +FMT), or set time\n"
99//usage: "\n -u Work in UTC (don't convert to local time)" 99//usage: "\n -u Work in UTC (don't convert to local time)"
100//usage: "\n [-s] TIME Set time to TIME" 100//usage: "\n [-s] TIME Set time to TIME"
101//usage: "\n -d TIME Display TIME, not 'now'" 101//usage: "\n -d TIME Display TIME, not 'now'"
102//usage: IF_FEATURE_DATE_ISOFMT( 102//usage: IF_FEATURE_DATE_ISOFMT(
103//usage: "\n -D FMT Use FMT (strptime format) for -d TIME conversion" 103//usage: "\n -D FMT FMT (strptime format) for -s/-d TIME conversion"
104//////// ^^^^^^ busybox invention, not compat 104////////^^^^^^^^^^^^^^^^^^^^^^ busybox invention, not compat
105//usage: ) 105//usage: )
106//usage: "\n -r FILE Display last modification time of FILE" 106//usage: "\n -r FILE Display last modification time of FILE"
107//usage: "\n -R Output RFC-2822 date" 107//usage: "\n -R Output RFC-2822 date"
108//usage: IF_FEATURE_DATE_ISOFMT( 108//usage: IF_FEATURE_DATE_ISOFMT(
109//usage: "\n -I[SPEC] Output ISO-8601 date" 109//usage: "\n -I[SPEC] Output ISO-8601 date"
110//usage: "\n SPEC='date' (default) for date only," 110//usage: "\n SPEC=date (default), hours, minutes, seconds or ns"
111//usage: "\n 'hours', 'minutes', 'seconds' or 'ns'"
112//usage: "\n for date and time"
113//usage: ) 111//usage: )
114//usage: "\n" 112//usage: "\n"
115//usage: "\nRecognized TIME formats:" 113//usage: "\nRecognized TIME formats:"
@@ -137,8 +135,8 @@ enum {
137 OPT_UTC = (1 << 2), /* u */ 135 OPT_UTC = (1 << 2), /* u */
138 OPT_DATE = (1 << 3), /* d */ 136 OPT_DATE = (1 << 3), /* d */
139 OPT_REFERENCE = (1 << 4), /* r */ 137 OPT_REFERENCE = (1 << 4), /* r */
140 OPT_TIMESPEC = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */ 138 OPT_ISO8601 = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
141 OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ 139 OPT_STR2DT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
142}; 140};
143 141
144#if ENABLE_LONG_OPTS 142#if ENABLE_LONG_OPTS
@@ -160,12 +158,6 @@ static const char date_longopts[] ALIGN1 =
160 * - after xasprintf we use other xfuncs 158 * - after xasprintf we use other xfuncs
161 */ 159 */
162 160
163static void maybe_set_utc(int opt)
164{
165 if (opt & OPT_UTC)
166 putenv((char*)"TZ=UTC0");
167}
168
169int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 161int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
170int date_main(int argc UNUSED_PARAM, char **argv) 162int date_main(int argc UNUSED_PARAM, char **argv)
171{ 163{
@@ -173,7 +165,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
173 struct tm tm_time; 165 struct tm tm_time;
174 char buf_fmt_dt2str[64]; 166 char buf_fmt_dt2str[64];
175 unsigned opt; 167 unsigned opt;
176 int ifmt = -1; 168 int isofmt = -1;
177 char *date_str; 169 char *date_str;
178 char *fmt_dt2str; 170 char *fmt_dt2str;
179 char *fmt_str2dt; 171 char *fmt_str2dt;
@@ -192,15 +184,16 @@ int date_main(int argc UNUSED_PARAM, char **argv)
192 ); 184 );
193 argv += optind; 185 argv += optind;
194 186
195 maybe_set_utc(opt); 187 if (opt & OPT_UTC)
188 putenv((char*)"TZ=UTC0");
196 189
197 if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_TIMESPEC)) { 190 if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_ISO8601)) {
198 ifmt = 0; /* default is date */ 191 isofmt = 0; /* default is date */
199 if (isofmt_arg) { 192 if (isofmt_arg) {
200 static const char isoformats[] ALIGN1 = 193 static const char isoformats[] ALIGN1 =
201 "date\0""hours\0""minutes\0""seconds\0ns\0"; 194 "date\0""hours\0""minutes\0""seconds\0ns\0";
202 ifmt = index_in_substrings(isoformats, isofmt_arg); 195 isofmt = index_in_substrings(isoformats, isofmt_arg);
203 if (ifmt < 0) 196 if (isofmt < 0)
204 bb_show_usage(); 197 bb_show_usage();
205 } 198 }
206 } 199 }
@@ -210,7 +203,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
210 fmt_dt2str = &argv[0][1]; /* skip over the '+' */ 203 fmt_dt2str = &argv[0][1]; /* skip over the '+' */
211 argv++; 204 argv++;
212 } 205 }
213 if (!(opt & (OPT_SET | OPT_DATE))) { 206 if (!(opt & (OPT_SET | OPT_DATE))) { /* neither -s TIME nor -d TIME? */
214 opt |= OPT_SET; 207 opt |= OPT_SET;
215 date_str = argv[0]; /* can be NULL */ 208 date_str = argv[0]; /* can be NULL */
216 if (date_str) { 209 if (date_str) {
@@ -278,7 +271,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
278 tm_time.tm_hour = 0; 271 tm_time.tm_hour = 0;
279 272
280 /* Process any date input to UNIX time since 1 Jan 1970 */ 273 /* Process any date input to UNIX time since 1 Jan 1970 */
281 if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_HINT)) { 274 if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_STR2DT)) {
282 if (strptime(date_str, fmt_str2dt, &tm_time) == NULL) 275 if (strptime(date_str, fmt_str2dt, &tm_time) == NULL)
283 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 276 bb_error_msg_and_die(bb_msg_invalid_date, date_str);
284 } else { 277 } else {
@@ -304,13 +297,13 @@ int date_main(int argc UNUSED_PARAM, char **argv)
304 if (fmt_dt2str == NULL) { 297 if (fmt_dt2str == NULL) {
305 int i; 298 int i;
306 fmt_dt2str = buf_fmt_dt2str; 299 fmt_dt2str = buf_fmt_dt2str;
307 if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) { 300 if (ENABLE_FEATURE_DATE_ISOFMT && isofmt >= 0) {
308 /* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds 4:ns*/ 301 /* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds 4:ns*/
309 strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S"); 302 strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S");
310 i = 8 + 3 * ifmt; 303 i = 8 + 3 * isofmt;
311 if (ifmt != 0) { 304 if (isofmt != 0) {
312 int n; 305 int n;
313 if (ifmt == 4) { 306 if (isofmt == 4) {
314 i -= 3; 307 i -= 3;
315 i += sprintf(&fmt_dt2str[i], ",%09u", (unsigned)ts.tv_nsec); 308 i += sprintf(&fmt_dt2str[i], ",%09u", (unsigned)ts.tv_nsec);
316 } 309 }