-
Notifications
You must be signed in to change notification settings - Fork 730
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
DateTime.toSeconds returns seconds.milliseconds #565
Comments
The reason people typically want You can alway call |
@icambron, thanks for clarification. |
Hey @icambron, just found this issue after spending some considerable time debugging why my app doesn't work, because I would never expect toSeconds() to return seconds.miliseconds. |
This was also a surprise to me |
Likewise. I think at the very least the docs should be explicit that a decimal number is returned |
I just ran into this issue as well. I definitely think it should return just the seconds stripping the millis. While I totally agree that I would not change this to return an One other possibility is to have an option to enable milliseconds. Something like Lastly, whether any changes are made, the current behavior should definitely be added/clarified in the docs 😄 |
I think it's quite reasonable to return a fractional number here, and I don't think it has anything to do with UNIX timestamps. It's fundamentally just a unit conversion like any other, and those can be fractional; if you were to convert "1300 meters" to kilometers, you would also expect to get "1.3 km" and not "1 km". This is different from extracting the amount of seconds, eg. From a practical perspective, it also makes sense; while you can round a fractional number, you cannot un-round a whole number. So returning just the whole seconds would make it impossible to get the fractional seconds from that. That having been said: yes, this should be explicitly documented. |
I think you should update the example in the manual : https://moment.github.io/luxon/docs/manual/formatting.html |
While some unix systems accepts floating point values for seconds, I believe that is not in specified (see e.g. usage in JWT https://tools.ietf.org/html/rfc7519#section-2 ). |
As explained on moment#565 .toSeconds() returns seconds.milliseconds to mimic UNIX system behaviour.
As explained on #565 .toSeconds() returns seconds.milliseconds to mimic UNIX system behaviour.
LuxonDateTime.fromSeconds(1642832200,{zone: "America/Chicago"}); returns an offset of 1080 not sure how to get this resolved works fine for other date and time |
Also ran into this issue, and it in fact created a bug, because the systems we convert this to seconds for, do not accept floating point numbers. So I'm not sure what this assumption was based on, but I think the majority of users would expect the output of @icambron is there any chance this can be revisisted in the future? Having to wrap every occurrence of |
One issue that I've found with this is that TypeORM rounds the number automatically when inserting it into MySQL. So while the DB looks correct, I had no idea that the actual value was a decimal and was messing up my API calls as they were converting to a string which included the decimal. |
Hi,
I'm wondering why DateTime.toSeconds() does return a floating-point number xxxxx.yyy where yyy represents the milliseconds. If I wanted to have milliseconds I would have called .toMilliSeconds()
Expected:
DateTime.fromISO("2019-08-31T00:27:39.689Z").toSeconds() // --> 1567211259
Actual:
DateTime.fromISO("2019-08-31T00:27:39.689Z").toSeconds() // --> 1567211259.689
The text was updated successfully, but these errors were encountered: