More Document Number: N2833
Submitter: Aaron Peter Bachmann
Submission Date: 2021-10-07
Add timegm() as non-optional part of
For the local time we have
localtime_r() to convert from
struct tm and
mktime() to convert
back. For UTC we have
to convert from
but the function to convert
struct tm to UTC is
missing from the C-Standard. This paper proposes the addition of
time_t timegm(struct tm *timeptr) to
fill the gap.
timegm()has its origin in BSD.
Several proposals (N2337 , N2417 , N2459 ) to improve and extend the time-related functions are already incorporated into the working draft N2596 .
UTC is often used since UTC is unique around the world. The use
of UTC is especially desirable if systems are spanning multiple
time-zones or devices move from one time-zone to another. In
addition when UTC is used there are fewer configuration issues.
Existing protocols, configuration-files and user interfaces and
(peripheral) devices (e. g. realtime-clocks) often utilize
broken down times. Implementing and testing
over and over again or alternatively locating a
implementation and verifying the code and its licence over and
over again is a waste of development-time. Temporarily changing
the timezone and using
mktime() is bad, since it
introduces a race-condition. It has a low implementation burden
once you have the source of
shall be defined by the C-standard.
The changes given here are relative to N2596 .
126.96.36.199 The mktime function
In B.26 Date and time <time.h>
time_t mktime(struct tm *timeptr);
Do we want to change the signatures to
time_t mktime(const struct tm *timeptr)
time_t gmtime(const struct tm *timeptr) ?
This might bring us in conflict with POSIX.
2019/02/03 Stoughton, Proposal To Add Extended Month Name
Formats to strftime()
2019/09/08 Gustedt, Modernize time.h functions v.2x
2019/11/18 Gustedt, Add an interface to query resolution of time
2020/12/12 Meneide, C2x Working Draft
Loosemore et alt., The GNU C Library Reference Manual