From patchwork Thu Sep 17 07:55:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vincent Bernat X-Patchwork-Id: 8738 X-Patchwork-Delegate: vapier@gentoo.org Received: (qmail 22382 invoked by alias); 17 Sep 2015 07:55:12 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 22366 invoked by uid 89); 17 Sep 2015 07:55:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_MX4, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: smtp-sh.infomaniak.ch From: Vincent Bernat To: libc-alpha@sourceware.org Cc: James Perkins Subject: Re: [PATCH 1/2] time: in strptime(), make %z accept Z as a time zone [BZ #17886] References: <20150911174300.GB2802@gmail.com> <1442393243-30956-1-git-send-email-Vincent.Bernat@exoscale.ch> <20150916171647.GG20252@vapier.lan> Date: Thu, 17 Sep 2015 09:55:04 +0200 In-Reply-To: <20150916171647.GG20252@vapier.lan> (Mike Frysinger's message of "Wed, 16 Sep 2015 13:16:47 -0400") Message-ID: <87mvwl5vl3.fsf@zoro.exoscale.ch> User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-Antivirus-Code: 0x100000 ❦ 16 septembre 2015 13:16 -0400, Mike Frysinger  : >> --- 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. OK, updated. From f860e2622d8079b205c51c4cb9483d10c0da8fc5 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 27 Jan 2015 15:58:07 +0100 Subject: [PATCH 1/2] time: in strptime(), make %z accept Z as a time zone [BZ #17886] 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 [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 | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) 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..3d906dec74e7 100644 --- a/time/tst-strptime2.c +++ b/time/tst-strptime2.c @@ -31,7 +31,8 @@ static bool verbose; whitespace matching strptime " " format specifier, and timezone string matching strptime "%z" format specifier. - Note that a valid timezone string contains the following fields: + Note that a valid timezone string is either "Z" or contains the + following fields: Sign field consisting of a '+' or '-' sign, Hours field in two decimal digits, and optional Minutes field in two decimal digits. @@ -155,6 +156,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), -- 2.5.1