diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2011-03-11 18:22:50 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2011-03-11 18:22:50 +0000 |
commit | 168f2e6cc1e3d6e59469c4b110b51e8a5e437949 (patch) | |
tree | 670cd46bf0c0080e6cfbb3583c7dfa17f32ac828 /bin/date | |
parent | e12dfdeade939ad75b101eac85b11cf4ca81892f (diff) |
Add a non-standard option that affects the output TZ only. The input (for
parsing) TZ is unaffected. This makes it it easier to convert timestamps
from any timezone to any other timezone -- no need for $() gymnastics
ok millert
Diffstat (limited to 'bin/date')
-rw-r--r-- | bin/date/date.1 | 15 | ||||
-rw-r--r-- | bin/date/date.c | 16 |
2 files changed, 23 insertions, 8 deletions
diff --git a/bin/date/date.1 b/bin/date/date.1 index e6b96016caf..09be59bf0a9 100644 --- a/bin/date/date.1 +++ b/bin/date/date.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: date.1,v 1.54 2010/09/19 20:55:25 jmc Exp $ +.\" $OpenBSD: date.1,v 1.55 2011/03/11 18:22:49 deraadt Exp $ .\" $NetBSD: date.1,v 1.12 1996/03/12 04:32:37 phil Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 @@ -33,7 +33,7 @@ .\" .\" @(#)date.1 8.3 (Berkeley) 4/28/95 .\" -.Dd $Mdocdate: September 19 2010 $ +.Dd $Mdocdate: March 11 2011 $ .Dt DATE 1 .Os .Sh NAME @@ -45,6 +45,7 @@ .Op Fl d Ar dst .Op Fl r Ar seconds .Op Fl t Ar minutes_west +.Op Fl z Ar output_zone .Op Cm + Ns Ar format .Sm off .Oo Oo Oo Oo Oo Oo @@ -112,6 +113,14 @@ by future calls to .Xr gettimeofday 2 . .It Fl u Display or set the date in UTC (Coordinated Universal) time. +.It Fl z Ar output_zone +Just before printing the time, change to the specified timezone; +see the description of +.Ev TZ +below. +This can be used with +.Fl j +to easily convert time specifications from one zone to another. .El .Pp An operand with a leading plus sign @@ -159,7 +168,7 @@ and leap years are handled automatically. .Sh ENVIRONMENT .Bl -tag -width Ds .It Ev TZ -The time zone to use when displaying dates. +The time zone to use when parsing or displaying dates. See .Xr environ 7 for more information. diff --git a/bin/date/date.c b/bin/date/date.c index 022ef1c59cc..891e6313fcd 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -1,4 +1,4 @@ -/* $OpenBSD: date.c,v 1.34 2011/03/11 17:11:15 deraadt Exp $ */ +/* $OpenBSD: date.c,v 1.35 2011/03/11 18:22:49 deraadt Exp $ */ /* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */ /* @@ -63,13 +63,13 @@ main(int argc, char *argv[]) { struct timezone tz; int ch, rflag; - char *format, buf[1024]; + char *format, buf[1024], *outzone = NULL; setlocale(LC_ALL, ""); tz.tz_dsttime = tz.tz_minuteswest = 0; rflag = 0; - while ((ch = getopt(argc, argv, "ad:jnr:ut:")) != -1) + while ((ch = getopt(argc, argv, "ad:jnr:ut:z:")) != -1) switch((char)ch) { case 'd': /* daylight saving time */ tz.tz_dsttime = atoi(optarg) ? 1 : 0; @@ -98,6 +98,9 @@ main(int argc, char *argv[]) break; } /* FALLTHROUGH */ + case 'z': + outzone = optarg; + break; default: usage(); } @@ -138,6 +141,9 @@ main(int argc, char *argv[]) if (argc > 0) errx(1, "too many arguments"); + if (outzone) + setenv("TZ", outzone, 1); + (void)strftime(buf, sizeof(buf), format, localtime(&tval)); (void)printf("%s\n", buf); exit(retval); @@ -270,9 +276,9 @@ static void usage(void) { (void)fprintf(stderr, - "usage: %s [-ajnu] [-d dst] [-r seconds] [-t minutes_west] [+format]\n", + "usage: %s [-ajnu] [-d dst] [-r seconds] [-t minutes_west] [-z output_zone]\n", __progname); (void)fprintf(stderr, - "%-*s[[[[[[cc]yy]mm]dd]HH]MM[.SS]]\n", (int)strlen(__progname) + 8, ""); + "%-*s[+format] [[[[[[cc]yy]mm]dd]HH]MM[.SS]]\n", (int)strlen(__progname) + 8, ""); exit(1); } |