- 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
The real WTF is hardcoded first day of week. In Russia first day is Monday.
Admin
But...why only 13 days? 14 maybe, there might be some code requiring fortnight processing or something. But 13? Bizarre
Admin
ok so theres only two comments on this right now, WTF? don't think i've ever seen it
Admin
Who could have guessed? We always thought they'd appear in threes or somesuch.
Admin
The real WTF is that there are only 13 entries. And using the same constants twice is a bad idea once the 14-days week had been established this would cause a serious problem. Not mentioning that the days of the week must start from 0.
Here is what I would have written:
Public Function DayOfTheWeek(iDay As Integer) As String 'Mapping of day number to day-of-the-week string.
End Function
Admin
Friday the 13th!
Which coincidentally also happens this week.
Admin
So, ppoplp, instpad of bpllyaching, lpt's hplp Alpx out and submit somp WTF's for him to usp. If wp arp rpading thpm, wp can submit thpm.
(Sorry, pvpry timp I kpy thp lpttpr 'p' I gpt an 'e'.)
Admin
This is not that bad. Someone wanted to be able to add a number (less than 7) to the current day of the week and still know what day of the week it would be. Sure, there are other ways to do that, but really it's just a quick hack. I'm surprised this qualifies.
Admin
It looks like it might be useful if you have, say, today's day-in-week number N and you want to show "a week from now" with DayOfTheWeek(N+7), but surely a modulo will be more flexible -- then you can do a fortnight hence as well!
Admin
Assuming a non-fake-out, why on earth is your keyboard doing that?
Admin
They might be being clever.
If the day offset from the start of the month is a Saturday (day 7) you only need 6 more days to print a calendar by week. Day 13 being Friday.
It's an awful way to write the function but it makes sense.
Not a total WTF.
(PS: I have not thought this through but it the first thing I thought of when I saw it).
Admin
I don't see the problem here. This is a perfectly cromulent function. It is a speedier alternative to:
-Harrow.
Admin
-Harrow.
Admin
The method is obviously misnamed and poorly built. Apparently what was wanted was a day calculator -- as in every 2 weeks on a weekday or some such. As the prevous poster put it, some simple math like modulo could have made it less buggy and virtually limitless. That's what poor math instruction in public schools will do to you
Waitt! But there us an even bigger WTF : why hardcode a culture specific weekday method when most Microsoft frameworks [ guy's using some incarnation of VB for crying out loud] contain excellent culture neutral calendar classes with all kinds of nifty date functions.
Admin
Ha! Everybody knows there's "Eight Days a Week."
Admin
For all of you saying this isn't a WTF, consider that it's been deemed such by a guy who thinks Monday was last week.
Admin
Yeah, this is ugly, but it's likely a part of some date-ranging function that takes day of week, adds some-number-mod7 and arrives at a new week day. It can then print the days between them.
The mod is in the wrong place, first.
Duplicating code is the next sin.
Boneheadedness in the algorithm is the last.
Admin
You, sir, are win.
Admin
The real WTF is that while the number of days per year is constantly increasing (by about 68 seconds per century), necessitating adding extra days to the YEAR, the number of days per week is unlikely to undergo any changes anytime soon.
Admin
Captcha: paratus. Semper Paratus.
Admin
I think this is called a "leap week". Didn't they use stuff like that back in the 16th century?
Admin
amateurs.
I once worked on some code that had a PHASE-OF-THE-MOON parameter. It needed to do slightly different processing on a 4 week cycle.
Admin
If a fake-out, would he have said "an"?
Admin
Damn. I meant NON-fake-out.
Admin
Sure, I can think of reasons why I would use a 13-day day calculator. But it's still WTF. Code where you have to think of an explanation for the code is by definition WTF.
Admin
Case 14 DayOfTheWeek = STR_SNORFDAY
Actually the 7 day week has probably been around longer than just about any other timekeeping convention, and likely without any interruption. You could go back week by week a few millennia and it'd still work. (Subject to geographical differences -- I don't think the ancient North Americans had a 7 day week, for example.)
Admin
Last week? Try two days ago. I think a little more sleep is still in order.
Admin
Muphry's law strikps again!
Admin
Last week if he used the modulo method...
Admin
The real WTF: They forgot Case Else...
Admin
In Soviet Russia we have no WFT's
Admin
Very good, but with a slight error. The last statement implies the p's and e's are getting switched.
Unfortunately Rumen forgot to actually do this in the first part of the post. (See ppoplp for instance.)
CAPTCHA: saluto
And saluto to you!
Admin
Gory details:
http://en.wikipedia.org/wiki/Seven-day_week
Admin
Admin
In Soviet Russia, WTF code executes you!
Admin
It actually makes sense. If you use any number modulus 7, you end up with a result between -6 and 6. If you then add 7 to this result, you start at 1 and end with 13. These numbers would be matching the exact outcome of this function.
Admin
The WTF is that you disagree with using 13 numbers... Do this:
iDay = (iRandomDay%7)+7
When -RandomDay is negative, you would get a negative value with the % but by adding 7, all days end in the range between 1 and 13...
It actually makes sense, especially if you'd allow negative dates...
Admin
hm, wouldn't it have been better to use a LinkedList in case the weekdays change more often (and to make it easier in case the days switch places)? then you wouldn't even have to recompile/restart the app so often ;)
na, seriously: what really is the best solution for something like this? my guess would be an array with the weekday names and an offset-variable eg. for countries where weeks don't start mondays (aka. USA). so you can do sthg like this in java (which even supports weeks with different than 7 days):
String getDayName(int day) { return dayname[(day + offset) % dayname.length]; }
CAPTCHA: dignissim
Admin
The problem is that the coder was only a demi-god. As such it was only on the 14th day he/she rested. Only the big fella gets the managerial privilege of having a day off EVERY week....
Admin
TRWTF is that Apple is now reinventing the week, and TRRWTF is that they're calling it the iDay instead of the iWeek. Typical.
Admin
Nope. Every time DayOfTheWeek is called, it's called like this:
Admin
The submitter should have more humility and faith in other human beings. There's obviously something intentional about the 13 days. At a minimum this sequence can encode any week that begins on any particular day:
Sunday through Saturday Monday through Sunday ... Saturday through Friday
Admin
Totally done it. TI 83+ graphing calculator in highschool (woah, 12 years ago now?). I built a simple schedule program to track homework and activities. Mine was a bit different in that the DAYS_OF_WEEK were stored in a 13 element array, a quick look at array(current+change) would result in the correct day no matter what. This method WAS faster than mod.
TiBasic, bitches, it works.
Admin
Case 14 DayOfTheWeek = FILE_NOT_FOUND
Admin
13 days of the week should be enough for anyone.
Admin
Admin
Yup, much better now.
Admin
Hahaha,
Alex, how are the drinks at the convention?
Sandor
Admin
Same story here: the week-end is the end of the week.
Admin
It reminds me of a prank I've read somewhere recently (a webcomic?): you detach two keys from the keyboard of a coworker (who type looking at the chars) and reattach them switched; then wait.
Some keyboards (IBM for instance) have the chars over "key-covers" you can easily pop out; I think it was done for make localization costs cheap.
CYA