diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-02-13 16:30:05 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-02-13 16:39:30 -0500 |
commit | 95f862fdd82a99e30bbf2c43009ec9a51e416804 (patch) | |
tree | 0edafaf7a69935d56dc4ce8b442325e12dfd88ff /parse.c | |
parent | 2cdc648441794db0f84518f79e8aaf3ead68f110 (diff) | |
download | bfs-95f862fdd82a99e30bbf2c43009ec9a51e416804.tar.xz |
parse: Handle 1969-12-31T23:59:59Z
mktime() returns -1 on error, but also for one second before the epoch.
Compare the input against localtime(-1) to distinguish those cases.
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -1129,9 +1129,9 @@ static struct expr *parse_daystart(struct parser_state *state, int arg1, int arg tm.tm_min = 0; tm.tm_sec = 0; - time_t time = mktime(&tm); - if (time == -1) { - perror("mktime()"); + time_t time; + if (xmktime(&tm, &time) != 0) { + perror("xmktime()"); return NULL; } @@ -1753,23 +1753,20 @@ static int parse_timestamp(const struct parser_state *state, struct expr *expr) end: if (local) { - expr->reftime.tv_sec = mktime(&tm); - if (expr->reftime.tv_sec == -1) { - perror("mktime()"); - return -1; + if (xmktime(&tm, &expr->reftime.tv_sec) != 0) { + goto error; } } else { - expr->reftime.tv_sec = xtimegm(&tm); - if (expr->reftime.tv_sec == -1) { - perror("xtimegm()"); - return -1; + if (xtimegm(&tm, &expr->reftime.tv_sec) != 0) { + goto error; } int offset = 60*tz_hour + tz_min; if (tz_negative) { - offset = -offset; + expr->reftime.tv_sec -= offset; + } else { + expr->reftime.tv_sec += offset; } - expr->reftime.tv_sec += offset; } expr->reftime.tv_nsec = 0; @@ -1809,6 +1806,10 @@ invalid: fprintf(stderr, " - %04d-%02d-%02dT%02d:%02d:%02dZ\n", year, month, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); return -1; + +error: + parse_error(state, "%s %s: Error parsing timestamp: %m.\n", expr->argv[0], expr->argv[1]); + return -1; } /** |