blob: aceb05830d3ef7bc972b735b3a11709a27477795 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/* 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;
}
|