time-util: introduce parse_gmtoff() helper function

This commit is contained in:
Yu Watanabe
2025-09-27 11:52:24 +09:00
parent e3f561a624
commit 23407c1806
3 changed files with 43 additions and 0 deletions
+13
View File
@@ -624,6 +624,19 @@ char* format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
return buf;
}
int parse_gmtoff(const char *t, long *ret) {
assert(t);
struct tm tm;
const char *k = strptime(t, "%z", &tm);
if (!k || *k != '\0')
return -EINVAL;
if (ret)
*ret = tm.tm_gmtoff;
return 0;
}
static int parse_timestamp_impl(
const char *t,
size_t max_len,
+1
View File
@@ -149,6 +149,7 @@ static inline char* format_timestamp(char *buf, size_t l, usec_t t) {
#define FORMAT_TIMESTAMP_STYLE(t, style) \
format_timestamp_style((char[FORMAT_TIMESTAMP_MAX]){}, FORMAT_TIMESTAMP_MAX, t, style)
int parse_gmtoff(const char *t, long *ret);
int parse_timestamp(const char *t, usec_t *ret);
int parse_sec(const char *t, usec_t *ret);