time-util: introduce parse_gmtoff() helper function
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user