From 935f3e6715f2f178159eef1501ae30ad53a68150 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 27 Apr 2005 04:33:01 +0000 Subject: * time/strptime_l.c (__strptime_internal): Handle 'z' to set tm_gmtoff. * time/Makefile (tests): Add tst-strptime2. * time/tst-strptime2.c: New file. --- time/strptime_l.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'time/strptime_l.c') diff --git a/time/strptime_l.c b/time/strptime_l.c index 01c4f8282a..dc0cc686fd 100644 --- a/time/strptime_l.c +++ b/time/strptime_l.c @@ -687,6 +687,42 @@ __strptime_internal (rp, fmt, tm, decided, era_cnt LOCALE_PARAM) case 'Z': /* XXX How to handle this? */ break; + case 'z': + /* We recognize two formats: if two digits are given, these + specify hours. If fours digits are used, minutes are + also specified. */ + { + val = 0; + while (*rp == ' ') + ++rp; + if (*rp != '+' && *rp != '-') + return NULL; + bool neg = *rp++ == '-'; + int n = 0; + while (n < 4 && *rp >= '0' && *rp <= '9') + { + val = val * 10 + *rp++ - '0'; + ++n; + } + if (n == 2) + val *= 100; + else if (n != 4) + /* Only two or four digits recognized. */ + return NULL; + else + { + /* We have to convert the minutes into decimal. */ + if (val % 100 >= 60) + return NULL; + val = (val / 100) * 100 + ((val % 100) * 50) / 30; + } + if (val > 1200) + return NULL; + tm->tm_gmtoff = (val * 3600) / 100; + if (neg) + tm->tm_gmtoff = -tm->tm_gmtoff; + } + break; case 'E': #ifdef _NL_CURRENT switch (*fmt++) -- cgit v1.2.3