From: Alan Cox Date: Sat, 21 Jul 2018 23:35:11 +0000 (+0100) Subject: date: rewrite and add manual page X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=d3f8ac6f3d5cb35b5963bae2153c49e31b49a7ef;p=FUZIX.git date: rewrite and add manual page We still need to support custom formats but that needs the fancy time format stuff we don't yet have. --- diff --git a/Applications/util/date.1 b/Applications/util/date.1 new file mode 100644 index 00000000..85fa4142 --- /dev/null +++ b/Applications/util/date.1 @@ -0,0 +1,12 @@ +DATE(1) +## NAME +*date* - display the current time and date +## SYNOPSIS +*date* \[-u\] +## DESCRIPTION +The *date* command displays the current date and time. If the *-u* option is +specified the time and date are shown in UTC, otherwise they are shown in +local time. +## STANDARDS +The *date* command is from POSIX 1003.1P. Fuzix does not currently implement +custom formats or system time setting via date. diff --git a/Applications/util/date.c b/Applications/util/date.c index cbb20de2..9f5e0361 100644 --- a/Applications/util/date.c +++ b/Applications/util/date.c @@ -1,15 +1,40 @@ #include +#include #include #include -int main(int argc, char *argv[]) +static void usage(void) { - time_t now; - const char *p; + write(2, "date: [-u]\n", 11); + exit(EXIT_FAILURE); +} - now = time(NULL); - p = ctime(&now); - write(1, p, strlen(p)); +int main(int argc, char *argv[]) +{ + time_t t; + struct tm *tm; + const char *ts, *z; + int utc = 0; + + if (argc > 1 && strcmp(argv[1], "-u") == 0) { + utc = 1; + argc--; + } + if (argc != 1) + usage(); + time(&t); + if (utc) + tm = gmtime(&t); + else + tm = localtime(&t); + ts = asctime(tm); + /* Up to the time zone */ + write(1, ts, 20); + /* Zone */ + z = tzname[tm->tm_isdst]; + write(1, z, strlen(z)); + /* Year */ + write(1, ts + 19, 6); return 0; }