[PATCH 1/2] time: in strptime(), make %z accept Z as a time zone [BZ #17886]
Vincent Bernat
Vincent.Bernat@exoscale.ch
Wed Sep 16 07:58:00 GMT 2015
❦ 11 septembre 2015 10:21 -0700, James Perkins <james@loowit.net> :
>> - /* We recognize two formats: if two digits are given, these
>> + /* We recognize three formats: if two digits are given, these
>> specify hours. If fours digits are used, minutes are
>> - also specified. */
>> + also specified. 'Z' is equivalent to +0000. */
>> {
>> val = 0;
>> while (ISSPACE (*rp))
>> ++rp;
>
> OK.
>
> However, note that val is not used until the loop that accumulates a
> sum in val. As an optimization/localization it could be moved down past
> the tests for Z, + and -. e.g.
>
> + val = 0;
> while (n < 4 && *rp >= '0' && *rp <= '9')
> .... accumulate digits in val ...
It is unrelated to the patch and this is also how this is done in
get_number() macro. I prefer to leave this as is if you don't mind.
>> + if (*rp == 'Z')
>> + {
>> + ++rp;
>> + break;
>> + }
>> if (*rp != '+' && *rp != '-')
>> return NULL;
>> bool neg = *rp++ == '-';
>
>
> I've thought about this early break a bit more and I think it's
> incomplete. strptime will not set tm fields if they are not valid
> input. However, it *does* set the tm fields if it parses them
> correctly. So for completeness, you probably want to do this:
>
> + if (*rp == 'Z')
> + {
> + ++rp;
> + tm->tm_gmtoff = 0;
> + break;
> + }
Agreed.
Updated patchset will come shortly.
--
Vincent Bernat — Vincent.Bernat@exoscale.ch
❬❱ http://www.exoscale.ch
More information about the Libc-alpha
mailing list