diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-02-02 18:30:29 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-02-02 20:12:31 +0100 |
commit | 1bb4b028a380d74cff6399ea1d8ffcf1b2f122bc (patch) | |
tree | 041f20a932fbf9d318cf5484bf5e22e8cddae5bc /src/basic/time-util.h | |
parent | time: time_t is signed, and mktime() is happy to return negative time (diff) | |
download | systemd-1bb4b028a380d74cff6399ea1d8ffcf1b2f122bc.tar.xz systemd-1bb4b028a380d74cff6399ea1d8ffcf1b2f122bc.zip |
time-util: refuse formatting/parsing times that we can't store
usec_t is always 64bit, which means it can cover quite a number of
years. However, 4 digit year display and glibc limitations around time_t
limit what we can actually parse and format. Let's make this explicit,
so that we never end up formatting dates we can#t parse and vice versa.
Note that this is really just about formatting/parsing. Internal
calculations with times outside of the formattable range are not
affected.
Diffstat (limited to 'src/basic/time-util.h')
-rw-r--r-- | src/basic/time-util.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/basic/time-util.h b/src/basic/time-util.h index f67a4474ed..7463507f51 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -181,3 +181,14 @@ static inline usec_t usec_sub(usec_t timestamp, int64_t delta) { return timestamp - delta; } + +#if SIZEOF_TIME_T == 8 +/* The last second we can format is 31. Dec 9999, 1s before midnight, because otherwise we'd enter 5 digit year + * territory. However, since we want to stay away from this in all timezones we take one day off. */ +#define USEC_TIMESTAMP_FORMATTABLE_MAX ((usec_t) 253402214399000000) +#elif SIZEOF_TIME_T == 4 +/* With a 32bit time_t we can't go beyond 2038... */ +#define USEC_TIMESTAMP_FORMATTABLE_MAX ((usec_t) 2147483647000000) +#else +#error "Yuck, time_t is neither 4 not 8 bytes wide?" +#endif |