diff options
author | Robert Griebl | 2002-07-30 23:11:00 +0000 |
---|---|---|
committer | Robert Griebl | 2002-07-30 23:11:00 +0000 |
commit | df03932b7e933f0f5f55aad24fac3b9d531dc4a1 (patch) | |
tree | 08482ae8240326db062a335d5363a672e78e3b3e /coreutils | |
parent | 70112da81a5591d345dc7e8c9fd23e4e8bb67d17 (diff) | |
download | busybox-df03932b7e933f0f5f55aad24fac3b9d531dc4a1.zip busybox-df03932b7e933f0f5f55aad24fac3b9d531dc4a1.tar.gz |
Added the -I (isofmt) options to date, which comes in handy for scripts
(this is a confiureable option)
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/date.c | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index 41ceee2..4bd308b 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -138,8 +138,15 @@ int date_main(int argc, char **argv) time_t tm; struct tm tm_time; +#ifdef CONFIG_FEATURE_DATE_ISOFMT + int ifmt = 0; +#define GETOPT_ISOFMT "I::" +#else +#define GETOPT_ISOFMT +#endif + /* Interpret command line args */ - while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) { + while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT )) != EOF) { switch (c) { case 'R': rfc822 = 1; @@ -160,11 +167,31 @@ int date_main(int argc, char **argv) if ((date_str != NULL) || ((date_str = optarg) == NULL)) show_usage(); break; +#ifdef CONFIG_FEATURE_DATE_ISOFMT + case 'I': + if ( !optarg ) + ifmt = 1; + else { + int ifmt_len = xstrlen ( optarg ); + + if (( ifmt_len <= 4 ) && ( strncmp ( optarg, "date", ifmt_len ) == 0 )) + ifmt = 1; + else if (( ifmt_len <= 5 ) && ( strncmp ( optarg, "hours", ifmt_len ) == 0 )) + ifmt = 2; + else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "minutes", ifmt_len ) == 0 )) + ifmt = 3; + else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "seconds", ifmt_len ) == 0 )) + ifmt = 4; + } + if ( ifmt ) + break; // else show_usage(); +#endif default: show_usage(); } } + if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) date_fmt = &argv[optind][1]; /* Skip over the '+' */ else if (date_str == NULL) { @@ -220,12 +247,33 @@ int date_main(int argc, char **argv) /* Deal with format string */ if (date_fmt == NULL) { - date_fmt = (rfc822 - ? (utc - ? "%a, %e %b %Y %H:%M:%S GMT" - : "%a, %e %b %Y %H:%M:%S %z") - : "%a %b %e %H:%M:%S %Z %Y"); - +#ifdef CONFIG_FEATURE_DATE_ISOFMT + switch ( ifmt ) { + case 4: + date_fmt = utc ? "%Y-%m-%dT%H:%M:%SZ" : "%Y-%m-%dT%H:%M:%S%z"; + break; + case 3: + date_fmt = utc ? "%Y-%m-%dT%H:%MZ" : "%Y-%m-%dT%H:%M%z"; + break; + case 2: + date_fmt = utc ? "%Y-%m-%dT%HZ" : "%Y-%m-%dT%H%z"; + break; + case 1: + date_fmt = "%Y-%m-%d"; + break; + case 0: + default: +#endif + date_fmt = (rfc822 + ? (utc + ? "%a, %e %b %Y %H:%M:%S GMT" + : "%a, %e %b %Y %H:%M:%S %z") + : "%a %b %e %H:%M:%S %Z %Y"); + +#ifdef CONFIG_FEATURE_DATE_ISOFMT + break; + } +#endif } else if (*date_fmt == '\0') { /* Imitate what GNU 'date' does with NO format string! */ printf("\n"); |