diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-01-02 15:05:27 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-01-21 23:53:22 -0800 |
commit | 5a8ea165926cb0737ab03bc48c18dc5198ab5305 (patch) | |
tree | 962dc3357c57f019f85658f99e2e753e30201c27 /libgo/go/time | |
parent | 6ac6529e155c9baa0aaaed7aca06bd38ebda5b43 (diff) | |
download | gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.zip gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.gz gcc-5a8ea165926cb0737ab03bc48c18dc5198ab5305.tar.bz2 |
libgo: update to Go1.14beta1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/214297
Diffstat (limited to 'libgo/go/time')
-rw-r--r-- | libgo/go/time/example_test.go | 19 | ||||
-rw-r--r-- | libgo/go/time/format_test.go | 2 | ||||
-rw-r--r-- | libgo/go/time/genzabbrs.go | 2 | ||||
-rw-r--r-- | libgo/go/time/internal_test.go | 3 | ||||
-rw-r--r-- | libgo/go/time/sleep.go | 22 | ||||
-rw-r--r-- | libgo/go/time/sleep_test.go | 71 | ||||
-rw-r--r-- | libgo/go/time/sys_unix.go | 2 | ||||
-rw-r--r-- | libgo/go/time/tick_test.go | 76 | ||||
-rw-r--r-- | libgo/go/time/time.go | 2 | ||||
-rw-r--r-- | libgo/go/time/zoneinfo.go | 10 | ||||
-rw-r--r-- | libgo/go/time/zoneinfo_abbrs_windows.go | 9 | ||||
-rw-r--r-- | libgo/go/time/zoneinfo_unix.go | 2 |
12 files changed, 155 insertions, 65 deletions
diff --git a/libgo/go/time/example_test.go b/libgo/go/time/example_test.go index 25c34eb..5a037da 100644 --- a/libgo/go/time/example_test.go +++ b/libgo/go/time/example_test.go @@ -113,6 +113,20 @@ func ExampleDuration_Hours() { // Output: I've got 4.5 hours of work left. } +func ExampleDuration_Microseconds() { + u, _ := time.ParseDuration("1s") + fmt.Printf("One second is %d microseconds.\n", u.Microseconds()) + // Output: + // One second is 1000000 microseconds. +} + +func ExampleDuration_Milliseconds() { + u, _ := time.ParseDuration("1s") + fmt.Printf("One second is %d milliseconds.\n", u.Milliseconds()) + // Output: + // One second is 1000 milliseconds. +} + func ExampleDuration_Minutes() { m, _ := time.ParseDuration("1h30m") fmt.Printf("The movie is %.0f minutes long.", m.Minutes()) @@ -153,8 +167,8 @@ func statusUpdate() string { return "" } func ExampleTick() { c := time.Tick(5 * time.Second) - for now := range c { - fmt.Printf("%v %s\n", now, statusUpdate()) + for next := range c { + fmt.Printf("%v %s\n", next, statusUpdate()) } } @@ -349,6 +363,7 @@ func ExampleParse() { func ExampleParseInLocation() { loc, _ := time.LoadLocation("Europe/Berlin") + // This will look for the name CEST in the Europe/Berlin time zone. const longForm = "Jan 2, 2006 at 3:04pm (MST)" t, _ := time.ParseInLocation(longForm, "Jul 9, 2012 at 5:02am (CEST)", loc) fmt.Println(t) diff --git a/libgo/go/time/format_test.go b/libgo/go/time/format_test.go index ac21570..3dbb774 100644 --- a/libgo/go/time/format_test.go +++ b/libgo/go/time/format_test.go @@ -119,7 +119,7 @@ var formatTests = []FormatTest{ } func TestFormat(t *testing.T) { - // The numeric time represents Thu Feb 4 21:00:57.012345600 PST 2010 + // The numeric time represents Thu Feb 4 21:00:57.012345600 PST 2009 time := Unix(0, 1233810057012345600) for _, test := range formatTests { result := time.Format(test.format) diff --git a/libgo/go/time/genzabbrs.go b/libgo/go/time/genzabbrs.go index e062cc2..38397f9 100644 --- a/libgo/go/time/genzabbrs.go +++ b/libgo/go/time/genzabbrs.go @@ -52,7 +52,7 @@ type zone struct { DSTime string } -const wzURL = "http://unicode.org/cldr/data/common/supplemental/windowsZones.xml" +const wzURL = "https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml" type MapZone struct { Other string `xml:"other,attr"` diff --git a/libgo/go/time/internal_test.go b/libgo/go/time/internal_test.go index ba5e00e..1e14f6c 100644 --- a/libgo/go/time/internal_test.go +++ b/libgo/go/time/internal_test.go @@ -69,8 +69,7 @@ func CheckRuntimeTimerOverflow() { // once more. stopTimer(r) t.Stop() - r.when = 0 - startTimer(r) + resetTimer(r, 0) }() // If the test fails, we will hang here until the timeout in the testing package diff --git a/libgo/go/time/sleep.go b/libgo/go/time/sleep.go index 2cc908d..37de846 100644 --- a/libgo/go/time/sleep.go +++ b/libgo/go/time/sleep.go @@ -11,14 +11,14 @@ func Sleep(d Duration) // Interface to timers implemented in package runtime. // Must be in sync with ../runtime/time.go:/^type timer type runtimeTimer struct { - tb uintptr - i int - - when int64 - period int64 - f func(interface{}, uintptr) // NOTE: must not be closure - arg interface{} - seq uintptr + pp uintptr + when int64 + period int64 + f func(interface{}, uintptr) // NOTE: must not be closure + arg interface{} + seq uintptr + nextwhen int64 + status uint32 } // when is a helper function for setting the 'when' field of a runtimeTimer. @@ -38,6 +38,7 @@ func when(d Duration) int64 { func startTimer(*runtimeTimer) func stopTimer(*runtimeTimer) bool +func resetTimer(*runtimeTimer, int64) // The Timer type represents a single event. // When the Timer expires, the current time will be sent on C, @@ -63,7 +64,7 @@ type Timer struct { // } // // This cannot be done concurrent to other receives from the Timer's -// channel. +// channel or other calls to the Timer's Stop method. // // For a timer created with AfterFunc(d, f), if t.Stop returns false, then the timer // has already expired and the function f has been started in its own goroutine; @@ -122,8 +123,7 @@ func (t *Timer) Reset(d Duration) bool { } w := when(d) active := stopTimer(&t.r) - t.r.when = w - startTimer(&t.r) + resetTimer(&t.r, w) return active } diff --git a/libgo/go/time/sleep_test.go b/libgo/go/time/sleep_test.go index 42df6d1..26cc488 100644 --- a/libgo/go/time/sleep_test.go +++ b/libgo/go/time/sleep_test.go @@ -235,28 +235,59 @@ func TestAfterTick(t *testing.T) { } func TestAfterStop(t *testing.T) { - AfterFunc(100*Millisecond, func() {}) - t0 := NewTimer(50 * Millisecond) - c1 := make(chan bool, 1) - t1 := AfterFunc(150*Millisecond, func() { c1 <- true }) - c2 := After(200 * Millisecond) - if !t0.Stop() { - t.Fatalf("failed to stop event 0") - } - if !t1.Stop() { - t.Fatalf("failed to stop event 1") - } - <-c2 - select { - case <-t0.C: - t.Fatalf("event 0 was not stopped") - case <-c1: - t.Fatalf("event 1 was not stopped") - default: + // We want to test that we stop a timer before it runs. + // We also want to test that it didn't run after a longer timer. + // Since we don't want the test to run for too long, we don't + // want to use lengthy times. That makes the test inherently flaky. + // So only report an error if it fails five times in a row. + + var errs []string + logErrs := func() { + for _, e := range errs { + t.Log(e) + } } - if t1.Stop() { - t.Fatalf("Stop returned true twice") + + for i := 0; i < 5; i++ { + AfterFunc(100*Millisecond, func() {}) + t0 := NewTimer(50 * Millisecond) + c1 := make(chan bool, 1) + t1 := AfterFunc(150*Millisecond, func() { c1 <- true }) + c2 := After(200 * Millisecond) + if !t0.Stop() { + errs = append(errs, "failed to stop event 0") + continue + } + if !t1.Stop() { + errs = append(errs, "failed to stop event 1") + continue + } + <-c2 + select { + case <-t0.C: + errs = append(errs, "event 0 was not stopped") + continue + case <-c1: + errs = append(errs, "event 1 was not stopped") + continue + default: + } + if t1.Stop() { + errs = append(errs, "Stop returned true twice") + continue + } + + // Test passed, so all done. + if len(errs) > 0 { + t.Logf("saw %d errors, ignoring to avoid flakiness", len(errs)) + logErrs() + } + + return } + + t.Errorf("saw %d errors", len(errs)) + logErrs() } func TestAfterQueuing(t *testing.T) { diff --git a/libgo/go/time/sys_unix.go b/libgo/go/time/sys_unix.go index 3af2288..ec98d6e 100644 --- a/libgo/go/time/sys_unix.go +++ b/libgo/go/time/sys_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build aix darwin dragonfly freebsd hurd js,wasm linux nacl netbsd openbsd solaris +// +build aix darwin dragonfly freebsd hurd js,wasm linux netbsd openbsd solaris package time diff --git a/libgo/go/time/tick_test.go b/libgo/go/time/tick_test.go index dd17aab..71ea367 100644 --- a/libgo/go/time/tick_test.go +++ b/libgo/go/time/tick_test.go @@ -5,34 +5,70 @@ package time_test import ( + "fmt" + "runtime" "testing" . "time" ) func TestTicker(t *testing.T) { - const Count = 10 - Delta := 100 * Millisecond - ticker := NewTicker(Delta) - t0 := Now() - for i := 0; i < Count; i++ { - <-ticker.C + // We want to test that a ticker takes as much time as expected. + // Since we don't want the test to run for too long, we don't + // want to use lengthy times. This makes the test inherently flaky. + // So only report an error if it fails five times in a row. + + count := 10 + delta := 20 * Millisecond + + // On Darwin ARM64 the tick frequency seems limited. Issue 35692. + if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" { + count = 5 + delta = 100 * Millisecond } - ticker.Stop() - t1 := Now() - dt := t1.Sub(t0) - target := Delta * Count - slop := target * 2 / 10 - if dt < target-slop || (!testing.Short() && dt > target+slop) { - t.Fatalf("%d %s ticks took %s, expected [%s,%s]", Count, Delta, dt, target-slop, target+slop) + + var errs []string + logErrs := func() { + for _, e := range errs { + t.Log(e) + } } - // Now test that the ticker stopped - Sleep(2 * Delta) - select { - case <-ticker.C: - t.Fatal("Ticker did not shut down") - default: - // ok + + for i := 0; i < 5; i++ { + ticker := NewTicker(delta) + t0 := Now() + for i := 0; i < count; i++ { + <-ticker.C + } + ticker.Stop() + t1 := Now() + dt := t1.Sub(t0) + target := delta * Duration(count) + slop := target * 2 / 10 + if dt < target-slop || dt > target+slop { + errs = append(errs, fmt.Sprintf("%d %s ticks took %s, expected [%s,%s]", count, delta, dt, target-slop, target+slop)) + continue + } + // Now test that the ticker stopped. + Sleep(2 * delta) + select { + case <-ticker.C: + errs = append(errs, "Ticker did not shut down") + continue + default: + // ok + } + + // Test passed, so all done. + if len(errs) > 0 { + t.Logf("saw %d errors, ignoring to avoid flakiness", len(errs)) + logErrs() + } + + return } + + t.Errorf("saw %d errors", len(errs)) + logErrs() } // Issue 21874 diff --git a/libgo/go/time/time.go b/libgo/go/time/time.go index 0d1cb9e..10a132f 100644 --- a/libgo/go/time/time.go +++ b/libgo/go/time/time.go @@ -257,7 +257,7 @@ func (t Time) Before(u Time) bool { // Equal reports whether t and u represent the same time instant. // Two times can be equal even if they are in different locations. -// For example, 6:00 +0200 CEST and 4:00 UTC are Equal. +// For example, 6:00 +0200 and 4:00 UTC are Equal. // See the documentation on the Time type for the pitfalls of using == with // Time values; most code should use Equal instead. func (t Time) Equal(u Time) bool { diff --git a/libgo/go/time/zoneinfo.go b/libgo/go/time/zoneinfo.go index 7dffbfa..558803f 100644 --- a/libgo/go/time/zoneinfo.go +++ b/libgo/go/time/zoneinfo.go @@ -14,7 +14,8 @@ import ( // A Location maps time instants to the zone in use at that time. // Typically, the Location represents the collection of time offsets -// in use in a geographical area, such as CEST and CET for central Europe. +// in use in a geographical area. For many Locations the time offset varies +// depending on whether daylight savings time is in use at the time instant. type Location struct { name string zone []zone @@ -34,7 +35,7 @@ type Location struct { cacheZone *zone } -// A zone represents a single time zone such as CEST or CET. +// A zone represents a single time zone such as CET. type zone struct { name string // abbreviated name, "CET" offset int // seconds east of UTC @@ -64,6 +65,11 @@ var UTC *Location = &utcLoc var utcLoc = Location{name: "UTC"} // Local represents the system's local time zone. +// On Unix systems, Local consults the TZ environment +// variable to find the time zone to use. No TZ means +// use the system default /etc/localtime. +// TZ="" means use UTC. +// TZ="foo" means use file foo in the system timezone directory. var Local *Location = &localLoc // localLoc is separate so that initLocal can initialize diff --git a/libgo/go/time/zoneinfo_abbrs_windows.go b/libgo/go/time/zoneinfo_abbrs_windows.go index 5411325..3294d0d 100644 --- a/libgo/go/time/zoneinfo_abbrs_windows.go +++ b/libgo/go/time/zoneinfo_abbrs_windows.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // Code generated by genzabbrs.go; DO NOT EDIT. -// Based on information from http://unicode.org/cldr/data/common/supplemental/windowsZones.xml +// Based on information from https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml package time @@ -14,11 +14,12 @@ type abbr struct { var abbrs = map[string]abbr{ "Egypt Standard Time": {"EET", "EET"}, // Africa/Cairo - "Morocco Standard Time": {"WET", "WEST"}, // Africa/Casablanca + "Morocco Standard Time": {"+00", "+01"}, // Africa/Casablanca "South Africa Standard Time": {"SAST", "SAST"}, // Africa/Johannesburg "Sudan Standard Time": {"CAT", "CAT"}, // Africa/Khartoum "W. Central Africa Standard Time": {"WAT", "WAT"}, // Africa/Lagos "E. Africa Standard Time": {"EAT", "EAT"}, // Africa/Nairobi + "Sao Tome Standard Time": {"GMT", "WAT"}, // Africa/Sao_Tome "Libya Standard Time": {"EET", "EET"}, // Africa/Tripoli "Namibia Standard Time": {"CAT", "CAT"}, // Africa/Windhoek "Aleutian Standard Time": {"HST", "HDT"}, // America/Adak @@ -36,7 +37,7 @@ var abbrs = map[string]abbr{ "Central Brazilian Standard Time": {"-04", "-03"}, // America/Cuiaba "Mountain Standard Time": {"MST", "MDT"}, // America/Denver "Greenland Standard Time": {"-03", "-02"}, // America/Godthab - "Turks And Caicos Standard Time": {"AST", "EDT"}, // America/Grand_Turk + "Turks And Caicos Standard Time": {"EST", "EDT"}, // America/Grand_Turk "Central America Standard Time": {"CST", "CST"}, // America/Guatemala "Atlantic Standard Time": {"AST", "ADT"}, // America/Halifax "Cuba Standard Time": {"CST", "CDT"}, // America/Havana @@ -81,6 +82,7 @@ var abbrs = map[string]abbr{ "N. Central Asia Standard Time": {"+07", "+07"}, // Asia/Novosibirsk "Omsk Standard Time": {"+06", "+06"}, // Asia/Omsk "North Korea Standard Time": {"KST", "KST"}, // Asia/Pyongyang + "Qyzylorda Standard Time": {"+05", "+06"}, // Asia/Qyzylorda "Myanmar Standard Time": {"+0630", "+0630"}, // Asia/Rangoon "Arab Standard Time": {"+03", "+03"}, // Asia/Riyadh "Sakhalin Standard Time": {"+11", "+11"}, // Asia/Sakhalin @@ -132,6 +134,7 @@ var abbrs = map[string]abbr{ "Romance Standard Time": {"CET", "CEST"}, // Europe/Paris "Russia Time Zone 3": {"+04", "+04"}, // Europe/Samara "Saratov Standard Time": {"+04", "+04"}, // Europe/Saratov + "Volgograd Standard Time": {"+04", "+04"}, // Europe/Volgograd "Central European Standard Time": {"CET", "CEST"}, // Europe/Warsaw "Mauritius Standard Time": {"+04", "+04"}, // Indian/Mauritius "Samoa Standard Time": {"+13", "+14"}, // Pacific/Apia diff --git a/libgo/go/time/zoneinfo_unix.go b/libgo/go/time/zoneinfo_unix.go index 495a7e6..dc425a5 100644 --- a/libgo/go/time/zoneinfo_unix.go +++ b/libgo/go/time/zoneinfo_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build aix darwin,386 darwin,amd64 dragonfly freebsd hurd js,wasm linux,!android nacl netbsd openbsd solaris +// +build aix darwin,386 darwin,amd64 dragonfly freebsd hurd linux,!android netbsd openbsd solaris // Parse "zoneinfo" time zone file. // This is a fairly standard file format used on OS X, Linux, BSD, Sun, and others. |