diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-06-04 12:52:39 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-06-04 12:52:39 -0400 |
commit | c6bb003b8882e9a16941f5803d072ec1cb728318 (patch) | |
tree | 273d7b3de70212b75bf6c841c70142a00fec5d3c /src | |
parent | 3da7fe8b4f5d6a41152d81bbfbd30b0ab3a9da1c (diff) | |
download | bfs-c6bb003b8882e9a16941f5803d072ec1cb728318.tar.xz |
xtime: Add support for @epochseconds timestamps
Diffstat (limited to 'src')
-rw-r--r-- | src/xtime.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/xtime.c b/src/xtime.c index 2808455..186651b 100644 --- a/src/xtime.c +++ b/src/xtime.c @@ -206,6 +206,23 @@ static int xgetpart(const char **str, size_t n, int *result) { } int xgetdate(const char *str, struct timespec *result) { + // Handle @epochseconds + if (str[0] == '@') { + long long value; + if (xstrtoll(str + 1, NULL, 10, &value) != 0) { + goto error; + } + + time_t time = (time_t)value; + if ((long long)time != value) { + errno = ERANGE; + goto error; + } + + result->tv_sec = time; + goto done; + } + struct tm tm = { .tm_isdst = -1, }; @@ -324,6 +341,7 @@ end: } } +done: result->tv_nsec = 0; return 0; |