Skip to content

Commit 91563ce

Browse files
ALTreebradfitz
authored andcommitted
time: make the ParseInLocation test more robust
The tzdata 2017a update (2017-02-28) changed the abbreviation of the Asia/Baghdad time zone (used in TestParseInLocation) from 'AST' to the numeric '+03'. Update the test so that it skips the checks if we're using a recent tzdata release. Fixes #19457 Change-Id: I45d705a5520743a611bdd194dc8f8d618679980c Reviewed-on: https://go-review.googlesource.com/37964 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 3b68922 commit 91563ce

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/time/format_test.go

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,34 +245,55 @@ func TestParseDayOutOfRange(t *testing.T) {
245245
}
246246
}
247247

248+
// TestParseInLocation checks that the Parse and ParseInLocation
249+
// functions do not get confused by the fact that AST (Arabia Standard
250+
// Time) and AST (Atlantic Standard Time) are different time zones,
251+
// even though they have the same abbreviation.
252+
//
253+
// ICANN has been slowly phasing out invented abbreviation in favor of
254+
// numeric time zones (for example, the Asia/Baghdad time zone
255+
// abbreviation got changed from AST to +03 in the 2017a tzdata
256+
// release); but we still want to make sure that the time package does
257+
// not get confused on systems with slightly older tzdata packages.
248258
func TestParseInLocation(t *testing.T) {
249-
// Check that Parse (and ParseInLocation) understand that
250-
// Feb 01 AST (Arabia Standard Time) and Feb 01 AST (Atlantic Standard Time)
251-
// are in different time zones even though both are called AST
252259

253260
baghdad, err := LoadLocation("Asia/Baghdad")
254261
if err != nil {
255262
t.Fatal(err)
256263
}
257264

258-
t1, err := ParseInLocation("Jan 02 2006 MST", "Feb 01 2013 AST", baghdad)
265+
var t1, t2 Time
266+
267+
t1, err = ParseInLocation("Jan 02 2006 MST", "Feb 01 2013 AST", baghdad)
259268
if err != nil {
260269
t.Fatal(err)
261270
}
262-
t2 := Date(2013, February, 1, 00, 00, 00, 0, baghdad)
263-
if t1 != t2 {
264-
t.Fatalf("ParseInLocation(Feb 01 2013 AST, Baghdad) = %v, want %v", t1, t2)
265-
}
271+
266272
_, offset := t1.Zone()
267-
if offset != 3*60*60 {
268-
t.Fatalf("ParseInLocation(Feb 01 2013 AST, Baghdad).Zone = _, %d, want _, %d", offset, 3*60*60)
273+
274+
// A zero offset means that ParseInLocation did not recognize the
275+
// 'AST' abbreviation as matching the current location (Baghdad,
276+
// where we'd expect a +03 hrs offset); likely because we're using
277+
// a recent tzdata release (2017a or newer).
278+
// If it happens, skip the Baghdad test.
279+
if offset != 0 {
280+
t2 = Date(2013, February, 1, 00, 00, 00, 0, baghdad)
281+
if t1 != t2 {
282+
t.Fatalf("ParseInLocation(Feb 01 2013 AST, Baghdad) = %v, want %v", t1, t2)
283+
}
284+
if offset != 3*60*60 {
285+
t.Fatalf("ParseInLocation(Feb 01 2013 AST, Baghdad).Zone = _, %d, want _, %d", offset, 3*60*60)
286+
}
269287
}
270288

271289
blancSablon, err := LoadLocation("America/Blanc-Sablon")
272290
if err != nil {
273291
t.Fatal(err)
274292
}
275293

294+
// In this case 'AST' means 'Atlantic Standard Time', and we
295+
// expect the abbreviation to correctly match the american
296+
// location.
276297
t1, err = ParseInLocation("Jan 02 2006 MST", "Feb 01 2013 AST", blancSablon)
277298
if err != nil {
278299
t.Fatal(err)

0 commit comments

Comments
 (0)