diff options
author | google <google@daverabbitz.ath.cx> | 2012-09-02 23:08:14 +1200 |
---|---|---|
committer | google <google@daverabbitz.ath.cx> | 2012-09-02 23:08:14 +1200 |
commit | dfc348c4e26b9f1bc58b70de94b47915afb1e7bc (patch) | |
tree | 9404c675633248f6013557a8ec5c92387904cc9e | |
parent | cdb7bdde96c0147fffe6d568ac7837839f678d8c (diff) |
Add -i and -t options to date for isodate and isotime display.
-rw-r--r-- | sys/man/1/date | 6 | ||||
-rw-r--r-- | sys/src/cmd/date.c | 25 |
2 files changed, 23 insertions, 8 deletions
diff --git a/sys/man/1/date b/sys/man/1/date index 705a95425..b49d65192 100644 --- a/sys/man/1/date +++ b/sys/man/1/date @@ -24,6 +24,12 @@ Report Greenwich Mean Time (GMT) rather than local time. .B -n Report the date as the number of seconds since the epoch, 00:00:00 GMT, January 1, 1970. +.TP +.B -i +Report the date as ISO-8601 without time and timezone suffix. +.TP +.B -t +Report the date as ISO-8601 with time and timezone suffix. .PP The conversion from Greenwich Mean Time to local time depends on the .B $timezone diff --git a/sys/src/cmd/date.c b/sys/src/cmd/date.c index fc2ec5af5..9d6504b3f 100644 --- a/sys/src/cmd/date.c +++ b/sys/src/cmd/date.c @@ -1,17 +1,19 @@ #include <u.h> #include <libc.h> -int uflg, nflg; +int uflg, nflg, iflg, tflg; void main(int argc, char *argv[]) { ulong now; - + Tm *tm; ARGBEGIN{ case 'n': nflg = 1; break; case 'u': uflg = 1; break; - default: fprint(2, "usage: date [-un] [seconds]\n"); exits("usage"); + case 't': tflg = 1; /* implies -i */ + case 'i': iflg = 1; break; + default: fprint(2, "usage: date [-itun] [seconds]\n"); exits("usage"); }ARGEND if(argc == 1) @@ -21,10 +23,17 @@ main(int argc, char *argv[]) if(nflg) print("%ld\n", now); - else if(uflg) - print("%s", asctime(gmtime(now))); - else - print("%s", ctime(now)); - + else if(iflg) { + tm = uflg ? gmtime(now) : localtime(now); + if(tflg) + print("%s\n", isotime(tm)); + else + print("%s\n", isodate(tm)); + } else { + if(uflg) + print("%s", asctime(gmtime(now))); + else + print("%s", ctime(now)); + } exits(0); } |