Get rid of the %Z-flag in strptime-format
We don't actually need it for Zulu-time and handroll it. We can add the gmt-offset to hour without range-checking, because the implementation will take care of it in mktime().
This commit is contained in:
parent
0f4192e6b2
commit
d02327d0eb
10
touch.c
10
touch.c
|
@ -48,6 +48,7 @@ time_t
|
||||||
parsetime(char *str, time_t current)
|
parsetime(char *str, time_t current)
|
||||||
{
|
{
|
||||||
struct tm *cur, t;
|
struct tm *cur, t;
|
||||||
|
int zulu = 0;
|
||||||
char *format;
|
char *format;
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
|
|
||||||
|
@ -87,7 +88,9 @@ parsetime(char *str, time_t current)
|
||||||
/* only Zulu-timezone supported */
|
/* only Zulu-timezone supported */
|
||||||
if (str[19] != 'Z')
|
if (str[19] != 'Z')
|
||||||
eprintf("Invalid time zone\n");
|
eprintf("Invalid time zone\n");
|
||||||
format = "%Y-%m-%dT%H:%M:%S%Z";
|
str[19] = 0;
|
||||||
|
zulu = 1;
|
||||||
|
format = "%Y-%m-%dT%H:%M:%S";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
eprintf("Invalid date format length\n", str);
|
eprintf("Invalid date format length\n", str);
|
||||||
|
@ -95,6 +98,11 @@ parsetime(char *str, time_t current)
|
||||||
|
|
||||||
if (!strptime(str, format, &t))
|
if (!strptime(str, format, &t))
|
||||||
weprintf("strptime %s: Invalid date format\n", str);
|
weprintf("strptime %s: Invalid date format\n", str);
|
||||||
|
if (zulu) {
|
||||||
|
t.tm_hour += t.tm_gmtoff / 60;
|
||||||
|
t.tm_gmtoff = 0;
|
||||||
|
t.tm_zone = "Z";
|
||||||
|
}
|
||||||
|
|
||||||
return mktime(&t);
|
return mktime(&t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user