time: new Time, Duration, ZoneInfo types

R=r, bradfitz, gri, dsymonds, iant
CC=golang-dev
https://golang.org/cl/5392041
diff --git a/src/pkg/time/sleep_test.go b/src/pkg/time/sleep_test.go
index 6fa2b69..91771fe 100644
--- a/src/pkg/time/sleep_test.go
+++ b/src/pkg/time/sleep_test.go
@@ -15,16 +15,16 @@
 )
 
 func TestSleep(t *testing.T) {
-	const delay = int64(100e6)
+	const delay = 100 * Millisecond
 	go func() {
 		Sleep(delay / 2)
 		Interrupt()
 	}()
-	start := Nanoseconds()
+	start := Now()
 	Sleep(delay)
-	duration := Nanoseconds() - start
+	duration := Now().Sub(start)
 	if duration < delay {
-		t.Fatalf("Sleep(%d) slept for only %d ns", delay, duration)
+		t.Fatalf("Sleep(%s) slept for only %s", delay, duration)
 	}
 }
 
@@ -96,32 +96,32 @@
 }
 
 func TestAfter(t *testing.T) {
-	const delay = int64(100e6)
-	start := Nanoseconds()
+	const delay = 100 * Millisecond
+	start := Now()
 	end := <-After(delay)
-	if duration := Nanoseconds() - start; duration < delay {
-		t.Fatalf("After(%d) slept for only %d ns", delay, duration)
+	if duration := Now().Sub(start); duration < delay {
+		t.Fatalf("After(%s) slept for only %d ns", delay, duration)
 	}
-	if min := start + delay; end < min {
-		t.Fatalf("After(%d) expect >= %d, got %d", delay, min, end)
+	if min := start.Add(delay); end.Before(min) {
+		t.Fatalf("After(%s) expect >= %s, got %s", delay, min, end)
 	}
 }
 
 func TestAfterTick(t *testing.T) {
 	const (
-		Delta = 100 * 1e6
+		Delta = 100 * Millisecond
 		Count = 10
 	)
-	t0 := Nanoseconds()
+	t0 := Now()
 	for i := 0; i < Count; i++ {
 		<-After(Delta)
 	}
-	t1 := Nanoseconds()
-	ns := t1 - t0
-	target := int64(Delta * Count)
+	t1 := Now()
+	d := t1.Sub(t0)
+	target := Delta * Count
 	slop := target * 2 / 10
-	if ns < target-slop || ns > target+slop {
-		t.Fatalf("%d ticks of %g ns took %g ns, expected %g", Count, float64(Delta), float64(ns), float64(target))
+	if d < target-slop || d > target+slop {
+		t.Fatalf("%d ticks of %s took %s, expected %s", Count, Delta, d, target)
 	}
 }
 
@@ -170,37 +170,37 @@
 
 type afterResult struct {
 	slot int
-	t    int64
+	t    Time
 }
 
-func await(slot int, result chan<- afterResult, ac <-chan int64) {
+func await(slot int, result chan<- afterResult, ac <-chan Time) {
 	result <- afterResult{slot, <-ac}
 }
 
 func testAfterQueuing(t *testing.T) error {
 	const (
-		Delta = 100 * 1e6
+		Delta = 100 * Millisecond
 	)
 	// make the result channel buffered because we don't want
 	// to depend on channel queueing semantics that might
 	// possibly change in the future.
 	result := make(chan afterResult, len(slots))
 
-	t0 := Nanoseconds()
+	t0 := Now()
 	for _, slot := range slots {
-		go await(slot, result, After(int64(slot)*Delta))
+		go await(slot, result, After(Duration(slot)*Delta))
 	}
 	sort.Ints(slots)
 	for _, slot := range slots {
 		r := <-result
 		if r.slot != slot {
-			return fmt.Errorf("after queue got slot %d, expected %d", r.slot, slot)
+			return fmt.Errorf("after slot %d, expected %d", r.slot, slot)
 		}
-		ns := r.t - t0
-		target := int64(slot * Delta)
-		slop := int64(Delta) / 4
-		if ns < target-slop || ns > target+slop {
-			return fmt.Errorf("after queue slot %d arrived at %g, expected [%g,%g]", slot, float64(ns), float64(target-slop), float64(target+slop))
+		dt := r.t.Sub(t0)
+		target := Duration(slot) * Delta
+		slop := Delta / 4
+		if dt < target-slop || dt > target+slop {
+			return fmt.Errorf("After(%s) arrived at %s, expected [%s,%s]", target, dt, target-slop, target+slop)
 		}
 	}
 	return nil