Hacker News new | past | comments | ask | show | jobs | submit login

Your function converts "0:23" into "11:00 PM".



If you were a human, you would have written "00:23", not "0:23".

It'll also convert "0:45" into "00:00AM" (and "0:23" into "11:00PM").


> If you were a human, you would have written "00:23", not "0:23".

No, I wouldn't. Leaving out the leading zero is pretty common where I'm from.


You come from a weird place.


Don't worry, we say the same about the US, where 12pm comes before 11pm.


Does that mean that in your country, the day is considered to start at 1:00 AM rather than midnight? That choice is very strange when combined with the choice to call midnight "0:00" rather than "12:00 PM".


No, we just don't use AM/PM. In written language, the 24 hour format is used exclusively. When the 12 hour format is used in spoken language, we either leave it out entirely when clear from context, or use "in the morning" vs "in the evening".

So noon is "12 in the morning", which is an hour after "11 in the morning"; and midnight is "12 in the evening", which is an hour after "11 in the evening".


That's not really compatible with your comment about the US. By your own description, you do exactly the same thing that the US does,† but it's only strange when the US does it?

† That is, you follow 11:00 PM with 12:00 AM, and you don't actually refer to "AM" or "PM". Both of those are normal US practice. You are different in the use of 24-hour formats in writing, but that has no bearing on the question of whether the hour following 11 PM is 12 AM; you just assured me that that's true in both countries.


In your comparison, we follow 11:00 PM with 12:00 PM, not 12:00 AM.


So the day begins at 1:00 AM rather than midnight?


No, the day begins at midnight, we just call it 12:00 PM.


Good catch. Easy fix:

    // Preserve 2400h time by changing leading zeros to 24.
    time = time.replace( /^0*[0:]/, '24' );


> Easy fix:

That converts "0800" into "00:00AM".


True enough, the regex was overzealous. This looks better:

    time = time.replace( /^0*(0:)+/, '24' );




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: