• Little Bobby Tables (unregistered)

    Aha, I get it. This is TRWTF:

    //Type appropriate comment here, and begin script below

    The HPC has used a code template and not filled in the comments.

  • JohnSmith (unregistered)

    You mean getUTCDay()?

  • my name is missing (unregistered)

    Too bad they didn't issue the check using this kind of math.

  • (nodebb)

    thirthieth

    Um. What?

  • (nodebb)

    "if (currentDate > selectedDate)"

    And at that point he noticed currentDate wasn't properly initiated?

  • (nodebb)

    So corporate, this whole story. Service Now, highly paid consultants, full time programmers not fixing the bugs properly. Thr only missing part is some slacking HR personnel constantly getting coffee.

  • JS Coder (unregistered) in reply to JohnSmith

    getUTCDay() returns day of the week. getUTCDate() returns day of the month. Big difference.

  • (nodebb)

    Isn't it commonplace that your "Highly Paid Consultant" is probably someone from India who took a boot camp (if you're lucky) and then bullshitted their way into a consulting company?

  • Terry C (unregistered)

    I think you meant 05-JUN-2018 not 2019, otherwise his terrible comparison would've been unusually correct.

  • Karsten Bock (github) in reply to JS Coder

    So, getUTCDate() returns the utc day of the month, not the complete date? While that is what I suspected - and explains the WTF - it still is confusing.

  • ray10k (unregistered) in reply to Steve_The_Cynic

    30th, except written out.

  • Little Bobby Tables (unregistered) in reply to ray10k

    You mean:

    "30th, excepth writthen outh."

  • Hartmut Holzgraefe (unregistered)

    Looks to me as if they confused JavaScript getUTCDate() with tSQL getUTCDate().

    The later returns a sortable string starting with 'YYYY-MM-DD' for which the comparison would have worked out fine, while the former confusingly actually returns a day number, not a date.

    So IMHO we have two WTFs here: confusing JavaScript naming, and a lack of testing ...

  • (nodebb) in reply to Mr. TA

    I've started referring to it as ServiceHow.

  • Dlareg (unregistered) in reply to DocMonster

    If you are lucky. We once had an HPC who was litteraly an intern. He was in his second year of university. The Firm told that he was more or less a puppet that they were monitoring him closely. FFWD a few months and the handler (the guy from the Firm) came to me to ask me if I could grade the intern and his report. Since I was the guy who had been working closesed with him.

    I did grade the guy and went to his defense. But I also told the story to our CFO. She was not amused. As I understood she took their bill and crossed out all the hours (at euro 150 each) of the intern and placed the hours I had spent on the guy there for 400. Her story if an intern is worth 150 a medior (who the hell invented that term) should do at least 400.

    Shit hit the fan, there was a settlement and I got a very nice bonus.

  • Dlareg (unregistered) in reply to DocMonster

    If you are lucky. We once had an HPC who was litteraly an intern. He was in his second year of university. The Firm told that he was more or less a puppet that they were monitoring him closely. FFWD a few months and the handler (the guy from the Firm) came to me to ask me if I could grade the intern and his report. Since I was the guy who had been working closesed with him.

    I did grade the guy and went to his defense. But I also told the story to our CFO. She was not amused. As I understood she took their bill and crossed out all the hours (at euro 150 each) of the intern and placed the hours I had spent on the guy there for 400. Her story if an intern is worth 150 a medior (who the hell invented that term) should do at least 400.

    Shit hit the fan, there was a settlement and I got a very nice bonus.

  • Brian Boorman (google) in reply to mjmilan1

    Was currentDate initialized or not? Hmm. Let's try RTFM'ing this and find out:

    •If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings for timezone offset.
  • richarson (unregistered) in reply to Little Bobby Tables

    The HPC probably scheduled filling in the comments for a later date, which of course was in the past...

  • snoofle (unregistered)

    I propose a new requirement for our industry...

    Given the propensity for managers to insist on programmers needing to do things in the past (e.g.: I need you to build a 10,000 man-hour project, and I promised that it'll be done in the next 3 days), maybe we should all be issued a Doc Brown DeLorean.

  • Brian Lawry (unregistered) in reply to snoofle

    Codes? Where we're going, we don't need codes!

  • (nodebb)

    How could this code be wrong? It’s just common sense, obviously.

    So.. The code doesn't work because the boolean statements are executed from left to right? right? Feels like a JS-noob, which actually feels like a compliment

  • (nodebb) in reply to Flips

    It wouldn't work if they were evaluated right to left either.

  • (nodebb) in reply to Watson

    Well that was I try to find out.. I feel like a noob-programmer now :(

    But would someone explain? Because it kinda looks like right-to-left-evaluation would work.

  • (nodebb) in reply to Flips

    Hold on that thought for 364 days.

  • Andrew (unregistered) in reply to Karsten Bock

    I absolutely agree. That is not the best name for that function. I will hedge my opinion with this, however, I'm not a JS programmer and had to ask Google for the details about the function. Perhaps it is named thusly for good reason?

    Ironically, as I think about it, had the HPC reversed the order of evaluation, i.e. compare year, month and then day, it may have worked as he'd intended. Matt's solution is more concise, and the preferred method.

  • markm (unregistered)

    Hartmut Holzgraefe: "Looks to me as if they confused JavaScript getUTCDate() with tSQL getUTCDate()."

    No, if the programmer thought it returned the whole date in a sortable format, he would not have used two comparisons. The bigger problem is the failure to recognize that the underlying date format is sortable (I assume it's something like days or seconds since Jan 1 1900 or 00:00:00 Jan 1 1970). Also, he got the logic wrong and he forgot to check the year, so orders entered in late December would fail even if the day and month logic had been correct.

    If you must use a date broken out into it's parts, use this pattern for selected date < current date:

    if(!(current.year<=selected.year && current.month<=selected.month && current.day<=selected.day))

  • James (unregistered)

    This also fails, e.g., current = 01-FEB-2017 selected = 01-JAN-2018. The problem is the year dominates the month comparison and also the year and month dominate the day comparison. So what you're really looking for is: if(!(current.year <= selected.year && (current.year < selected.year || current.month <= selected.month) && (current.year < selected.year || current.month < selected.month || current.day <= selected.day))) or more simply: If you must use a date broken out into its parts, find another job.

  • James (unregistered) in reply to markm

    This also fails, e.g., current = 01-FEB-2017 selected = 01-JAN-2018. The problem is the year dominates the month comparison and also the year and month dominate the day comparison. So what you're really looking for is: if(!(current.year <= selected.year && (current.year < selected.year || current.month <= selected.month) && (current.year < selected.year || current.month < selected.month || current.day <= selected.day))) or more simply: If you must use a date broken out into its parts, find another job.

  • Jimmy (unregistered) in reply to Andrew

    Various "fixes" above don't work, so don't do that at home.

    current = 2000/02/01, selected = 2001/01/01

    • Reversing order: in short, || is commutative, so it does not matter. [ 2000 > 2001 (false) || 02 > 01 (true) || ... ] -> true

    !(!a && !b && !c) == a || b || c, so this is exactly like the above: ![ 2000 <= 2001 (true) && 02 <= 01 (false) && ...] -> !false -> true

  • JSDev (unregistered)

    Step 1: laugh at HPC for screwing up a simple datetime comparison. Step 2: fill comment thread with BS assumptions (which could have been corrected had you bothered to open the browser console and test it out) and poor attempts at "fixing" the bug. Step 3: feel superior to HPC.

  • Dates are not the only fruit (unregistered) in reply to JS Coder

    //getUTCDate() returns day of the month.//

    The true WTF.

  • (nodebb) in reply to markm

    If you must use a date that's already been split into parts, then (current.year * 10000 + current.month * 100 + current.day > selected.year * 10000 + selected.month * 100 + selected.day) is at least going to give an accurate result, assuming a large enough default integer type.

  • SomeDude (unregistered)

    I literally came across this exact same bug at one of my prior employers. It was also written by an HPC. What are the chances it was the same one?

  • (nodebb) in reply to markm

    If you must use a date broken out into it's parts, use this pattern for selected date < current date: if(!(current.year<=selected.year && current.month<=selected.month && current.day<=selected.day))

    No, don't do that unless you enjoy failure. Consider for example current date 6 Feb 2019, selected date 5 May 2020: current.day is greater than selected.day, so your condition returns true even though the selected date is greater than the current date.

    The correct comparison by parts is: Are the years different? If so then the earlier year represents the earlier date. Otherwise, are the months different? If so then the earlier month represents the earlier date. Otherwise, compare the days and the result is the result for the whole comparison.

    Or, for selected date < current date: (selected.year < current.year) || (selected.year = current.year && selected.month < current.month) || (selected.year = current.year && selected.month = current.month || selected.day < current.day)

    or if you like ternaries: selected.year < current.year? 1 : selected.year > current.year? 0 : selected.month < current.month? 1 : selected.month > current.month? 0 : selected.day < current.day

    But really, it's less confusing to do year * 10000 + month * 100 + day to get both dates as numbers in YYYYMMDD format and just see if one number is greater than the other.

    (Of course, using the date class's inbuilt comparison is the best way of all if you start with a date object.)

  • notroot (unregistered) in reply to Steve_The_Cynic

    Typo, an extra h.

  • notroot (unregistered) in reply to Flips

    They are comparing each part of the date which returns true only if all the comparisons are true. That's not how you compare dates. You figure out the date/timestamp/whatever and compare those.

Leave a comment on “A Date with a Consultant”

Log In or post as a guest

Replying to comment #502939:

« Return to Article