// Special Case 3: Some time zones are not named, but have +/-00 format
if value[0] == '+' || value[0] == '-' {
length = parseSignedOffset(value)
- return length, true
+ ok := length > 0 // parseSignedOffset returns 0 in case of bad input
+ return length, ok
}
// How many upper-case letters are there? Need at least three, at most five.
var nUpper int
// parseGMT parses a GMT time zone. The input string is known to start "GMT".
// The function checks whether that is followed by a sign and a number in the
-// range -14 through 12 excluding zero.
+// range -23 through +23 excluding zero.
func parseGMT(value string) int {
value = value[3:]
if len(value) == 0 {
}
// parseSignedOffset parses a signed timezone offset (e.g. "+03" or "-04").
-// The function checks for a signed number in the range -14 through +12 excluding zero.
+// The function checks for a signed number in the range -23 through +23 excluding zero.
// Returns length of the found offset string or 0 otherwise
func parseSignedOffset(value string) int {
sign := value[0]
if sign == '-' {
x = -x
}
- if x == 0 || x < -14 || 12 < x {
+ if x == 0 || x < -23 || 23 < x {
return 0
}
return len(value) - len(rem)
{"ESASTT hi", 0, false}, // run of upper-case letters too long.
{"ESATY hi", 0, false}, // five letters must end in T.
{"WITA hi", 4, true}, // Issue #18251
- {"+03 hi", 3, true}, // Issue #24071
- {"-04 hi", 3, true}, // Issue #24071
+ // Issue #24071
+ {"+03 hi", 3, true},
+ {"-04 hi", 3, true},
+ // Issue #26032
+ {"-11", 3, true},
+ {"-12", 3, true},
+ {"-23", 3, true},
+ {"-24", 0, false},
+ {"+13", 3, true},
+ {"+14", 3, true},
+ {"+23", 3, true},
+ {"+24", 0, false},
}
func TestParseTimeZone(t *testing.T) {