Skip to content

Commit 88d7a4e

Browse files
committed
compiler/natives/src/time: Don't import strings package.
The real time package doesn't import strings package. This keeps the import graph of augmented time package consistent with the real standard library. Source: https://godoc.org/time?import-graph This is a change analogous to #453.
1 parent 48aeb3a commit 88d7a4e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/natives/src/time/time.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package time
44

55
import (
66
"runtime"
7-
"strings"
87

98
"github.com/gopherjs/gopherjs/js"
109
)
@@ -29,8 +28,8 @@ type runtimeTimer struct {
2928
func initLocal() {
3029
d := js.Global.Get("Date").New()
3130
s := d.String()
32-
i := strings.IndexByte(s, '(')
33-
j := strings.IndexByte(s, ')')
31+
i := indexByte(s, '(')
32+
j := indexByte(s, ')')
3433
if i == -1 || j == -1 {
3534
localLoc.name = "UTC"
3635
return
@@ -95,3 +94,8 @@ func initTestingZone() {
9594
z.name = "Local"
9695
localLoc = *z
9796
}
97+
98+
// indexByte is copied from strings package to avoid importing it (since the real time package doesn't).
99+
func indexByte(s string, c byte) int {
100+
return js.InternalObject(s).Call("indexOf", js.Global.Get("String").Call("fromCharCode", c)).Int()
101+
}

0 commit comments

Comments
 (0)