Skip to content

Request: (*Object)Time() time.Time method #668

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

Closed
flimzy opened this issue Jul 30, 2017 · 3 comments
Closed

Request: (*Object)Time() time.Time method #668

flimzy opened this issue Jul 30, 2017 · 3 comments

Comments

@flimzy
Copy link
Member

flimzy commented Jul 30, 2017

It's possible to convert a JS Date object to time.Time with a struct:

type foo struct {
    *js.Object
    FooTimestamp time.Time `js:"timestamp"`
}

But I don't see any way to do it otherwise.

Would it be reasonable to add a Time() method to the *js.Object type to do this, to match Int64(), String(), Bool(), Float(), etc, etc?

I envisage a function signature of:

func (o *Object) Time() time.Time

Which would panic if o is not an instance of JS type Date.

@dmitshur
Copy link
Member

dmitshur commented Jul 30, 2017

But I don't see any way to do it otherwise.

It's possible to convert it directly. See the table at js package docs:

image

Example at https://gopherjs.github.io/playground/#/P7ktYq34Zl.

@flimzy
Copy link
Member Author

flimzy commented Jul 30, 2017

Oh right. Thanks. Not sure why I overlooked that. 👍

@flimzy flimzy closed this as completed Jul 30, 2017
@myitcv
Copy link
Member

myitcv commented Jul 31, 2017

Just to confirm the perhaps obvious: this conversion will remain post #617.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants