diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-13 19:16:27 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-12-13 19:16:27 +0000 |
commit | 43eb1b72e5730064410a2d81e3f8d78ab62776cb (patch) | |
tree | c5132538d5da85ed816c7e1f9d93c4a503b838ab /libgo/go/time/example_test.go | |
parent | e27d80f7754f29f038c29ddcb2decd894d3e4aa4 (diff) | |
download | ppe42-gcc-43eb1b72e5730064410a2d81e3f8d78ab62776cb.tar.gz ppe42-gcc-43eb1b72e5730064410a2d81e3f8d78ab62776cb.zip |
libgo: Update to weekly.2011-12-02.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182295 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/time/example_test.go')
-rw-r--r-- | libgo/go/time/example_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libgo/go/time/example_test.go b/libgo/go/time/example_test.go new file mode 100644 index 00000000000..153b1a3b660 --- /dev/null +++ b/libgo/go/time/example_test.go @@ -0,0 +1,58 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package time_test + +import ( + "fmt" + "time" +) + +func expensiveCall() {} + +func ExampleDuration() { + t0 := time.Now() + expensiveCall() + t1 := time.Now() + fmt.Printf("The call took %v to run.\n", t1.Sub(t0)) +} + +var c chan int + +func handle(int) {} + +func ExampleAfter() { + select { + case m := <-c: + handle(m) + case <-time.After(5 * time.Minute): + fmt.Println("timed out") + } +} + +func ExampleSleep() { + time.Sleep(100 * time.Millisecond) +} + +func statusUpdate() string { return "" } + +func ExampleTick() { + c := time.Tick(1 * time.Minute) + for now := range c { + fmt.Printf("%v %s\n", now, statusUpdate()) + } +} + +func ExampleMonth() { + _, month, day := time.Now().Date() + if month == time.November && day == 10 { + fmt.Println("Happy Go day!") + } +} + +// Go launched at Tue Nov 10 15:00:00 -0800 PST 2009 +func ExampleDate() { + t := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC) + fmt.Printf("Go launched at %s\n", t.Local()) +} |