/* See LICENSE file for copyright and license details. */ #include "common.h" const char * libpatch_parse_timestamp(const char *text, struct tm *time_out, const char **frac_out, int *has_zone_out, enum libpatch_style style) { const char *fmt, *r; struct tm zone; if (style == LIBPATCH_STYLE_COPIED) { fmt = "%a %b %e %T %Y"; } else if (style == LIBPATCH_STYLE_UNIFIED) { fmt = "%Y-%m-%d %H:%M:%S"; } else { errno = EINVAL; return NULL; } text = strptime(text, fmt, time_out); if (!text) return NULL; if (text[0] == '.') { *frac_out = ++text; while (isdigit(*text)) text++; } else { *frac_out = NULL; } time_out->tm_isdst = -1; time_out->tm_zone = NULL; r = strptime(text, " %z", &zone); if (r) { text = r; *has_zone_out = 1; time_out->tm_gmtoff = zone.tm_gmtoff; } else { *has_zone_out = 0; time_out->tm_gmtoff = 0; } return text; }