Closed bradfitz closed 9 years ago
How about failing with a more helpful error message at least? Much of the time package will still work without zoneinfo files. It just silently defaults to UTC in the case of no zoneinfo files. In zoneinfo_unix.go's setupZone(): case len(tz) > 0: var ok bool zones, ok = readinfofile(zoneDir + tz) if !ok { zones, _ = readinfofile(zoneDir2 + tz) } case len(tz) == 0: // do nothing: use UTC If that's going to be the behavior (silent fallback instead of, say, a panic) then we could have an exported func/var in package time for whether or not zoneinfo is loaded. Then the tests could either skip those tests or fail loudly with a useful error message.
We should at least explain what the actual problem is. For example, diff --git a/src/pkg/time/time_test.go b/src/pkg/time/time_test.go --- a/src/pkg/time/time_test.go +++ b/src/pkg/time/time_test.go @@ -19,6 +19,12 @@ os.Setenv("TZ", "America/Los_Angeles") } +func TestZoneData(t *testing.T) { + if tz := LocalTime().Zone; tz != "PST" && tz != "PDT" { + t.Errorf("Unable to find US Pacific time zone data for testing") + } +} + type TimeTest struct { seconds int64 golden Time Which outputs: --- FAIL: time_test.TestZoneData (0.0 seconds) Unable to find US Pacific time zone data for testing --- FAIL: time_test.TestSecondsToLocalTime (0.0 seconds) SecondsToLocalTime(0): want={Year:1969 Month:12 Day:31 Hour:16 Minute:0 Second:0 Weekday:3 ZoneOffset:-28800 Zone:PST} have={Year:1970 Month:1 Day:1 Hour:0 Minute:0 Second:0 Weekday:4 ZoneOffset:0 Zone:UTC} SecondsToLocalTime(1221681866): want={Year:2008 Month:9 Day:17 Hour:13 Minute:4 Second:26 Weekday:3 ZoneOffset:-25200 Zone:PDT} have={Year:2008 Month:9 Day:17 Hour:20 Minute:4 Second:26 Weekday:3 ZoneOffset:0 Zone:UTC} --- FAIL: time_test.TestFormat (0.0 seconds) ANSIC expected "Thu Feb 4 21:00:57 2010" got "Fri Feb 5 05:00:57 2010" UnixDate expected "Thu Feb 4 21:00:57 PST 2010" got "Fri Feb 5 05:00:57 UTC 2010" RubyDate expected "Thu Feb 04 21:00:57 -0800 2010" got "Fri Feb 05 05:00:57 +0000 2010" RFC822 expected "04 Feb 10 2100 PST" got "05 Feb 10 0500 UTC" RFC850 expected "Thursday, 04-Feb-10 21:00:57 PST" got "Friday, 05-Feb-10 05:00:57 UTC" RFC1123 expected "Thu, 04 Feb 2010 21:00:57 PST" got "Fri, 05 Feb 2010 05:00:57 UTC" RFC3339 expected "2010-02-04T21:00:57-08:00" got "2010-02-05T05:00:57Z" Kitchen expected "9:00PM" got "5:00AM" am/pm expected "9pm" got "5am" AM/PM expected "9PM" got "5AM" --- FAIL: time_test.TestParse (0.0 seconds) UnixDate: bad tz offset: 0 not -28800 RFC850: bad tz offset: 0 not -28800 RFC1123: bad tz offset: 0 not -28800 FAIL