-
Notifications
You must be signed in to change notification settings - Fork 570
time.Now().String() should work #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Is this a good solution to your problem? |
Yeah, it worked. Thanks! |
Hi, d, _ := time.ParseDuration("1m30s")
fmt.Println("%T, %v", d, d)
// prints: "int64, 90000000000" And then, any attempt to call I tried on the gopherjs playground, and of course it doesn't have the same behavior. I have |
GopherJS tip (3e4dfb7) with Go 1.12.7 on my mac works for me: package main
import (
"fmt"
"runtime"
"time"
)
func main() {
d, _ := time.ParseDuration("1m30s")
fmt.Printf("%T, %v\n", d, d)
fmt.Printf("%s\n", d)
fmt.Printf("%s\n", d.String())
fmt.Printf("%s\n", runtime.Version())
} prints % gopherjs run issue_32.go
time.Duration, 1m30s
1m30s
1m30s
go1.12.7
% gopherjs version
GopherJS 1.12-2 Maybe an upgrade would fix things? |
Actually, to repeat my use case in a more similar way, I received a I found a workaround, which consists of:
And then it's rightfully considered as (And I tried with just this, and it failed:
) |
What's the actual type returned by If it is returning a Could you post a full main() function or link to the GopherJS playground that reproduces the problem? |
Here is the gopherjs playground: And the equivalent go playground: |
Y'all this is weird. From @dolanor's first gopherjs playground link: type Message struct {
Duration time.Duration
}
m := Message{Duration: time.Minute}
var buf bytes.Buffer
err := gob.NewEncoder(&buf).Encode(m)
if err != nil {
panic(err)
}
m2 := Message{}
err = gob.NewDecoder(&buf).Decode(&m2)
if err != nil {
panic(err)
}
fmt.Printf("m2 => type: %T, value: %v, decimal: %d\n", m2.Duration, m2.Duration, m2.Duration)
// prints m2 => type: int64 [should be time.Duration], value: 60000000000 [should be 1m0s], decimal: 60000000000 [this is fine] So somehow the gob decoder is not setting the type of Somebody that knows more gopherjs internals than I do is going to have to weigh on this. Sorry @dolanor. Might want to open a new issue. |
Trying to convert a time.Time object to a string might not work. It is because this seems to need the access to a file where zones are defined if the Time includes a locale. As far as I know, a Time object with UTC (like a Time created by time.Parse()) doesn't cause problems. For example, on my locale machine:
can be compiled, but the JavaScript file results in:
I wonder if I could use Time object without accessing any files. As JavaScript's Time knows the local locale, time.Now().String() should be able to work.
The text was updated successfully, but these errors were encountered: