summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-02-13 16:30:05 -0500
committerTavian Barnes <tavianator@tavianator.com>2020-02-13 16:39:30 -0500
commit95f862fdd82a99e30bbf2c43009ec9a51e416804 (patch)
tree0edafaf7a69935d56dc4ce8b442325e12dfd88ff /parse.c
parent2cdc648441794db0f84518f79e8aaf3ead68f110 (diff)
downloadbfs-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.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/parse.c b/parse.c
index 6ffe8e7..ada0ec2 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
}
/**