Added the -I (isofmt) options to date, which comes in handy for scripts
(this is a confiureable option)
This commit is contained in:
parent
70112da81a
commit
df03932b7e
@ -138,8 +138,15 @@ int date_main(int argc, char **argv)
|
|||||||
time_t tm;
|
time_t tm;
|
||||||
struct tm tm_time;
|
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 */
|
/* Interpret command line args */
|
||||||
while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
|
while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT )) != EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'R':
|
case 'R':
|
||||||
rfc822 = 1;
|
rfc822 = 1;
|
||||||
@ -160,11 +167,31 @@ int date_main(int argc, char **argv)
|
|||||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||||
show_usage();
|
show_usage();
|
||||||
break;
|
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:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
|
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
|
||||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||||
else if (date_str == NULL) {
|
else if (date_str == NULL) {
|
||||||
@ -220,12 +247,33 @@ int date_main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Deal with format string */
|
/* Deal with format string */
|
||||||
if (date_fmt == NULL) {
|
if (date_fmt == NULL) {
|
||||||
|
#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
|
date_fmt = (rfc822
|
||||||
? (utc
|
? (utc
|
||||||
? "%a, %e %b %Y %H:%M:%S GMT"
|
? "%a, %e %b %Y %H:%M:%S GMT"
|
||||||
: "%a, %e %b %Y %H:%M:%S %z")
|
: "%a, %e %b %Y %H:%M:%S %z")
|
||||||
: "%a %b %e %H:%M:%S %Z %Y");
|
: "%a %b %e %H:%M:%S %Z %Y");
|
||||||
|
|
||||||
|
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else if (*date_fmt == '\0') {
|
} else if (*date_fmt == '\0') {
|
||||||
/* Imitate what GNU 'date' does with NO format string! */
|
/* Imitate what GNU 'date' does with NO format string! */
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user