- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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");
Admin
Oof, until "CTO" I was afraid I knew this project.
Admin
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.
Admin
@Dlareg - and "year - TOYEAR < 0" for the Dec 31st > Jan 1st rollover.
Admin
Would it not make more sense to get the date for yesterday using a date object rather than maths, no point overcomplicating this stuff.
Admin
People with a job title like "C*O" should not have permissions to alter code.
Admin
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.
Admin
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?
Admin
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."
Admin
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).
Admin
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).
Admin
I heard that it was once said that there are three hard things in programming:
Naming.
Cache invalidation.
Dates.
Off by one errors.
Admin
I heard that twice.
Admin
The only one of those problems this thing doesn't have is #2.
Admin
Came in here to say this
Admin
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.
Admin
TRWTF is Angular.
Admin
I've said it before but it bears repeating: TRWTF is modern JavaScript development as a whole.
Admin
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.
Admin
Yep... on the zeroth day... it will. there's no yesterday :)
Admin
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!
Admin
That's all right, no one is in the office on New Years Day, so no one will notice :-)
Admin
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.
Admin
Except for all the remainder of January!
Admin
... and that's the reason why you test edge cases! Now run along kids!
Admin
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?
Admin
TRWTF is that if you keep the page open for several days all of those "today"s and "yesterday"s will be wrong.
Admin
But it was a CTO, a Code Tweaking Officer. ;-)
Admin
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.
Admin
Nope. In JavaScript you can pretty much subtract one day from a
Date
object, with justdate.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.