• ray10k (unregistered)

    And of course, badly implemented date/time mangling is at the core of the issue. obligatory("Gee, I wish there were a better way to do this");

  • Tree (unregistered)

    Oof, until "CTO" I was afraid I knew this project.

  • Dlareg (unregistered)

    Yes this is a very minimal bug. Only affecting the first day of the month (so it triggers 12 out of 365 days) and when it does it still provides valid output (e.g. the date of yesterday). I do not think anybody notices this. So it is a very minor bug. Also it is easy to solve with an if or two where you check if day-TODAY < 1. and then check if month -TOMONTH <0.

  • Athanasius (unregistered)

    @Dlareg - and "year - TOYEAR < 0" for the Dec 31st > Jan 1st rollover.

  • scragar (unregistered) in reply to Dlareg

    Would it not make more sense to get the date for yesterday using a date object rather than maths, no point overcomplicating this stuff.

    Date.prototype.isSameDate = function(input_datetime){
        return input_datetime.getDate() === this.getDate() &&
               input_datetime.getMonth() === this.getMonth() &&
               input_datetime.getFullyear() === this.getFullyear();
    }
    
    
    const yesterday = new Date();
    yesterday.setDate(yesterday.getDate() - 1); // Works even on Jan first because setDate(0) automatically corrects that stuff to avoid invalid datetimes
    
    if (originalTimestampDate.isSameDay(yesterday)) {
        dateAbbreviation = 'yesterday at ';
    }
    
  • Chronomium (unregistered)

    People with a job title like "C*O" should not have permissions to alter code.

  • Time Leap (unregistered)

    Assume you are on 1st march. What about february 28 then?, is it yesterday or not? It depends if the year is a leap year and had 29 days or not. This formula is well known. But what if February 30 existed? You never know if they will insert a leap day again as it already happened in the past in Sweden and Soviet Union. Are you going to to rewrite your homebrewn date-arithmetic then? I don't think so. But if you would use the alredy existing calendar-methods to tell you if it was yesterday or not, then you are on the safe site. For sure then there will be a calendar-library-update available for your language, and you don't need to touch your own software.

  • 3090 (unregistered)

    I'm a little confused. I thought C.T.O. stood for Chief Technology Officer. You then state "...CTO just took matters into their own hands .... As the CTO, they bypassed ..." Did you mean Chief Technology Office? Why did you use plural pronouns?

  • Eric Gregory (github)

    TRWTF is the unit test doesn't have the whatever Javascript function returns today's date mocked out. There's no excuse for letting this cause unit tests failures when it's "that time of the month."

  • (nodebb)

    Certainly agree.

    Unfortunately, that rule doesn't work well when the CEO/President of the company was the one who started the company in his 'garage' by writing the original code and is still the "expert" on PostScript filters (that no one else wanted to touch). Also unfortunate is that the CEO wrote methods hundreds of lines long, and in Pascal sub-classes/methods inside others many levels deep, resulting in classes with 25KLOC+

    Career tip; do not critique/complain about said code while the founder of the company is still the CEO/President - even if he is not in the room; it will get back to him. DAMHIK.

    Better career tip; when considering a position, learn about the history of the codebase, who has worked on it, who can work on it and so on. This will save you a LOT of grief (if you can afford to turn down the position).

  • NevemTeve (unregistered)

    Well, it couldn't be solved "quite easily" (if you want a complete solution), it requires a date-handling library (a timestamp-handling library will not do, just think of the dreaded Daylight Saving Time, and its turning days).

  • (nodebb)

    I heard that it was once said that there are three hard things in programming:

    1. Naming.

    2. Cache invalidation.

    3. Dates.

    4. Off by one errors.

  • Tim! (unregistered) in reply to herby

    I heard that twice.

  • (nodebb) in reply to herby

    The only one of those problems this thing doesn't have is #2.

  • Marine Core Todd (unregistered) in reply to Eric Gregory

    Came in here to say this

  • someone (unregistered) in reply to Dlareg

    This is exactly why you should only "roll your own" if you know exactly what you're doing. You've neglected what happens on the first of January; just like the original author neglected the first of each month, you've failed to account for the first of each year.

  • (nodebb)

    TRWTF is Angular.

  • someone (unregistered) in reply to tahir_ahmadov

    I've said it before but it bears repeating: TRWTF is modern JavaScript development as a whole.

  • (nodebb)

    I'd expect the someday when this gets fixed to be the first of the following month; because on that day with the build broken it's suddenly a major problem for the dev team; and fixing it would surely take less time than having all the devs on standstill for a day.

  • SMon (unregistered)

    It might get fixed, someday

    Yep... on the zeroth day... it will. there's no yesterday :)

  • ☃☃☃ anonymous snowman ☃☃☃ (unregistered)

    The fix, when committed, will undoubtedly check for TODAY_DAY <= 0 and if so, check for month === TODAY_MONTH - 1.

    Congratulations, as of new years, it's a critical bug!

  • JG (unregistered) in reply to ☃☃☃ anonymous snowman ☃☃☃

    That's all right, no one is in the office on New Years Day, so no one will notice :-)

  • DrPepper (unregistered)

    When "the test fails only on the first day of the month" then you know the tests are broken. It should not matter when the test is written; the test should be written in such a way as to provide to the method under test a date object, which the method under test uses to produce the output.

  • ☃☃☃ anonymous snowman ☃☃☃ (unregistered) in reply to JG

    Except for all the remainder of January!

  • (nodebb)

    ... and that's the reason why you test edge cases! Now run along kids!

  • (nodebb) in reply to Developer_Dude

    I've never found interviews to be particularly enlightening on details like that. I like to ask for a copy of their code "standards" because that's what frightened developers often use against perceived threats. Rarely is that very simple request indulged. That's counter-productive if you really think about it. Wouldn't it be great to know if the interviewee was inclined to follow them before hiring them? What does it profit you to lure somebody in that isn't going to comply with your poor practices? Because without fail, these positions I've accepted that have subsequently devolved into fights over bracket placement or local variable names have had absolutely nothing special going on. Why would I want to work somewhere that there was nothing to learn because small minds that had missed a hundred deadlines were suddenly fixated on "Sql" vs "SQL" in fucking comments?

  • Guest (unregistered)

    TRWTF is that if you keep the page open for several days all of those "today"s and "yesterday"s will be wrong.

  • (nodebb) in reply to Chronomium

    But it was a CTO, a Code Tweaking Officer. ;-)

  • (nodebb) in reply to 3090

    English doesn't have gender-neutral third person singular pronouns. Traditionally you would have to assume that a given person is male, but some people prefer to use the plural pronouns instead.

  • MaxArt (unregistered) in reply to Time Leap

    Nope. In JavaScript you can pretty much subtract one day from a Date object, with just date.setDate(date.getDate() - 1). It won't throw if it's the first day of the month, leaving the OS figuring out all the quirks about timezones, DST, leap years and seconds, and such.

Leave a comment on “The UI Annoyance”

Log In or post as a guest

Replying to comment #:

« Return to Article