summaryrefslogtreecommitdiffstats
path: root/include/timeutils.h
Commit message (Collapse)AuthorAgeFilesLines
* timeutils: match today day and this year correctlySami Kerola2019-01-121-3/+0Star
| | | | | | | | | Assumption all years since 1970 have been exactly 365 days long has it's problems when leap years happen. Lets use struct tm fields that are provided by localtime_r(), making year and day to be correctly compared even when it's late new years eve somewhere else than UTC-0. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/timeutils: add common ISO timestamp masksJ William Piggott2017-11-101-9/+17
| | | | | | | | | | | | | | | | | | | | | | * Start the ISO format flags at bit 0 instead of bit 1. * Remove unnecessary _8601 from ISO format flag names to avoid line wrapping and to ease readability. * ISO timestamps have date-time-timzone in common, so move the TIMEZONE flag to bit 2 causing all timestamp masks to have the first three bits set and the last four bits as timestamp 'options'. * Change the 'SPACE' flag to a 'T' flag, because it makes the code and comments more concise. * Add common ISO timestamp masks. * Implement the ISO timestamp masks in all applicable code using the strxxx_iso() functions. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils: add get_gmtoff()J William Piggott2017-11-101-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This new function returns the GMT offset relative to its argument. It is used in this patch to fix two bugs: 1) On platforms that the tm struct excludes tm_gmtoff, hwclock assumes a one hour DST offset. This can cause an incorrect kernel timezone setting. For example: Master branch tested with tm_gmtoff illustrates the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494204.192398, -660) Master branch tested without tm_gmtoff has an incorrect offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494249.193852, -690) Patched tested without tm_gmtoff has the correct offset: $ TZ="Australia/Lord_Howe" hwclock --hctosys --test | grep settimeofday Calling settimeofday(1507494260.194208, -660) 2) ISO 8601 'extended' format requires all time elements to use a colon (:). Current invalid ISO 8601: $ hwclock 2017-10-08 16:25:17.895462-0400 Patched: $ hwclock 2017-10-08 16:25:34.141895-04:00 Also required by this change: login-utils/last.c: increase ISO out_len and in_len by one to accommodate the addition of the timezone colon. Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib/timeutils: ISO_8601_BUFSIZ too smallJ William Piggott2017-11-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although iso-8601 specifies years as 4 digits, it allows them to be wider. The current POSIX year width is limited by 'int tm_year' at 10 digits plus a negative sign. That, and the possibility of nanosecond time makes the widest POSIX iso-8601 time 41 characters. Plus the \0 string terminator yields a buffer size of 42. Before truncated output: /sbin/hwclock --utc --noadjfile --predict --date '-2147483765 years' -2147481748-09-25 20:29:45.0000 Patched: ./hwclock --utc --noadjfile --predict --date '-2147483765 years' -2147481748-09-25 20:17:21.000000-0456 ./hwclock --utc --noadjfile --predict --date '-2147483766 years' hwclock: invalid date '-2147483766 years' Comparable to coreutils 'date' command: date -Ins --date '-2147483765 years' -2147481748-09-25T19:49:31,578899297-0456 date -Ins --date '-2147483766 years' date: invalid date '-2147483766 years' The 'date' output illustrates the full 41 character POSIX iso-8601 Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib: add parse-date.yJ William Piggott2017-03-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | | * include/timeutils.h Add parse-date API * lib/parse-date.y - new file Lib function that parses a date string into a timespec struct. Derived from gnulib-dd7a871 parse-datetime.y with these changes: * reduced to a single function API renamed to parse_date() * removed gnulib dependencies * removed debugging * converted to util-linux coding style * include/cctype.h - new file Like ctype.h only hard coded to the 'C' locale. Used by lib/parse-date.y. Derived from gnulib-dd7a871 c-ctype.h with these changes: * removed gnulib dependencies * converted to util-linux coding style * add requisite util-linux constants Signed-off-by: J William Piggott <elseifthen@gmx.com>
* lib: add timegm() portability function to lib/timeutils.cSami Kerola2017-02-031-0/+4
| | | | | | | | | Local timegm() is a replacement function in cases it is missing from libc implementation. Hopefully the replacement is never, or very rarely, used. CC: Ruediger Meier <ruediger.meier@ga-group.nl> Reviewed-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libcommon: add ISO_8601_GMTIME that will print UTC-0 timestampsSami Kerola2016-06-261-1/+2
| | | | | | | When timestamps are intented to be conversable back from string to binary it is best to stick with UTC-0 timezone. This is needed in utmpdump(1). Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/timeutils: add strtime_short()Karel Zak2016-05-241-0/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/timeutils: rewrite iso formatting functionsKarel Zak2016-05-241-6/+10
| | | | | | | | | - use buffers rather than allocate memory - support .usec and ,usec convention - use strftime for timezone (we need to care about daylight saving time) Signed-off-by: Karel Zak <kzak@redhat.com>
* include/timeutils: use pointer for time_tKarel Zak2016-05-231-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timeutils: add strxxx_iso() functionsKarel Zak2016-05-111-0/+13
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: move all around clock_gettime() to monotonic.cKarel Zak2014-11-191-2/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: use monotonic time rater than gettimeofdayKarel Zak2014-11-181-0/+3
| | | | | | Based on patch Alexander Samilovskih <alexsamilovskih@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/timeutils: remove get_boot_time from libcommonKarel Zak2014-05-061-1/+0Star
| | | | | | | | clock_gettime() needs -lrt, so let's keep this stuff outside libcommon.la Reported-by: Ruediger Meier <sweet_f_a@gmx.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* dmesg: move get_boot_time() to lib/timeutilsSami Kerola2014-05-041-0/+1
| | | | | | In future the last(1) will use get_boot_time() as well. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib: rename time-util.c to timeutils.c, fix headersKarel Zak2013-09-101-0/+55
Signed-off-by: Karel Zak <kzak@redhat.com>