-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Nanosecond precision #2022
Comments
There is no Date object that supports nanoseconds. We might have parsing, storage, setting, we might even try to extract from |
👎 Tracking dates with more precision than JS doesn't seem like a good fit for Moment. |
Hmm I would not mind bumping this. Since 64-bit numbers are supported and widely used in many backend languages, there may be valid cases where a company who is native-client-focused supplies a timestamp in accordance with RFC3339Nano. Take a look at the godocs for the
I definitely think that parsing at the least should be supported. I'm not steadfast on doing the additional padding as a convenience when creating strings, but it would be nice to have. |
Parsing is already supported, with any number of decimal places. It's only formatting that is restricted to 3 decimal places. The only bit of weirdness is that it repeats the value in the formatting. moment('2014-07-30 02:59:32.123456789','YYYY-MM-DD HH:mm:ss.SSSSSSSSS').format('YYYY-MM-DD HH:mm:ss.SSSSSSSSS')
// returns: "2014-07-30 02:59:32.1231231"
// expected: "2014-07-30 02:59:32.1230000" |
Logged that issue separately. Closing this one. |
👍 |
What about
|
I can't imagine what purpose that would serve. I highly doubt anyone working with time on the nanosecond scale cares about calendar concepts like years. If one wants to deal in nanoseconds, they can just work with numbers. Besides, a moment-duration's year and month are approximations anyway. |
I care :( And numbers don't work as 1 year in nanoseconds is > Number.MAX_SAFE_INTEGER |
Can you provide more details? What is the use case? |
Basically I am collecting some data that is nanosecond precision, it is kept for more than 1 year. So in my app I want to parse and format duration that can be < 1ms or > 1 year |
I totally get there's a use case for this, but it's just not common enough to put into Moment, especially given how hard it would be. We'd have the same problem internally with not being able to fit the numbers in JS types, too, for example. Moment has a lot of features now, but we still need to be judicious about what we add, even if that excludes some use case. |
Fair enough |
There is a date class that supports down to nano seconds https://www.npmjs.com/package/nano-date |
|
The final word on this is no. Moment will not get support for nanosecond precision. However, @maggiepint and I are working on a new native date/time API that will indeed support nanoseconds. https://github.com/tc39/proposal-temporal See particularly tc39/proposal-temporal#34 |
momentjs should support nanosecond precision (9 digits after the second), at least for parsing and formatting.
The following code should output 2014-07-30 02:59:32.109590000
The text was updated successfully, but these errors were encountered: