-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add support for creation with unix timestamp in seconds #213
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
Conversation
Now that I look at the unix timestamp docs again, I guess it could be confusing. Let me know what you think. |
Any feedback on this? If it doesn't fit in Moment, I can just close this pull request and keep the patch on our side. |
Yeah, now that I look into it, I guess the docs are a bit of a misnomer. It should be something like 'Milliseconds since the Unix Epoch'. I think I also need to make it much clearer that javascript measures time in milliseconds since the epoch, as that may be a common trip-up. Also, I'll probably make the getter function named 'unix' instead of 'unixValueOf', as I only use 'valueOf' so that comparision operators can work ( |
Add support for creation with unix timestamp in seconds
I also switched to flooring instead of rounding, as that's probably more accurate to how unix timestamps are calculated. |
Fair enough. Thanks! :) |
I am dealing exclusively in unix timestamps (seconds) for the project I'm working on, so this is a welcomed addition. However I also deal exclusively in UTC timestamps, so the creation of non-localized moments still requires |
@slindberg, you could use
The only other options I could think of are something like |
@timrwood, I mistakenly assumed there was overhead involved in creating a localized Moment instance that could be bypassed using the |
This is something that we wanted to avoid doing *1000 on every single UTC timestamp we receive (in seconds).
Figured I would suggest it as I think it makes a nicer API.
I can look into writing tests/docs for it first if you want.