diff mbox

[1/2] time: in strptime(), make %z accept Z as a time zone [BZ #17886]

Message ID 1442393243-30956-1-git-send-email-Vincent.Bernat@exoscale.ch
State Superseded
Delegated to: Mike Frysinger
Headers show

Commit Message

Vincent Bernat Sept. 16, 2015, 8:47 a.m. UTC
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.

This fixes BZ #17886.

2015-09-16  Vincent Bernat  <vincent@bernat.im>

	[BZ #17886]
	* time/strptime_l.c (__strptime_internal): Make %z accept Z as a
	valid time zone.
---
 time/strptime_l.c    | 10 ++++++++--
 time/tst-strptime2.c |  7 +++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

Comments

Mike Frysinger Sept. 16, 2015, 5:16 p.m. UTC | #1
On 16 Sep 2015 10:47, Vincent Bernat wrote:
> --- a/time/tst-strptime2.c
> +++ b/time/tst-strptime2.c

the mkbuf function has a comment block that needs updating since it
discusses valid inputs for timezone offsets.
-mike
diff mbox

Patch

diff --git a/time/strptime_l.c b/time/strptime_l.c
index 4203ad81a0f3..989edd6144e6 100644
--- a/time/strptime_l.c
+++ b/time/strptime_l.c
@@ -749,13 +749,19 @@  __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;
+		tm->tm_gmtoff = 0;
+		break;
+	      }
 	    if (*rp != '+' && *rp != '-')
 	      return NULL;
 	    bool neg = *rp++ == '-';
diff --git a/time/tst-strptime2.c b/time/tst-strptime2.c
index 5b06a63ba4c3..cfb7d70c4cc2 100644
--- a/time/tst-strptime2.c
+++ b/time/tst-strptime2.c
@@ -155,6 +155,13 @@  do_test (void)
   expect = LONG_MAX;
   result |= compare (buf, expect, nresult);
 
+  /* Create and test input string with "Z" input (valid format).
+     Expect tm_gmtoff of 0.  */
+
+  sprintf (buf, "%s Z", dummy_string);
+  expect = 0;
+  result |= compare (buf, expect, nresult);
+
   /* Create and test input strings with sign and digits:
      0 digits (invalid format),
      1 digit (invalid format),