Skip to content

Commit 089d7b3

Browse files
ALTreemetux
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 golang#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 46fb427 commit 089d7b3

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
@@ -244,34 +244,55 @@ func TestParseDayOutOfRange(t *testing.T) {
244244
}
245245
}
246246

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

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

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

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

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

0 commit comments

Comments
 (0)