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
Bug with hours format on diff moment object #1597
Comments
Can you boil this down to as few lines as possible with an expected result and an actual result? I'm not quite sure what I'm looking at here. |
Sure thing, that was a snippet you could copy and paste into some client-side code to replicate, but this also reproduces the discrepancy.
|
Thanks. The problem is that var totalTimeAgo = currentTime.diff(testPostDate); // 3483000
moment(totalTimeAgo).format(); //=> "1969-12-31T19:58:03-05:00" The reason that's 19:58 instead of 00:58 is that it's in local time. So you can fix this by using UTC: moment(totalTimeAgo).utc().format(); //=> "1970-01-01T00:58:03+00:00"
//thus
moment(totalTimeAgo).utc().format('H'); //=> "0" Note that all of this is sort of a hack. The really right way to do this is through Durations: var totalTimeAgo = currentTime.diff(testPostDate);
moment.duration(totalTimeAgo).hours(); //=> 0
//or if you like decimals
moment.duration(totalTimeAgo).asHours(); //=> 0.9675 The issue is that we haven't yet implemented |
Okay good to know, I was looking at durations, and will switch over to that instead. Thanks! |
I'm getting bad data back when trying to do a difference between two moment date objects. Only appears to occur for the hour format. I've attached the debug code that is working for me so you can simulate the issue. Could be bad code, but I couldn't find anything wrong with this after looking through the documentation for a few hours and only have problem trying to use moment to get back the remainder hours...
The text was updated successfully, but these errors were encountered: