diff options
author | J William Piggott | 2017-10-15 02:37:11 +0200 |
---|---|---|
committer | J William Piggott | 2017-11-10 22:34:55 +0100 |
commit | 4111bb3ab5f406ee381a3807385af59fe33b28f3 (patch) | |
tree | d03f85ab061bfade57c03c716e5226048fcdc8af /include | |
parent | lib/timeutils: add get_gmtoff() (diff) | |
download | kernel-qcow2-util-linux-4111bb3ab5f406ee381a3807385af59fe33b28f3.tar.gz kernel-qcow2-util-linux-4111bb3ab5f406ee381a3807385af59fe33b28f3.tar.xz kernel-qcow2-util-linux-4111bb3ab5f406ee381a3807385af59fe33b28f3.zip |
lib/timeutils: add common ISO timestamp masks
* 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>
Diffstat (limited to 'include')
-rw-r--r-- | include/timeutils.h | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/include/timeutils.h b/include/timeutils.h index e8a261462..230e6db5f 100644 --- a/include/timeutils.h +++ b/include/timeutils.h @@ -55,18 +55,26 @@ typedef uint64_t nsec_t; int parse_timestamp(const char *t, usec_t *usec); int get_gmtoff(const struct tm *tp); -/* flags for strxxx_iso() functions */ +/* flags and masks for strxxx_iso() functions */ enum { - ISO_8601_DATE = (1 << 1), - ISO_8601_TIME = (1 << 2), - ISO_8601_DOTUSEC = (1 << 3), - ISO_8601_COMMAUSEC = (1 << 4), - ISO_8601_TIMEZONE = (1 << 5), - ISO_8601_SPACE = (1 << 6), - ISO_8601_GMTIME = (1 << 7) + ISO_DATE = (1 << 0), + ISO_TIME = (1 << 1), + ISO_TIMEZONE = (1 << 2), + ISO_DOTUSEC = (1 << 3), + ISO_COMMAUSEC = (1 << 4), + ISO_T = (1 << 5), + ISO_GMTIME = (1 << 6), + ISO_TIMESTAMP = ISO_DATE | ISO_TIME | ISO_TIMEZONE, + ISO_TIMESTAMP_T = ISO_TIMESTAMP | ISO_T, + ISO_TIMESTAMP_DOT = ISO_TIMESTAMP | ISO_DOTUSEC, + ISO_TIMESTAMP_DOT_T = ISO_TIMESTAMP_DOT | ISO_T, + ISO_TIMESTAMP_COMMA = ISO_TIMESTAMP | ISO_COMMAUSEC, + ISO_TIMESTAMP_COMMA_T = ISO_TIMESTAMP_COMMA | ISO_T, + ISO_TIMESTAMP_COMMA_G = ISO_TIMESTAMP_COMMA | ISO_GMTIME, + ISO_TIMESTAMP_COMMA_GT = ISO_TIMESTAMP_COMMA_G | ISO_T }; -#define ISO_8601_BUFSIZ 42 +#define ISO_BUFSIZ 42 int strtimeval_iso(struct timeval *tv, int flags, char *buf, size_t bufsz); int strtm_iso(struct tm *tm, int flags, char *buf, size_t bufsz); |