Skip to content
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

00:00:00 should not be equal to 12:00:00 when parsed with h:m:s format #123

Closed
davidcalhoun opened this issue Jan 6, 2012 · 4 comments
Closed
Milestone

Comments

@davidcalhoun
Copy link

These seem to be the wrong results - am I doing something wrong?

moment('12:00:00', 'hh:mm:ss').format('hh:mm:ss'); // "12:00:00"
moment('00:00:00', 'hh:mm:ss').format('hh:mm:ss'); // "12:00:00" (seems to be incorrect)

moment('12:30:00', 'hh:mm:ss').format('hh:mm:ss'); // "12:30:00"
moment('00:30:00', 'hh:mm:ss').format('hh:mm:ss'); // "12:30:00" (seems to be incorrect)

@rockymeza
Copy link
Contributor

You should be using HH:mm:ss instead of hh:mm:ss in order to get a 24 hour clock.

However, there does seem to be a bug. 0 o'clock is not a valid hour in a 12-hour clock. I'm not sure what the desired behavior is in this situation though. It doesn't seem like you should get an error if it is 0 o'clock.

@davidcalhoun
Copy link
Author

Cool, thanks for the reply. I switched over to using HH but seem to still be getting the issue, at least with Chrome:

moment('12:00:00', 'HH:mm:ss').format('HH:mm:ss'); // "00:00:00" (incorrect?)
moment('00:00:00', 'HH:mm:ss').format('HH:mm:ss'); // "00:00:00" (correct behavior)

@timrwood
Copy link
Member

By default, HH and hh parse hours in 24 hour time. In order to parse in 12 hour time, you need to add 'am' or 'pm'.

The original post was be having correctly. You can see this if you add a to the formatting string.

moment('12:00:00', 'hh:mm:ss').format('hh:mm:ss a'); // "12:00:00 pm"
moment('00:00:00', 'hh:mm:ss').format('hh:mm:ss a'); // "12:00:00 am"

moment('12:30:00', 'hh:mm:ss').format('hh:mm:ss a'); // "12:30:00 pm"
moment('00:30:00', 'hh:mm:ss').format('hh:mm:ss a'); // "12:30:00 am"

I believe the issue below is a known issue that was fixed. It was caused by the commit in #74 and fixed in #92. I'm adding unit tests for it though. I'll also clarify the docs.

moment('12:00:00', 'HH:mm:ss').format('HH:mm:ss'); // "00:00:00"

If you are using 1.2.0, you should upgrade to 1.3.0, as that was when the bugfix was introduced.

@davidcalhoun
Copy link
Author

Cool, sounds good. Thanks!

butterflyhug pushed a commit to WhoopInc/frozen-moment-OLD that referenced this issue Jul 22, 2014
Fix copy/paste method sig issue
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