• someone (unregistered)

    TRWTF is the US date format.

  • Hans (unregistered)

    IsLeapYeaarDate is probably just checking whether the year can be divided by 4.

  • bvs23bkv33 (unregistered)

    wait, they have 24 months?

  • xpil (unregistered) in reply to bvs23bkv33

    Twice the productivity!

  • RLB (unregistered) in reply to Hans

    I once wrote code that did that. Of course, that was code which, if it were still running in 2100, would be a sign of much worse problems (and TTBOMK it's not running any more, and if it is, it's SEP) and I added a comment that I knew it was wrong and why I didn't care.

  • DQ (unregistered)

    My favorite WTF is the for-loop itself having an end-condition that is not related to the rest.

  • LCrawford (unregistered) in reply to Hans

    Except that the date is passed to IsLeapYeaarDate in string format, so 4/4/2018 divided by 4 results in 0.000496 ; therefore this is leap year since it can be divided by 4.

  • my name is missing (unregistered)

    This is truly a real WTF. But it is a testament to the creativity of some programmers to solve problems in unique ways. The increasing/decreasing for loop is a classic.

  • scragar (unregistered) in reply to LCrawford

    There's a typo, the reference to IsLeapYeaarDate only shows up in the comment at the bottom, and not in the sample code. It should be IsLeapYearDate.

  • 04012018 (unregistered)

    One nice thing about javascript is the prevalence of closures. You can just put in some date library, and then write code on top of that to blue/green the entire thing in runtime.

    In fact, that's really how quantum physics apply to modern electronics. Theoretical physicists use the prevalence of modern electronics to preserve the status quo, AKA send money and let us hump each other all day, while the very nature of P and N Type Semiconductors is uncertainty alone.

    If I turn on and off the faucet a thousand times a second, I would fill up the same bowl if I turned the faucet on and off a million times a second. That way, I can drop on/off events via a new calculable phenomenon of signal integrity which I can push to zero.

    That Joel guy said learn C so you worry about the bytes of string manipulations. Well if we are going to do that, I want to see him use Feynman to create an infinite amount of chemical elements, you pinko bums.

    Call off the SA Goons now or face a Tsunami of head hunters from Borneo who can keep your head alive in a jar forever. Yes. That's a real thing. You want a cure Bill and Sergey? Pretty soon, you're going to have one, no matter what.

    PS: Zuck has three choices: Start dressing and acting like an Adult Put on a #MAGA hat at his Senate Testimony Break down crying like that writer from the Sopranos after he was squeezed

    You know, all I really wanted was $2,000 a month? That's Walmart wages. I'm willing to cut a deal, whenever.

    https://www.facebook.com/steve.hartken.31/posts/131716387671945

  • audiodill (unregistered) in reply to Hans

    Dividing by 4 would cause a y2k type of break for this instance at least because leap years don't happen at the beginning of the century except for a cycle of every 400 years. The year 2000 was the first beginning of a century that had a leap year since the year 1600

  • sd (unregistered)

    This is just a guess, but the original offender might have had an extensive assembler background. We did things like that back in the mists of time. Still, I have to give credit for the convoluted logic. Had to pull out my big chief tablet and crayon to figure out what the heck it was doing.

  • tbo (unregistered) in reply to someone

    Well, given the only sane format is YYYY-MM-DD, at least the U.S. has the MM-DD order correct.

    If you're going to argue that it makes sense to go from smallest to largest, well, I'll buy you a cup of coffee for 59.2$.

  • whoopie_doopie_do (unregistered) in reply to 04012018

    Hey 04012018 , how is it that you can write a meaningful sentence followed by complete nonsense? I mean, I see ideas in there, but something obviously short-circuited in your brain.

  • whoopie_doopie_do (unregistered) in reply to tbo

    Well, given the only sane format is YYYY-MM-DD, at least the rest of the world apart from the US has the elements in an order that makes sense (DD/MM/YYYY). The US version of MM/DD/YYYY makes no sense. And please, I'd love you to pay $59 for a cup of coffee for me.

  • Bubba (unregistered) in reply to 04012018

    Are you having a stroke? Are you suffering from the long-term after-effects of having a stroke?

  • Barry Margolin (google)

    The US format is obviously just a numerical form of the way we write and say dates in long form: April 4, 2018 has the components in the order Month Day Year. When writing conventions like this came about, they can hardly have anticipated that they would be problematic for computers.

  • ooOOooGa (unregistered) in reply to DQ

    Indeed. Why are there two loop control variables? That is just asking for an infinite for loop. Which is quite an impressive feat to accomplish accidentally.

    The only reason that I can think of for that is to be able to accommodate different amounts of months in a year without changing the code logic. And if that isn't premature optimization, then I don't understand the meaning of the term well enough.

  • castlerobber (unregistered)

    This is the same kind of date-handling I inherited from the highly-paid consultants who converted my employer's programs from COBOL on an HP 3000, to RPG III on a brand-new IBM AS/400, in 1989:

     C           DTECHK    BEGSR
     C                     MOVEL'Y'       GOOD
     C           @MO       IFLT 1
     C           @MO       ORGT 12
     C                     MOVEL'N'       GOOD
     C                     ELSE
      * GET LAST DAY OF MONTH
     C                     Z-ADDMTH,@MO   LAST
      * IF FEB. AND LEAP YEAR THEN Z-ADD29 TO LAST DAY OF MONTH
     C           @MO       IFEQ 2
     C           @YEAR     DIV  4         XX
     C                     MVR            TEST
     C           TEST      IFEQ 0
     C                     Z-ADD29        LAST
     C                     ENDIF                           TEST=0
     C                     ENDIF                           @MO=2
      *
     C           @DAY      IFLT 1
     C           @DAY      ORGT LAST
     C                     MOVEL'N'       GOOD
     C                     ENDIF                           @DAY<1 >LAST
     C                     ENDIF                           @MO<1 & >12
     C                     ENDSR
    

    ** F M A M J J A S O N D DAYS IN EACH MONTH 312831303130313130313031

  • Mason Wheeler (unregistered)

    The code in question happened to be so old that “this is server side JavaScript” was a horrifying novelty when they wrote it, instead of a standard deployment option via Node.

    Don't kid yourself. The lack of novelty doesn't make Node any less horrifying.

  • castlerobber (unregistered)

    Also from those highly-paid consultants...

    The files and COBOL programs on the HP had been designed using YYYYMMDD dates, but the consultants STRIPPED OFF THE CENTURY, against the end-users' wishes, when they converted for the AS/400...which makes the part about adjusting for the 21st century kind of ironic. I was hired near the end of the project, as my employer's first in-house programmer/operator and PC tech, and didn't find out until years later about the shortening of the dates. Would have loved to bill the consultants for that part of our Y2K project, but of course they were long out of business by then.

      * PER REQUEST 3/8/90 NO LONGER TAKE INTO ACCOUNT LEAP YEARS
     C           CALDAY    BEGSR
      * NEW METHOD THAT DOES NOT COUNT LEAP YEARS
     C           @YEAR     MULT 365       DYOFCN
     C                     ADD  ELPS,@MO  DYOFCN
     C                     ADD  @DAY      DYOFCN
      * ADJUST FOR 21ST CENTURY
     C           @YEAR     IFLT 50
     C                     ADD  36525     DYOFCN
     C                     END
     C                     ENDSR
    
    • NUMBER DAYS ELAPSED AT START MO
    • 000 000 JAN
    • 031 031
    • 059 060
    • 090 091
    • 120 121
    • 151 152
    • 181 182
    • 212 213
    • 243 244
    • 273 274
    • 304 305
    • 334 335
    • 365 366 JAN
  • Ducky (unregistered) in reply to bvs23bkv33

    Nope. It's a while loop masquerading as a for loop, mainly so we don't have to add a line to increment "i" somewhere else.

    The code is trying to get the total number of days between a starting month and an ending month that's up to 12 months later. Expected input:

    intMonth, which should be the starting month. intMonthsToDisplay, which should be a number <= 12.

    Expected output: arrNoDaysInMonth - an array of the number of days for the range of months we're displaying. intTotalDays -- Total number of days. (Hopefully initialized to 0 before entering this block.)

    Main issue with the code: If the person knew enough to know how to return a numeric array, why did he or she decide to use a string for the lookup table?

  • Vicki (unregistered)

    Isn't the first line of the mnemonic "Thirty days hath September"? You can't just change it to "November" without prior authorisation! Soon some idiot will take that as licence to try it with "December" and then where will we be? Human sacrifice, dogs and cats living together, mass hysteria; that's where!

  • Randal L. Schwartz (google)

    MM/DD/YYYY makes sense when you realize it's the numeric translation of "April 1st, 2018" so it needs to be "4/1/2018". I guess DD/MM/YYYY is ok if you always say "1st of April, 2018". But I don't know anyone who consistently does that in the English-speaking world.

  • Sole Purpose of Visit (unregistered) in reply to Barry Margolin

    Which is sort of why you store date information in a logical form, understood by computers, and then use the magic of these things we call "computer languages" to mutate that well-known value into a form understood by the client/user in the first place.

    The great thing about this is, you only need one logical form of storage. And you can internationalize the presentation to the user in any way that is appropriate!

    I'm sorry, I think I understood what your point was, but after thirty seconds, that point completely eludes me.

  • evnafets (unregistered)

    I applaud how they tried to handle leap years (emphasis on tried) But the 24 month thing then puts them wrong. If the current year is a leap year, next year won't be. But in the leap year string, both "Februarys" have 29 days. Both Februarys in the non leap year string have 28 - which will fail if next year is a leap year...

    Dates and off by one errors are hard...

  • someone (unregistered) in reply to Randal L. Schwartz

    Because if you don't know of such people, then logically they don't exist.

    I'm pretty sure only US people say Month day. Everyone I speak to (who don't live in the US) say day of month.

  • HK-47 (unregistered)

    US people are gay For saying month Then day...

  • RichP (unregistered)

    IsLeapYearDate must include a line like: strLeapYears = "00010001000100010001000100010001";

  • 04012018 (unregistered)

    https://bit.ly/2GBcEnd

  • eric bloedow (unregistered)

    reminds me of an older story, someone tried to write a date validation program, but the "valid month" value was "janfebmaraprmayjunjulaugsepoctnovdec", which meant that "anf" would pass the test...

  • Jim T (unregistered)

    Pssh. That's got a lot of useless duplication. It really should be:

        strDaysInMonths = "312831303130313130313031312831303130313130313031";
    
        if (IsLeapYearDate(intMonth+i+1 +"/1/" + intYear) )  
        {
          strDaysInMonths = strDaysInMonth.replace(/8/, '9');
        }
    

    See! Look at that concise, easy to read and update code. And it's even got a regular expression in it now, so it's double good. :-)

  • Gerry (unregistered) in reply to Randal L. Schwartz

    "But I don't know anyone who consistently does that in the English-speaking world."

    I suppose it depends on what part of the English speaking world you live in, and will give you a pass as you said consistently, but I would nearly always say "The fifth of April" not April the Fifth, as would most other Kiwis.

    Mind you it is always "May the Fourth" (be with you)

  • Stephen (unregistered) in reply to eric bloedow

    Didn't they know that you need to use "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec" instead? Then of course you have to ensure there are no pipes allowed in the input, but that's a UI issue, so not my problem.

  • bobcat (unregistered) in reply to eric bloedow

    Stupid Smarch weather...

  • Drak (unregistered)

    I would personally implement IsLeapYearDate as

    function isLeapYear(year) { return new Date(year, 1, 29).getTime() != new Date(year, 2, 1).getTime(); // javascript months start at 0 for some reason }

  • DQ (unregistered) in reply to Gerry

    But it's always the 4th of July Never knew about an american celebrating July the 4th

  • (nodebb)

    Of course, TRWTF is calling IsLeapYearDate and assigning strDaysInMonths within the loop. It's a redundant waste of CPU cycles. Nowhere does the code in the loop change intYear.

  • eric bloedow (unregistered)

    most people simply say "it's 4 o'clock", some pretentious people (mostly British) would say, "it's 4 of the clock", but ONCE i read a book where a REALLY pretentious person said, "it's 4 of the o'clock."

  • airdrik (unregistered) in reply to evnafets

    Actually the leap year check has a decent chance of handling of the next year's leap-yearedness correctly. We don't know but that calling isLeapYearDate with e.g. "14/1/2019" may in fact return true (or something similarly truthful) resulting in the correct string being selected for the next year.

    However, even if that were the case, the rest of the code only works for months within the same year. If invoked with intMonth+intMonthsToDisplay > 12 then it'll end up doing a substring past the end of the string and fill in empty months beyond December of intYear.

  • X (unregistered)

    Bit like everyone speaks of the July 4th party instead of 4th of July.

  • Ulysses (unregistered)

    Server/desktop JavaScript is still a horror and gag inducer.

  • RandomSaneGuy (unregistered) in reply to Barry Margolin

    That's why we say "4th of April, 2018" here. It's sane and results in d/m/y order.

    Alternatively, I will accept ISO standard dates, enforced at gunpoint, as long as it's for everybody.

  • RandomSaneGuy (unregistered) in reply to Barry Margolin

    "When writing conventions like this came about, they can hardly have anticipated that they would be problematic for computers."

    While getting excited about the Amero-centric "I've never seen this so it doesn't happen" claim, I missed the important bit: It's not a problem for computers, it's a problem for me and every other human who doesn't use this b0rked format. If I see a date written "11/10/09" I literally can't tell if it's 2009 or 2011, October or November. And if you use something like Skype, you get Microsoft saying they use the "standard" date format, when what they mean is they didn't give a rats about the standards and instead used what somebody in their office felt like using (i.e. USA format).

    That's why this matters. It affects people who try to extract information from what you present. When you use USA format, that information is corrupted. Please stop.

  • BernieTheBernie (unregistered) in reply to RichP

    You're right. And likely even longer, 8000 something characters (or at least some 400 plus, if they omitted the centuries). Your comment deserves to be featured (oh, wtf, where can I recommend a "featured comment"?)

  • Axel (unregistered) in reply to RandomSaneGuy

    No.

  • someone (unregistered) in reply to Axel

    "No"? What a well-thought-out rebuttal.

    I don't see any faults with RandomSaneGuy's comment, apart from not being able to tell the year.

    Care to explain what you find disagreeable?

  • RandomSaneGuy (unregistered) in reply to someone

    "I don't see any faults with RandomSaneGuy's comment..."

    That's the nicest thing anyone has ever said to me on the Intertron. :-)

    "...apart from not being able to tell the year."

    yy/mm/dd turns up from time to time. Japanese do this routinely, apparently, but I've seen it in other places (worked out by context in a sequence of funny looking dates). It really ruins date stamps when people omit the century.

    So, we have people using d/m/y and m/d/y and y/m/d with all variants of 2 and 4 digit y. And that's just within ONE calendar system! Madness.

    Again, I appeal to anyone in control of anything date related: ISO dates or sabotage the project so it never sees the light of day. Either will suffice. Thank you.

  • bob (unregistered) in reply to Randal L. Schwartz

    Literally everyone in Britain says it as DD-MM-YYYY.

  • bob (unregistered) in reply to eric bloedow

    Never heard anyone say "4 of the clock" in 50 years of living in Britain.

Leave a comment on “30 Days”

Log In or post as a guest

Replying to comment #:

« Return to Article