Skip to content

Commit

Permalink
gmtime etc. now say "UTC", not "GMT"
Browse files Browse the repository at this point in the history
POSIX is being revised to require this.
* NEWS, etcetera, theory.html: Mention this.
* date.c (dogmt): Simulate gmtime with TZ=UTC0, not GMT0.
* localtime.c (etc_utc): New constant.
(utc): Now an offset from etc_utc, replacing gmt.  All uses changed.
(gmtload): Load from "Etc/UTC", not from "GMT", so that
the abbreviation is "UTC" not "GMT".
  • Loading branch information
eggert committed Jul 19, 2022
1 parent bf8aa94 commit 50df7d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Unreleased, experimental changes
zic now checks its input for NUL bytes and unterminated lines, and
now supports input line lengths up to 2048 (not 512) bytes.

gmtime and related code now use the abbreviation "UTC" not "GMT".
POSIX is being revised to require this.

When tzset and related functions set vestigial static variables
like tzname, they now prefer specified timestamps to unspecified ones.
(Problem reported by Almaz Mingaleev.)
Expand Down
4 changes: 2 additions & 2 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ dogmt(void)
register int from;
register int to;
register int n;
static char tzegmt0[] = "TZ=GMT0";
static char tzeutc0[] = "TZ=UTC0";

for (n = 0; environ[n] != NULL; ++n)
continue;
Expand All @@ -131,7 +131,7 @@ dogmt(void)
exit(retval);
}
to = 0;
fakeenv[to++] = tzegmt0;
fakeenv[to++] = tzeutc0;
for (from = 1; environ[from] != NULL; ++from)
if (strncmp(environ[from], "TZ=", 3) != 0)
fakeenv[to++] = environ[from];
Expand Down
8 changes: 6 additions & 2 deletions etcetera
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
# behind GMT but uses the completely misleading abbreviation "GMT".

Zone Etc/GMT 0 - GMT

# The following zone is used by tzcode functions like gmtime,
# which load the "UTC" file to handle seconds properly.
Zone Etc/UTC 0 - UTC

# The following link uses older naming conventions,
# but it belongs here, not in the file 'backward',
# as functions like gmtime load the "GMT" file to handle leap seconds properly.
# We want this to work even on installations that omit the other older names.
# as it is needed for tzcode releases through 2022a,
# where functions like gmtime load "GMT" instead of the "Etc/UTC".
# We want this to work even on installations that omit 'backward'.
Link Etc/GMT GMT

Link Etc/UTC Etc/Universal
Expand Down
15 changes: 8 additions & 7 deletions localtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static void unlock(void) { }

static const char wildabbr[] = WILDABBR;

static const char gmt[] = "GMT";
static char const etc_utc[] = "Etc/UTC";
static char const *utc = etc_utc + sizeof "Etc/" - 1;

/*
** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
Expand Down Expand Up @@ -125,7 +126,7 @@ struct state {
time_t ats[TZ_MAX_TIMES];
unsigned char types[TZ_MAX_TIMES];
struct ttinfo ttis[TZ_MAX_TYPES];
char chars[max(max(TZ_MAX_CHARS + CHARS_EXTRA, sizeof gmt),
char chars[max(max(TZ_MAX_CHARS + CHARS_EXTRA, sizeof "UTC"),
2 * (MY_TZNAME_MAX + 1))];
struct lsinfo lsis[TZ_MAX_LEAPS];

Expand Down Expand Up @@ -314,7 +315,7 @@ settzname(void)
int stddst_mask = 0;

#if HAVE_TZNAME
tzname[0] = tzname[1] = (char *) (sp ? wildabbr : gmt);
tzname[0] = tzname[1] = (char *) (sp ? wildabbr : utc);
stddst_mask = 3;
#endif
#if USG_COMPAT
Expand Down Expand Up @@ -1393,8 +1394,8 @@ tzparse(const char *name, struct state *sp, struct state *basep)
static void
gmtload(struct state *const sp)
{
if (tzload(gmt, sp, true) != 0)
tzparse("GMT0", sp, NULL);
if (tzload(etc_utc, sp, true) != 0)
tzparse("UTC0", sp, NULL);
}

/* Initialize *SP to a value appropriate for the TZ setting NAME.
Expand All @@ -1412,7 +1413,7 @@ zoneinit(struct state *sp, char const *name)
sp->charcnt = 0;
sp->goback = sp->goahead = false;
init_ttinfo(&sp->ttis[0], 0, false, 0);
strcpy(sp->chars, gmt);
strcpy(sp->chars, utc);
sp->defaulttype = 0;
return 0;
} else {
Expand Down Expand Up @@ -1666,7 +1667,7 @@ gmtsub(struct state const *sp, time_t const *timep, int_fast32_t offset,
** but this is no time for a treasure hunt.
*/
tmp->TM_ZONE = ((char *)
(offset ? wildabbr : gmtptr ? gmtptr->chars : gmt));
(offset ? wildabbr : gmtptr ? gmtptr->chars : utc));
#endif /* defined TM_ZONE */
return result;
}
Expand Down
8 changes: 6 additions & 2 deletions theory.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ <h2 id="naming">Timezone identifiers</h2>
on platforms that do not support POSIX-style <code>TZ</code> strings;
no other source file other than <code>backward</code>
contains links to its zones.
One of <code>etcetera</code>'s names is <code>GMT</code>,
One of <code>etcetera</code>'s names is <code>Etc/UTC</code>,
used by functions like <code>gmtime</code> to obtain leap
second information on platforms that support leap seconds.
Another <code>etcetera</code> name, <code>GMT</code>,
is used by older code releases.
</p>
</section>

Expand Down Expand Up @@ -468,6 +470,7 @@ <h2 id="abbreviations">Time zone abbreviations</h2>
PST/PDT Philippine,
SAST South Africa,
SST Samoa,
UTC Universal,
WAT/WAST West Africa,
WET/WEST/WEMT Western European,
WIB Waktu Indonesia Barat,
Expand Down Expand Up @@ -1295,7 +1298,8 @@ <h2 id="leapsec">Leap seconds</h2>
if no time zone correction is desired,
calls to <code>gmtime</code>-like functions
also need to consult a <abbr>TZif</abbr> file,
conventionally named <samp><abbr>GMT</abbr></samp>,
conventionally named <samp><abbr>Etc/UTC</abbr></samp>
(<samp><abbr>GMT</abbr></samp> in previous versions),
to see whether leap second corrections are needed.
To convert an application's <code>time_t</code> timestamps to or from
POSIX <code>time_t</code> timestamps (for use when, say,
Expand Down

0 comments on commit 50df7d6

Please sign in to comment.