Source file
src/time/zoneinfo_js.go
1
2
3
4
5
6
7 package time
8
9 import (
10 "runtime"
11 "syscall/js"
12 )
13
14 var zoneSources = []string{
15 "/usr/share/zoneinfo/",
16 "/usr/share/lib/zoneinfo/",
17 "/usr/lib/locale/TZ/",
18 runtime.GOROOT() + "/lib/time/zoneinfo.zip",
19 }
20
21 func initLocal() {
22 localLoc.name = "Local"
23
24 z := zone{}
25 d := js.Global().Get("Date").New()
26 offset := d.Call("getTimezoneOffset").Int() * -1
27 z.offset = offset * 60
28
29
30
31
32
33 z.name = "UTC"
34 if offset < 0 {
35 z.name += "-"
36 offset *= -1
37 } else {
38 z.name += "+"
39 }
40 z.name += itoa(offset / 60)
41 min := offset % 60
42 if min != 0 {
43 z.name += ":" + itoa(min)
44 }
45 localLoc.zone = []zone{z}
46 }
47
48
49
50 func itoa(i int) string {
51 if i < 10 {
52 return digits[i : i+1]
53 }
54 return smallsString[i*2 : i*2+2]
55 }
56
57 const smallsString = "00010203040506070809" +
58 "10111213141516171819" +
59 "20212223242526272829" +
60 "30313233343536373839" +
61 "40414243444546474849" +
62 "50515253545556575859" +
63 "60616263646566676869" +
64 "70717273747576777879" +
65 "80818283848586878889" +
66 "90919293949596979899"
67 const digits = "0123456789"
68
View as plain text