From 38143badf1d7244f1015286ba2d2d540a3a78d69 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Wed, 22 Aug 2018 10:58:24 +0200 Subject: [PATCH] time: allow +00 as numeric timezone name and GMT offset A timezone with a zero offset from UTC and without a three-letter abbreviation will have a numeric name in timestamps: "+00". There are currently two of them: $ zdump Atlantic/Azores America/Scoresbysund Atlantic/Azores Wed Aug 22 09:01:05 2018 +00 America/Scoresbysund Wed Aug 22 09:01:05 2018 +00 These two timestamp are rejected by Parse, since it doesn't allow for zero offsets: parsing time "Wed Aug 22 09:01:05 2018 +00": extra text: +00 This change modifies Parse to accept a +00 offset in numeric timezone names. As side effect of this change, Parse also now accepts "GMT+00". It was explicitely disallowed (with a unit test ensuring it got rejected), but the restriction seems incorrect. DATE(1), for example, allows it: $ date --debug --date="2009-01-02 03:04:05 GMT+00" date: parsed date part: (Y-M-D) 2009-01-02 date: parsed time part: 03:04:05 date: parsed zone part: UTC+00 date: input timezone: parsed date/time string (+00) date: using specified time as starting value: '03:04:05' date: starting date/time: '(Y-M-D) 2009-01-02 03:04:05 TZ=+00' date: '(Y-M-D) 2009-01-02 03:04:05 TZ=+00' = 1230865445 epoch-seconds date: timezone: system default date: final: 1230865445.000000000 (epoch-seconds) date: final: (Y-M-D) 2009-01-02 03:04:05 (UTC) date: final: (Y-M-D) 2009-01-02 04:04:05 (UTC+01) Fri 2 Jan 04:04:05 CET 2009 This fixes 2 of 17 time.Parse() failures listed in Issue #26032. Updates #26032 Change-Id: I01cd067044371322b7bb1dae452fb3c758ed3cc2 Reviewed-on: https://go-review.googlesource.com/130696 Run-TryBot: Alberto Donizetti TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/time/format.go | 6 ++++-- src/time/format_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/time/format.go b/src/time/format.go index f9cdbab3b8..2adbbe0770 100644 --- a/src/time/format.go +++ b/src/time/format.go @@ -1172,13 +1172,15 @@ func parseSignedOffset(value string) int { return 0 } x, rem, err := leadingInt(value[1:]) - if err != nil { + + // fail if nothing consumed by leadingInt + if err != nil || value[1:] == rem { return 0 } if sign == '-' { x = -x } - if x == 0 || x < -23 || 23 < x { + if x < -23 || 23 < x { return 0 } return len(value) - len(rem) diff --git a/src/time/format_test.go b/src/time/format_test.go index c3552f4161..db9d4f495a 100644 --- a/src/time/format_test.go +++ b/src/time/format_test.go @@ -416,7 +416,11 @@ var parseTimeZoneTests = []ParseTimeZoneTest{ {"gmt hi there", 0, false}, {"GMT hi there", 3, true}, {"GMT+12 hi there", 6, true}, - {"GMT+00 hi there", 3, true}, // 0 or 00 is not a legal offset. + {"GMT+00 hi there", 6, true}, + {"GMT+", 3, true}, + {"GMT+3", 5, true}, + {"GMT+a", 3, true}, + {"GMT+3a", 5, true}, {"GMT-5 hi there", 5, true}, {"GMT-51 hi there", 3, true}, {"ChST hi there", 4, true}, @@ -431,6 +435,7 @@ var parseTimeZoneTests = []ParseTimeZoneTest{ {"+03 hi", 3, true}, {"-04 hi", 3, true}, // Issue #26032 + {"+00", 3, true}, {"-11", 3, true}, {"-12", 3, true}, {"-23", 3, true}, -- 2.48.1