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