• P (unregistered)

    I found it more confusing that I can't determine which field is month and which is day from a glance than the WTF itself, which is immediately obvious.

  • LCrawford (unregistered)

    $fristChar was missing - that's the biggest problem.

  • Shannon (unregistered)

    The real WTF is putting the least significant digits between more significant digits.

  • (nodebb)

    trwtf is not using ISO 8601 and using yyyymmdd or similar. I've seen enough confusion about whether 7/1 means 1st July or 7th Jan

    Addendum 2019-11-19 06:57: (Remy please note)

  • (nodebb)

    I hate to say this but PHP is the least of his problems.

  • Little Bobby Tables (unregistered)

    The funniest bit is where it carefully checks that the second character is a forward slash, and if not, then it carefully checks whether the second character is not a foward slash. Just in case the Law of the Excluded Middle does not hold in this context.

    Suppose "date" may have changed in between, maybe.

  • ooOOooGa (unregistered) in reply to Little Bobby Tables

    Even if $date did somehow manage to change (considering it is a parameter passed by value...), $secondChar wouldn't.

  • tbo (unregistered) in reply to Shannon

    The real wtf is complaining about mm/dd/yyyy when you use dd/mm/yyyy on a programming website where yyyy-mm-dd is the only acceptable answer.

  • ooOOooGa (unregistered)

    I saw something similar to this once. There was an external component that our program was interacting with. That program had a non-standard version string format that included letters and variable width fields. Instead of using a regular expression to parse it, the previous developer had decided to create a function that did character extraction to test whether the version string was equal to or later than a particular version of interest.

    Then they had to create another similar function for a different version of interest.

    Then another.

    And another.

    When I got there, there were about seven or eight of these 'isVersionXXOrLater' functions. All doing character extraction and testing to determine the version attributes. Sometimes doing it wrong.

  • James (unregistered) in reply to Little Bobby Tables

    He's a constructivist.

  • Little Bobby Tables (unregistered) in reply to James

    He is indeed. That was the term I was hunting for. Thnx. Brouwer would be proud.

  • sizer99 (google)

    I've seen code that uses a gigantic switch statement to do this for months and then days of the month. Splits on / (wrooong) and then switch (monthStr) { case "1": case "2": ... case "9": monthStr = "0" + monthStr; break; case "10": case "11": ... case "31": monthStr = monthStr; break; }. The best I can say is that at least they combined the cases instead of replicating "0" + for every one.

  • Decius (unregistered)

    This is the kind of problem you end up with when programmers have trouble getting a date.

  • Shannon (unregistered) in reply to tbo

    Why do you think I use dd/mm/yyyy ?

  • (nodebb)

    TRWTF: "but since there had just been a massive refactoring project, nobody want to make any code changes which weren’t new features."

    Refactoring should be part of DAILY work not a "massive project".... Remember Red, Green, REFACTOR.

  • Phil's Shoulder Angel (unregistered)

    This code also has an "off-label" use to return the month abbreviation. For example, convertSingleDigitMonthOrDayToTwoDigitMonthOrDay("January 1st") returns "Jan". It's a feature and it might be used that way in the code, so you can't change it.

    This function will also return the first 6 characters of a random string, as long as the 3rd char is the only '/'.

  • RJ (unregistered)

    Funniest part is the code is wrong...

  • Mr. Clean Code (unregistered)

    Gotta grudgingly give some points to the function's name, that's a rare occurrence in that kind of mess.

  • Grant (unregistered)

    Sometimes, you want your dates to look like this: 3/3/2019.

    No I don't.

    Other times, you want them to look like this: 03/03/2019.

    No I don't.

Leave a comment on “Never Refuse a Fifth”

Log In or post as a guest

Replying to comment #:

« Return to Article