diff options
author | Jim Meyering <jim@meyering.net> | 1996-01-06 06:07:23 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1996-01-06 06:07:23 +0000 |
commit | 0f100b0d3f541e0bcc107eb8cc416277ce759109 (patch) | |
tree | 003f7195aada80ca93152b559f6a655c29dd46f8 /src/date.c | |
parent | 83adf65c37e49075499f2624e2eb45e7f2c0f380 (diff) | |
download | coreutils-0f100b0d3f541e0bcc107eb8cc416277ce759109.tar.xz |
(putenv): Declare.
(universal_time): Remove.
(main): If -u is given, set TZ to "UTC0"; this causes date to use
UTC uniformly and fixes bugs in the handling of date -u +'%s %Z'.
(show_date): Just use localtime and a single format, since TZ will
be set properly if -u is given. From Paul Eggert.
Diffstat (limited to 'src/date.c')
-rw-r--r-- | src/date.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/date.c b/src/date.c index 378b30262..eabecd85c 100644 --- a/src/date.c +++ b/src/date.c @@ -38,6 +38,7 @@ size_t strftime (); time_t time (); #endif +int putenv (); int stime (); char *xrealloc (); @@ -56,9 +57,6 @@ static int show_help; /* If nonzero, print the version on standard output and exit. */ static int show_version; -/* If nonzero, print or set Coordinated Universal Time. */ -static int universal_time = 0; - static struct option const long_options[] = { {"date", required_argument, NULL, 'd'}, @@ -179,7 +177,11 @@ main (argc, argv) set_date = 1; break; case 'u': - universal_time = 1; + if (putenv ("TZ=UTC0") != 0) + error (1, 0, "memory exhausted"); +#if LOCALTIME_CACHE + tzset (); +#endif break; default: usage (1); @@ -307,16 +309,14 @@ show_date (format, when) char *out = NULL; size_t out_length = 0; - tm = (universal_time ? gmtime : localtime) (&when); + tm = localtime (&when); if (format == NULL) { /* Print the date in the default format. Vanilla ANSI C strftime doesn't support %e, but POSIX requires it. If you don't use a GNU strftime, make sure yours supports %e. */ - format = (universal_time - ? "%a %b %e %H:%M:%S UTC %Y" - : "%a %b %e %H:%M:%S %Z %Y"); + format = "%a %b %e %H:%M:%S %Z %Y"; } else if (*format == '\0') { |