- 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
What a great idea to consistently name all method parameters "in".
Admin
Devan L. forgot that today is WTFday.
Admin
While I appreciate the usefulness of calendars and agendas considering Sunday the first day of the week, I would probably tell my daughter Monday is the first day of the week (followed by Frogday obviously).
Admin
// Not sure if this comment is visible in leap years
Admin
The real WTF is a week starting with Sunday.
Admin
The real WTF is that he could use only one method:
public Date getDateInWeek(Date in, int desiredDay) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(in); return new Date(in.getTime() + (desiredDay - gc.get(Calendar.DAY_OF_WEEK))243600*1000); }
Admin
TRWTF is that Calendar.add() actual does roll over month boundaries correctly. This is of course as long as you want to stay in the same week rather than in the same month, which seems to be the intent of this code.
Admin
I don't get it - why has the original developer been worried that only his getTuesdayInWeek() method might not work in leap years? Is there a special leapyear rule involving tuesdays I haven't heard of yet?
I only know the classic one: yes if %4 == 0 unless %100 also == 0 with the exception that %400 is also yes. Oh, and 0 == file_not_found, obviously.
Admin
The first day of the week is different in different locales.
Admin
Admin
Quite convenient! For Frogdays, just need to add by copy-pasting:
And add the correspondent value to the switch entry:EDIT: Oops! I made a copy-paste mistake on the case statement. WTF!
Admin
Judging from the name of the last method (getReleaseDateInWeek) I'd say the code was tested only for Tuesday/Frogday.
Admin
TRWTF is using new GregorianCalendar(): it is explicitely discuraged in the docs since I can remember (you have to do Calendar.getInstance()); or at least since 1.3, that is more than a decade ago.
And if you're worried about locales, creating a GregorianCalendar is the wrong thing to do anyway.
Admin
TRWTF is using Java's Calendars, Dates, etc. Use JodaTime and pray for this to make sense in Java8
Admin
That might be because it's the only method used.
Admin
Admin
Why is it that date handling code, which is notoriously easy to screw up, is such a favourite target for reinvention by beginner programmers?
Admin
It's because dates seem so easy to the poor souls new to programming... I'd say one should be forced to write a date handler lib during once schooling, since it's a fairly good example of that which one takes for granted as simple in normal life gets seriously fucked up when you try to write code for it.
Admin
I like how the guy was only not sure about Tuesdays working on leap years.
And it's not like you can't run a program with a bunch of loops to actually, you know, TEST shit like this?
Where I work now, some date-related code was trying to interface with the C libraries that came with IAR. The guy who preceded me thought he had figured it out with some DST code. Oops, he didn't! I ran a test and found out that about half of the years had it wrong, including the upcoming year.
This also revealed the correct (or "a" correct) way to set the DST dates. I'll just say that the DST calculations very WTF-ey and very undocumented and that the library source had P.J. Plauger's name all over it. I was able to google a Dr. Dobb's article related to the library code, but it didn't tell how the DST parameters worked either.
Admin
Someone should design an entire 400-level CS course in which students screw up seemingly simple implementations like this, then do it again correctly using existing libraries.
Admin
I actually think "wise" fools are the greatest danger we face. An honest to goodness moron doesn't do any harm. No-one's going to give them a programming job in the first place. But an educated idiot who outwardly probably seems quite intelligent, maybe has some supposed mathematical aptitude, can be entrusted to produce this abomination. And people will notice it doesn't work quite right, shrug their shoulders, and ignore it.
Admin
Admin
Alex, that is your next project after BuildMaster -- the Daily WTF IT Business Case Library.
Admin
Say what you wish about this code, but I'm glad that the president's daughter is feeling well. At least she is conscious and when told a joke, she laughs.
Admin
Admin
Admin
Why?
In Christian, Islamic and Jewish tradition, Sunday is the first day of the week.
Most Western countries (and many others) are based on one of the above traditions, so Sunday is generally the first day of the week.
Languages like Portuguese, Greek, Vietnamese and others essentially call Monday 'day two' or 'second day' (eg "segunda-feira" for Monday in Portuguese), meaning Sunday would be 'Day one'
Admin
The "getDateInWeek()" function is another WTF. Why use an int for the argument and then have to put an unnecessary default action in the case statement?
The argument should have been of type Calendar enum (or whatever) which means it would automatically fit the case statements.
Yeah, yeah, I know, if they ever decide to make weeks have more than seven days or give them other names... who cares? If that ever happens, almost all code ever written will have much bigger problems.
Admin
Quick web search finds this:
So ISO and USA disagree. They also disagree on week numbers - by definition, a week belongs to a given year if four or more days of the week fall into the year; because of the different definition of the first day, if a year starts with a thursday then according to ISO, Dec. 29th to Jan. 4th (monday to sunday) are the first week of the next year, while according to USA rules, Dec. 28th to Jan3rd (sunday to saturday) are the last week of the previous week, and the first week starts Jan. 4th.Admin
[quote user="pscs"][quote user="olaf"]In Christian, Islamic and Jewish tradition, Sunday is the first day of the week.[/quote] God created the universe in six days, and the seventh day was a day of rest. Sunday = seventh day in Christian tradition. And think about the word "weekend".
Admin
If leap day falls on a Tuesday in a year not divisible by 4, then it's only 23 hours long instead of the usual 24.
Admin
How dull!
Admin
I never could get the hang of Tuesdays.
Admin
MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY
Admin
Okay, let's think about it... Saturday and Sunday are generally considered "the weekend". But like a line segment, a week has two endpoints. The final day of the week is one end, and the initial day is the other end. Therefore, Saturday and Sunday must be the final and initial days of the week. Quod erat demonstrandum.
Admin
Admin
I'm waiting for that distinction to attribute any meaning to life.
...
Nope. Still don't get it.
Admin
Admin
ZOMG. What does the start of the week attribute to anything if a month can start on any day?
What is it?
Billing cycles - Who cares if I get paid on Wednesday or Friday.
The start of the workweek - Do the non-salary even care? When I was non-salary I wouldn't know what day it was if it weren't for church.
Public holidays - I think the "day" ones start on a specific day, not a number from the start of the week.
As long as days have names, it doesn't matter.
Admin
No. God rested on the seventh day of the week. That was the Sabbath. The 'Sabbath' is Saturday. If you know any Jews, ask them...
In Christianity, Sunday is 'The Lord's Day' - it is celebrated because that's when Jesus rose from the dead - which was the FIRST day of the week (Easter Sunday).
Mark 16:2 - "2 Very early on the first day of the week, they were on their way to the tomb. It was just after sunrise. 3 They asked each other, “Who will roll the stone away from the entrance to the tomb?”"
(PS the word "Weekend" is OK, because it has two days, one at each END of the WEEK ;-) )
(Also, again in Portuguese - Saturday is 'sabado' (Sabbath), Sunday is 'domingo' (from Lord's day) )
Admin
[quote user="gnasher729"][quote user="pscs"][quote user="olaf"]In Christian, Islamic and Jewish tradition, Sunday is the first day of the week.[/quote] God created the universe in six days, and the seventh day was a day of rest. Sunday = seventh day in Christian tradition. And think about the word "weekend". [/quote]
Actually even that's wrong.
Sunday was still the first day. The seventh day of rest was Saturday. The early church (Paul's church) switched to worship on Sunday for two reasons.
Admin
Admin
FRIDAY FRIDAY FRIDAY FRIDAY FRIDAY I'm waiting for the Weeeeeekend!
Admin
You are wrong!
Your honest moron found a job for the government.
Admin
sorry it didnt quote previously
You are wrong!
Your honest moron found a job for the government.
Admin
Admin
Admin
The existing methodology can also be really intimidating. Just look at Java dates >_<
Admin
No thank you
Admin