[hackers] [sbase] Get rid of the %Z-flag in strptime-format || FRIGN

From: <git_AT_suckless.org>
Date: Thu, 19 Feb 2015 19:32:36 +0100 (CET)

commit 10216d4b925a2793b0dce4339c1bc07fbc8bfc01
Author: FRIGN <dev_AT_frign.de>
Date: Thu Feb 19 19:27:17 2015 +0100

    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().

diff --git a/touch.c b/touch.c
index 8c488f1..dc76cfb 100644
--- a/touch.c
+++ b/touch.c
_AT_@ -48,6 +48,7 @@ time_t
 parsetime(char *str, time_t current)
 {
         struct tm *cur, t;
+ int zulu = 0;
         char *format;
         size_t len = strlen(str);
 
_AT_@ -87,7 +88,9 @@ parsetime(char *str, time_t current)
                 /* only Zulu-timezone supported */
                 if (str[19] != 'Z')
                         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;
         default:
                 eprintf("Invalid date format length\n", str);
_AT_@ -95,6 +98,11 @@ parsetime(char *str, time_t current)
 
         if (!strptime(str, format, &t))
                 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);
 }
Received on Thu Feb 19 2015 - 19:32:36 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 19 2015 - 19:36:09 CET