time: in strptime(), make %z accept Z as a time zone
Commit Message
From: Vincent Bernat <vincent@bernat.im>
In ISO 8601, the timezone can be 'Z' instead of using
digits. 2014-08-17T12:33:12+0000 is often expressed as
2014-08-17T12:33:12Z.
---
ChangeLog | 5 +++++
time/strptime_l.c | 9 +++++++--
time/tst-strptime2.c | 1 +
3 files changed, 13 insertions(+), 2 deletions(-)
Comments
On 27 Jan 2015 16:05, Vincent Bernat wrote:
> In ISO 8601, the timezone can be 'Z' instead of using
> digits. 2014-08-17T12:33:12+0000 is often expressed as
> 2014-08-17T12:33:12Z.
code wise, this looks good to me. style problems though ...
> --- a/time/strptime_l.c
> +++ b/time/strptime_l.c
>
> - also specified. */
> + also specified. 'Z' is equivalent to +0000. */
GNU style puts two spaces after the period
> {
> val = 0;
> while (ISSPACE (*rp))
> ++rp;
> + if (*rp == 'Z')
> + {
> + rp++;
> + break;
> + }
indentation is incorrect -- you need to start with a tab
minor nit: this code would do ++rp instead of rp++
-mike
@@ -1,3 +1,8 @@
+2015-01-27 Vincent Bernat <vincent@bernat.im>
+
+ [BZ #17886]
+ * time/strptime_l.c: Make %z accept Z as a valid time zone.
+
2015-01-27 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
* iconv/loop.c: Suppress array out of bound warning caused by GCC
@@ -749,13 +749,18 @@ __strptime_internal (rp, fmt, tmp, statep LOCALE_PARAM)
rp++;
break;
case 'z':
- /* 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;
+ if (*rp == 'Z')
+ {
+ rp++;
+ break;
+ }
if (*rp != '+' && *rp != '-')
return NULL;
bool neg = *rp++ == '-';
@@ -17,6 +17,7 @@ static const struct
{ "1113472456 -1030", -37800 },
{ "1113472456 +0030", 1800 },
{ "1113472456 -0030", -1800 },
+ { "1113472456 Z", 0 },
{ "1113472456 -1330", LONG_MAX },
{ "1113472456 +1330", LONG_MAX },
{ "1113472456 -1060", LONG_MAX },