• RandomGuy (unregistered)

    TRWTF is AM and PM instead of 24h time ...

  • Pete (unregistered)

    Brillant!

    All the cool kids are using EHDST* format now.

    *Evening Hour Decrement Standard Time

  • Anon (unregistered) in reply to RandomGuy

    That's actually what I thought, first.

  • rob (unregistered)

    If this has to be done at all in PHP, then the code should be something like

    function getTimeFromISODateTime($date) { list ($day, $time) = split (" ", $date); list ($hour, $min, $sec) = split (":", $time);

    /* assumes that provided value shows time as military */ $ampm = "AM"; if if ($hour => 12) { $ampm = "PM"; } if ($hour > 12) { $hour = 24 - $hour; }

    if (strlen($hour) == 1) $hour = "0" . $hour;

    return $hour . ":" . $min . ":" . $sec . " " . $ampm; }

  • Mike5 (unregistered)

    Also, what about hour '0' ?

  • cpradio (unregistered) in reply to rob
    rob:
    If this has to be done at all in PHP, then the code should be something like

    function getTimeFromISODateTime($date) { list ($day, $time) = split (" ", $date); list ($hour, $min, $sec) = split (":", $time);

    /* assumes that provided value shows time as military */ $ampm = "AM"; if if ($hour => 12) { $ampm = "PM"; } if ($hour > 12) { $hour = 24 - $hour; }

    if (strlen($hour) == 1) $hour = "0" . $hour;

    return $hour . ":" . $min . ":" . $sec . " " . $ampm; }

    I think you missed the critical issue here, 24-$hour is entirely wrong! Consider 1 PM (13), 24-13 = 11. It should have been $hour = $hour - 12;

  • Sam (unregistered)

    This is in fact trivial to do in PHP in a perfectly sensible way:

    function getTimeFromISODateTime($date) {
        $datetime = new DateTime($date);
        return $datetime->format('g:i:s A');
    }
    

    This assumes that counting the afternoon hours from 1 to 12 is desired behaviour.

  • TheIrritainer (unregistered) in reply to rob
    rob:
    If this has to be done at all in PHP, then the code should be something like

    function getTimeFromISODateTime($date) { list ($day, $time) = split (" ", $date); list ($hour, $min, $sec) = split (":", $time);

    /* assumes that provided value shows time as military */ $ampm = "AM"; if if ($hour => 12) { $ampm = "PM"; } if ($hour > 12) { $hour = 24 - $hour; }

    if (strlen($hour) == 1) $hour = "0" . $hour;

    return $hour . ":" . $min . ":" . $sec . " " . $ampm; }

    sigh, the error appears due to $hour = 24 - $hour. 24 - 13 = 11....

    $hour = $hour - 12;

    But still horrible use of PHP..

  • (cs)

    Ode To A Small Lump Of Green Putty I Found In My Armpit One Midsummer Morning

  • Bring Back TopCod3r (unregistered) in reply to cpradio

    True, but thanks to rob, I am now also aware of the lesser WTF of it showing 12 AM not 12 PM, and also of course 00 AM not 12 AM.

  • (cs) in reply to Sam
    Sam:
    This is in fact trivial to do in PHP in a perfectly sensible way:
    function getTimeFromISODateTime($date) {
        $datetime = new DateTime($date);
        return $datetime->format('g:i:s A');
    }
    
    This assumes that counting the afternoon hours from 1 to 12 is desired behaviour.
    Thank you. Some sanity, at last.

    And for those wondering whether this is some new-fangled technology not available at the time: the DateTime class was only formally introduced with PHP5.2, but you can do the exact same thing with strtotime() and date(), which have been around for a lot longer.

  • someone (unregistered)

    Developer days feel like a roller coaster...

  • Hannes (unregistered) in reply to Mike5
    Mike5:
    Also, what about hour '0' ?

    The code says: If the length of the hour is just one letter (ie '9') then add a 0 to it (ie '09'). Just a formatting issue.

    But of course, TRWTF is PHP.

  • Patrys (unregistered) in reply to Hannes
    Hannes:
    Mike5:
    Also, what about hour '0' ?

    The code says: If the length of the hour is just one letter (ie '9') then add a 0 to it (ie '09'). Just a formatting issue.

    Nope, in 24-hour format midnight is in fact hour zero. Which means that the code in question shows midnight as 0AM and noon as 12AM.

  • chipdale (unregistered) in reply to Bring Back TopCod3r

    12 noon is neither am nor pm. The m means meridian (i.e. midday/noon) The A means ante (before) and the P means post (after). So 12 noon is neither before noon nor after noon, it IS noon.

    Similarly for midnight. Is it midnight this morning or midnight tonight?

    http://www.npl.co.uk/science-technology/time-frequency/time/faqs/is-midnight-12-a.m.-or-12-p.m.-(faq-time)

  • Shutterbug (unregistered) in reply to Zagyg
    Zagyg:
    Ode To A Small Lump Of Green Putty I Found In My Armpit One Midsummer Morning

    +1 for the vogon poetry!

  • Bring Back TopCod3r (unregistered) in reply to chipdale
    chipdale:
    12 noon is neither am nor pm. The m means meridian (i.e. midday/noon) The A means ante (before) and the P means post (after). So 12 noon is neither before noon nor after noon, it IS noon.

    Similarly for midnight. Is it midnight this morning or midnight tonight?

    http://www.npl.co.uk/science-technology/time-frequency/time/faqs/is-midnight-12-a.m.-or-12-p.m.-(faq-time)

    Well caught, but 12:00:01 is definitely Post Meridian.

  • Geoff (unregistered)

    Never done any PHP myself but I would expect there would be some data/time library functions that can convert a unix time value to a string in the desired format? Seems like a pretty common need that would part of something like PHP

  • someone (unregistered) in reply to Bring Back TopCod3r

    It has nothing to do with Meridians. Meridiem, on the other hand, is like Latin for Midday

  • phord (unregistered) in reply to chipdale

    It is assumed that 12:00:00 does not represent the precise moment of the meridian, but some milliseconds thereafter. So, 12:00:01PM is as correct as 12:00:00PM, meridian be damned. You're right that it still can cause confusion as there is no standard. Perhaps the code should always add one minute to the time if ever out finds out to be "12:00". :-)

  • TheLatinPig (unregistered) in reply to someone

    if you want to nitpick, someone, the Latin word would be like meridies, meridiem being like the accusative form.

  • Sam (unregistered) in reply to TheLatinPig
    TheLatinPig:
    if you want to nitpick, someone, the Latin word would be like meridies, meridiem being like the accusative form.

    Although in "AM" the word would indeed by meridiem, since ante takes the accusative.

  • (cs) in reply to TheLatinPig
    TheLatinPig:
    if you want to nitpick, someone, the Latin word would be like meridies, meridiem being like the accusative form.
    From http://en.wikipedia.org/wiki/12-hour_clock:
    The 12-hour clock is a time convention in which the 24 hours of the day are divided into two periods:[1] a.m. (from the Latin ante meridiem, meaning "before midday") and p.m. (post meridiem, "after midday").[2] Each period consists of 12 hours numbered: 12 (acting as zero),[3] 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11.

    In the same vein: http://www.nist.gov/pml/div688/times.cfm

    Are noon and midnight referred to as 12 a.m. or 12 p.m.? This is a tricky question because 12 a.m. and 12 p.m. are ambiguous and should not be used.

    To illustrate this, consider that "a.m." and "p.m." are abbreviations for "ante meridiem" and "post meridiem," which mean "before noon" and "after noon," respectively. Since noon is neither before noon nor after noon, a designation of either a.m. or p.m. is incorrect. Also, midnight is both twelve hours before noon and twelve hours after noon.

    It is fair to say, however, that the shortest measurable duration after noon should be designated as p.m. For example, it would be applicable for a digital clock changing from 11:59:59 a.m. to 12:00:00 to indicate p.m. as soon as it the 12:00 appears, and not delay the display of the p.m. by a minute, or even a second. The same is true for midnight, but there is an added issue of which day midnight refers to (see below).

    Hours of operation for a business or other references to a block of time should also follow this designation rule. For example, a business might be open on Saturdays from 8 a.m. to noon or weekends from 3:30 p.m. until midnight. Is midnight the end of a day or the beginning of a day? When someone refers to "midnight tonight" or "midnight last night" the reference of time is obvious. However, if a date/time is referred to as "at midnight on Friday, October 20th" the intention could be either midnight the beginning of the day or midnight at the end of the day.

    To avoid ambiguity, specification of an event as occurring on a particular day at 11:59 p.m. or 12:01 a.m. is a good idea, especially legal documents such as contracts and insurance policies. Another option would be to use 24-hour clock, using the designation of 0000 to refer to midnight at the beginning of a given day (or date) and 2400 to designate the end of a given day (or date).

    So I'd say that the evidence lies in favour of "meridiem" regardless of the grammatical correctness of the word in this context. And of 12:00:00 m being technically correct for the infinitessimal period at exactly noon, but for practical purposes there is no point in doing it. Imagine an LCD clock - in the time that the "m" takes to appear, it will have become invalid, so don't bother. And for specifying "noon", since there is a hypothecated quantum granularity of time, we can assert that it probably can never actually be exactly noon, but always a small fraction of a Planck interval before or after, it is always either am or pm.

    Steve The Cynic has spoken. Let it be so.

  • Rollyn01 (unregistered)

    This is one of the reasons for me that the 24-hour format makes more sense, less ambiguity to work. Then again, It could be that it can never get a good gauge on whether it's morning or evening by looking at a 12-hour clock. Damn summers and winters.

    Captcha: aliquam. I doubt aliquam, I'm not into dudes that way.

  • Landius (unregistered)

    You didn't really listen to TheLatinPig.

    "meridies" is the Latin word for "midday", and as usual, we refer to nouns by their nominative form, so this is the one in dictionaries.

    The latin prepositions "ante" and "post", however, force the noun to be in accusative form, which happens to be "meridiem". So please don't just cite Wikipedia and claim to have evidence. This is probably TRWTF ;)

  • miko (unregistered)

    TRWTF is definitely the murican AM/PM over-complication of it all. Why bother? Why not just give in and do like the rest of the world? The day starts at zero (00:00) and ends at 24 (24:00) because there are 24 hours in a day. Simple as that.

    Please convert to the metric system already, so we can speak to each other without confusion... "1 inch is 0.083333333 feet" and "1 cup is 0.0625 gallons" who can keep track of those decimal values? How do you even remember if it's 0.0833 or 0.0625?

  • Pippo (unregistered) in reply to RandomGuy
    RandomGuy:
    TRWTF is AM and PM instead of 24h time ...

    +1

    CAPTCHA: odio again, so it REALLY hates me

  • EatenByAGrue (unregistered) in reply to Zagyg
    Zagyg:
    Ode To A Small Lump Of Green Putty I Found In My Armpit One Midsummer Morning

    That's nothing - check out this bit by Paula Nancy Millstone Jennings:

    The dead swans lay in the stagnant pool. They lay. They rotted. They turned Around occasionally. Bits of flesh dropped off them from Time to time. And sank into the pool's mire. They also smelt a great deal.

  • Franky (unregistered)

    q.e.d. US date notation sucks. 24 hour format forever!

  • Anonymous Paranoiac (unregistered) in reply to Geoff
    Geoff:
    Never done any PHP myself but I would expect there would be some date/time library functions that can convert a unix time value to a string in the desired format? Seems like a pretty common need that would part of something like PHP

    FTFY. Also, as Sam pointed out, PHP does have date/time library functions that would have made doing this 'correctly' (I think we can all agree that the only 'correct' date format is the yyyy-mm-dd hh:mm:ss standard) trivial.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)
    $hour = 24 - $hour;
    Wow. Just wow. It's like Daylight Saving Time, only different! 9pm sunsets in the summer not good enough for you? How about sunny at 11pm all year round!
  • salmiyak lover #0000021 (unregistered)

    It took me a minute to see it, but when I saw it I could not unsee it.

    I understand what he was going for but man, if youre doing a $shour>12 check you should think to shape your decrement by the same number you're checking against, no?

  • (cs) in reply to miko
    miko:
    TRWTF is definitely the murican AM/PM over-complication of it all. Why bother? Why not just give in and do like the rest of the world? The day starts at zero (00:00) and ends at 24 (24:00) because there are 24 hours in a day. Simple as that.

    Please convert to the metric system already, so we can speak to each other without confusion... "1 inch is 0.083333333 feet" and "1 cup is 0.0625 gallons" who can keep track of those decimal values? How do you even remember if it's 0.0833 or 0.0625?

    I find it easier to remember 12 inches to the foot and 8 pints to the gallon which combines with 2 cups to the pint to give 16 cups to the gallon.

    Of course, if you are worrying about the conversion between cups and gallons, you're probably doing something wrong. (Notably: why the hell are you measuring cooking ingredients - the normal stuff you measure in cups - in gallons?)

  • (cs)

    So time runs forwards for half the day, then backwards for the remainder?

    Nice.

  • (cs) in reply to EatenByAGrue
    EatenByAGrue:
    That's nothing - check out this bit by Paula Nancy Millstone Jennings:

    The dead swans lay in the stagnant pool. They lay. They rotted. They turned Around occasionally. Bits of flesh dropped off them from Time to time. And sank into the pool's mire. They also smelt a great deal.

    Hey? that's not half bad.

  • (cs) in reply to eViLegion
    eViLegion:
    So time runs forwards for half the day, then backwards for the remainder?

    Nice.

    How else would it be able to start at exactly the same time on the next day? The clocks need to be rewound.

  • 3rd Ferguson (unregistered) in reply to eViLegion
    eViLegion:
    EatenByAGrue:
    That's nothing - check out this bit by Paula Nancy Millstone Jennings:

    The dead swans lay in the stagnant pool. They lay. They rotted. They turned Around occasionally. Bits of flesh dropped off them from Time to time. And sank into the pool's mire. They also smelt a great deal.

    Hey? that's not half bad.

    It's all bad!

    <StatlerAndWaldorf>Meh-heh-heh-heh-heh!</StatlerAndWaldorf>

  • miko (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    Of course, if you are worrying about the conversion between cups and gallons, you're probably doing something wrong. (Notably: why the hell are you measuring cooking ingredients - the normal stuff you measure in cups - in **gallons**?)

    You are right - something is wrong when you measure in cups or gallons ;) Different households have different cups - some even have different sized cups for coffee and for tea.

    No, I wouldn't know which to use, I heard there is also a difference between dry and wet ounces, and that fact alone is enough for me to NOT trust those scales. I recently saw a graph of how much sugar is in a coke bottle, but the coke bottle volume was measured in ounces (I think) and the amount of sugar in it was measured in cups - how is that in any way relevant to each other? You guys mix your scales all the time, and it is so confusing.

    1 cubic metre of water = 1000 litres = 1000 kilos. 100 degrees, water turns to gas. 0 degrees, water turns to ice. (under normal pressure) Same scale. Always 10 based. Simple. You should try it! :)

  • JC (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    miko:
    TRWTF is definitely the murican AM/PM over-complication of it all. Why bother? Why not just give in and do like the rest of the world? The day starts at zero (00:00) and ends at 24 (24:00) because there are 24 hours in a day. Simple as that.

    Please convert to the metric system already, so we can speak to each other without confusion... "1 inch is 0.083333333 feet" and "1 cup is 0.0625 gallons" who can keep track of those decimal values? How do you even remember if it's 0.0833 or 0.0625?

    I find it easier to remember 12 inches to the foot and 8 pints to the gallon which combines with 2 cups to the pint to give 16 cups to the gallon.

    Of course, if you are worrying about the conversion between cups and gallons, you're probably doing something wrong. (Notably: why the hell are you measuring cooking ingredients - the normal stuff you measure in cups - in gallons?)

    TRWTF is Americans using cups for measuring cooking ingredients. Especially things like flour, which can vary in density quite significantly depending on if it's sifted, how well packed it is in the packed etc.

  • (cs) in reply to miko
    miko:
    TRWTF is definitely the murican AM/PM over-complication of it all. Why bother? Why not just give in and do like the rest of the world? The day starts at zero (00:00) and ends at 24 (24:00) because there are 24 hours in a day. Simple as that.

    Please convert to the metric system already, so we can speak to each other without confusion... "1 inch is 0.083333333 feet" and "1 cup is 0.0625 gallons" who can keep track of those decimal values? How do you even remember if it's 0.0833 or 0.0625?

    The ONLY reason we have the metric system is because we're so pedantic on decimal-points of measurements. Which is great for working measurements of space and volume like designing a building. It's horrible for other uses like cooking, etc.

    When using different measurements for different sizes, they don't have to be related. We can measure a person by feet. 6 and 1/3, 6 and 1/2, 6 and 1/4, 6 and 1/6. We have all those specifications with feet and inches.

    If you still want to keep on this issue, then why 10s. Why don't we scale metric to a base that makes more sense. Nope, we chose 10s. 10 is a horrible number for fractions. 12 is much much better, 30 if you'd prefer using 1/5 over 1/4, 60 does it all but much harder to create a character system for. What's 1/4, 1/3, 1/6 of 10?

    When cooking, do you measure your ground herbs by liter? I suppose you could do milliliter, or worse "cubic-centimeter", but have you compared recipes in metric vs. "standard"?

    The reason standard exists is because we used to measure by what made sense for the size/scale/object. Now we want all our measurements to relate so it's easier to compare. But outside of engineering, do you really need to compare the weight of your eggs to a skyscraper?

    Addendum (2013-07-09 10:18): 10 was a number we should have abandoned when we could start recording amounts. 10 is only useful because we only have 10 fingers. What's the fractional granularity of 10. 1/10, 1/5, 1/2. That's it. 1, 2, and 5. With 12 we get 1/12, 1/6, 1/3, 1/4, 1/6, or 1, 2, 3, 4, and 6. We only miss 5.

    It's much easier for humans to use fractions of 1/x or (x-1)/x. Other fractions are meaningless when we hear them. How do you compare 5/12 to 1/3 or 2/3? Takes a second?

    How do you compare 4/10 to 9/10? We can compare 4/10 to 8/10 quickly because 4/8 is 1/2. But 4/9? Not that useful.

  • (cs) in reply to miko
    miko:
    You are right - something is wrong when you measure in cups or gallons ;) Different households have different cups - some even have different sized cups for coffee and for tea.

    Take a FAIL point, dude. Whenmeasuringliquids a cup is a unit of measure, equal to half a pint. Of course that means a US cup is about 5/6 of an Imperial cup, because the corresponding pints are in about that ratio. (And, worse, they aren't the same number of fluid ounces, because a US pint is 16 US fluid ounces, while an Imperial pint (the only way to measure beer, even if you call it 568ml) is 20 Imperial fluid ounces.)

    miko:
    No, I wouldn't know which to use, I heard there is also a difference between dry and wet ounces, and that fact alone is enough for me to NOT trust those scales.
    It's easy. A dry ounce is a unit of force, usually used for weights, while a fluid (not wet) ounce is a unit of volume.
    miko:
    I recently saw a graph of how much sugar is in a coke bottle, but the coke bottle volume was measured in ounces (I think) and the amount of sugar in it was measured in cups - how is that in any way relevant to each other? You guys mix your scales all the time, and it is so confusing.
    Which 'you guys' are you talking about? You obviously haven't been paying attention. I'm an Englishman living in France. My everyday life (vie quotidienne?) is in metric, although I'll admit to still thinking of terrestrial distances and speeds in miles.
    miko:
    1 cubic metre of water = 1000 litres = 1000 kilos. 100 degrees, water turns to gas. 0 degrees, water turns to ice. (under normal pressure) Same scale. Always 10 based. Simple. You should try it! :)
    Actually, water turns to gas at any temperature below the critical point, if the partial pressure of water vapour is low enough. It's called evaporation above the melting point, and sublimation below. You meant to say that water *boils* at 100 degrees centigrade. (And that centigrade part is important because the F scale is also degrees. Alternatively, go 100% SI, where water melts (at standard pressure) at 273.15 K (not degrees, because the kelvin unit is not a degrees unit).)
  • (cs) in reply to JC
    JC:
    TRWTF is Americans using cups for measuring cooking ingredients. Especially things like flour, which can vary in density quite significantly depending on if it's sifted, how well packed it is in the packed etc.
    I agree 100% with that. However the US tendency to measure liquids in recipes in cups is why I still have some US cup-fraction measuring scoops at home. It's moderately annoying.
  • Bring Back TopCod3r (unregistered) in reply to someone
    someone:
    It has nothing to do with Meridians. Meridiem, on the other hand, is like Latin for Midday

    That makes a lot more sense.

  • Hannes (unregistered) in reply to Patrys
    Patrys:
    Hannes:
    Mike5:
    Also, what about hour '0' ?

    The code says: If the length of the hour is just one letter (ie '9') then add a 0 to it (ie '09'). Just a formatting issue.

    Nope, in 24-hour format midnight is in fact hour zero.

    I know. ;) Still the code adds an extra zero if the hour is between 0 and 9.

  • dpm (unregistered) in reply to miko
    miko:
    The day starts at zero (00:00) and ends at 24 (24:00) because there are 24 hours in a day.
    Technically, a day begins at 00:00:00 and ends at 23:59:59 --- you have an off-by-one error.
  • Chris P. Peterson (unregistered)

    A fail to be sure. Proof that even a basic unit test goes a long way. Reminds me of a co-worker who wrote a circle drawing routine that generated over a billion points in one of the paths through the code. An epic fail that could have been caught with a simple unit test that exercised all the paths through the code.

  • (cs) in reply to Steve The Cynic
    Steve The Cynic:
    JC:
    TRWTF is Americans using cups for measuring cooking ingredients. Especially things like flour, which can vary in density quite significantly depending on if it's sifted, how well packed it is in the packed etc.
    I agree 100% with that. However the US tendency to measure liquids in recipes in cups is why I still have some US cup-fraction measuring scoops at home. It's moderately annoying.

    I suppose you could keep a small scale and measure by grams.

  • (cs) in reply to dpm
    dpm:
    miko:
    The day starts at zero (00:00) and ends at 24 (24:00) because there are 24 hours in a day.
    Technically, a day begins at 00:00:00 and ends at 23:59:59 --- you have an off-by-one error.

    23:59:59.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999....

    Addendum (2013-07-09 10:28): Which is the same as 24:00:00.

    http://en.wikipedia.org/wiki/0.999...

  • (cs) in reply to Steve The Cynic
    Steve The Cynic:

    Take a FAIL point, dude. Whenmeasuringliquids a cup is a unit of measure, equal to half a pint. Of course that means a US cup is about 5/6 of an Imperial cup, because the corresponding pints are in about that ratio. (And, worse, they aren't the same number of fluid ounces, because a US pint is 16 US fluid ounces, while an Imperial pint (the only way to measure beer, even if you call it 568ml) is 20 Imperial fluid ounces.)

    See, this is why I don't understand bashing the standard system.

    If you are stubborn enough to insist that 1 -> 10 is superior in every way. Why abandon that and convert 568ml to 20?

    At that point you basically reintroduced the standard system, which is measure by whatever makes sense and not worry about being able to convert.

    Do you really need to know how much beer it would take to fill the pipes in the water treatment plant?

    No... You need a way to personally track how much beer it takes to get intoxicated. Which is best measurable in drinks, which is measured per drink type by alcohol content over total volume.

    For example, you have a separate cup for shots than wine, and it's not just for style. Do you really want to drink wine in shot glasses, or shots in wine glasses.

  • huppenzuppen (unregistered) in reply to dpm

    No, it doesn't. You're missing one second.

Leave a comment on “Epoch Fail”

Log In or post as a guest

Replying to comment #412033:

« Return to Article