Source file
test/fixedbugs/issue17918.go
1
2
3
4
5
6
7
8
9 package dead
10
11 import (
12 "fmt"
13 "time"
14 )
15
16 var (
17 units = []struct {
18 divisor time.Duration
19 unit rune
20 }{
21 {1000000, 's'},
22 {60, 'm'},
23 {60, 'h'},
24 {24, 'd'},
25 {7, 'w'},
26 }
27 )
28
29 func foobar(d time.Duration) string {
30 d /= time.Microsecond
31 unit := 'u'
32
33 for _, f := range units {
34 if d%f.divisor != 0 {
35 break
36 }
37 d /= f.divisor
38 unit = f.unit
39 }
40 return fmt.Sprintf("%d%c", d, unit)
41 }
42
View as plain text