Comment On The Long Week

Turns out that I'm The Real WTF, since the Code SOD from earlier today was already posted... last week. Whoops; consequences of posting realllly late at night in a hotel room while at The Business of Software conference I suppose. Anyway, here's one that I'm pretty sure wasn't from last week. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: The Long Week

2009-11-11 13:44 • by undefined (unregistered)
The real WTF is hardcoded first day of week. In Russia first day is Monday.

Re: The Long Week

2009-11-11 13:47 • by Anon Coward (unregistered)
But...why only 13 days? 14 maybe, there might be some code requiring fortnight processing or something. But 13? Bizarre

Re: The Long Week

2009-11-11 13:47 • by WTF (unregistered)
ok so theres only two comments on this right now, WTF? don't think i've ever seen it

Re: The Long Week

2009-11-11 13:50 • by Marvin the Martian (unregistered)
290459 in reply to 290458
WTF:
ok so theres only two comments on this right now, WTF? don't think i've ever seen it

What a heartstoppingly relevant remark to be preserved for eternity: a few minutes after the story was posted, there were only 2 remarks.

Who could have guessed? We always thought they'd appear in threes or somesuch.

Re: The Long Week

2009-11-11 13:51 • by My Name? (unregistered)
Wayoo:
FRIST!!

Not for long, as your posting gets soon deleted.

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.

if(iDay>=14) DayOfTheWeek(iDay%14);
if(iDay<0) DayOfTheWeek(14-(abs(iDay)%14));
Select Case iDay
Case 0
DayOfTheWeek = STR_SATURDAY
Case 1
DayOfTheWeek = STR_SUNDAY
Case 2
DayOfTheWeek = STR_MONDAY
Case 3
DayOfTheWeek = STR_TUESDAY
Case 4
DayOfTheWeek = STR_WEDNESDAY
Case 5
DayOfTheWeek = STR_THURSDAY
Case 6
DayOfTheWeek = STR_FRIDAY
Case 7
DayOfTheWeek = STR_SATURDAY2
Case 8
DayOfTheWeek = STR_SUNDAY2
Case 9
DayOfTheWeek = STR_MONDAY2
Case 10
DayOfTheWeek = STR_TUESDAY2
Case 11
DayOfTheWeek = STR_WEDNESDAY2
Case 12
DayOfTheWeek = STR_THURSDAY2
Case 13
DayOfTheWeek = STR_FRIDAY2
End Select
End Function


Re: The Long Week

2009-11-11 13:57 • by Scott M (unregistered)
Friday the 13th!

Which coincidentally also happens this week.

Re: The Long Week

2009-11-11 14:18 • by Rumen (unregistered)
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'.)

Re: The Long Week

2009-11-11 14:27 • by Nathon (unregistered)
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.

Re: The Long Week

2009-11-11 14:27 • by Berry (unregistered)
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!

Re: The Long Week

2009-11-11 14:31 • by SarahE
290468 in reply to 290465
Rumen:
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'.)

You've piqued my curiosity... how did you get that last (real) 'e' in there? Alt + 101? Or were you just faking it?

Assuming a non-fake-out, why on earth is your keyboard doing that?

Re: The Long Week

2009-11-11 14:33 • by random lurker (unregistered)
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).

Re: The Long Week

2009-11-11 14:35 • by Harrow (unregistered)
I don't see the problem here. This is a perfectly cromulent function. It is a speedier alternative to:

Public Function DayOfTheWeek(iDay As Integer) As String

'Mapping of day number to day-of-the-week string.
Select Case iDay
Case 1
DayOfTheWeek = STR_SUNDAY
Case 2
DayOfTheWeek = STR_MONDAY
Case 3
DayOfTheWeek = STR_TUESDAY
Case 4
DayOfTheWeek = STR_WEDNESDAY
Case 5
DayOfTheWeek = STR_THURSDAY
Case 6
DayOfTheWeek = STR_FRIDAY
Case 7
DayOfTheWeek = STR_SATURDAY
End Select
End Function

Public Function TicklerNextDay(iNxtDay As Integer) As String
'Because the tickler scheduler may add up to six days
'iDay may range from 1 to 13 (ie. Today to Today+6)
TicklerNextDay + DayOfTheWeek(((iNxtDay-1)%7)+1)
End Function


-Harrow.

Re: The Long Week

2009-11-11 14:41 • by Harrow (unregistered)
random lurker:
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.

Brilliant. I'm sure that's it. I knew I'd seen -- maybe even coded -- a six day offset into the week, but I couldn't remember why! So I made up that unlikely "Tickler scheduler" example. I just wish I could think as fast as you.

-Harrow.

Re: The Long Week

2009-11-11 14:47 • by Jj (unregistered)
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.

Re: The Long Week

2009-11-11 14:52 • by Dennis (unregistered)
Ha! Everybody knows there's "Eight Days a Week."

Re: The Long Week

2009-11-11 15:11 • by Nobody You Know (unregistered)
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.

Re: The Long Week

2009-11-11 15:19 • by Chad M (unregistered)
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.

Re: The Long Week

2009-11-11 15:20 • by Eh? (unregistered)
290483 in reply to 290480
Nobody You Know:
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.


You, sir, are win.

Re: The Long Week

2009-11-11 15:20 • by gus (unregistered)
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.

Re: The Long Week

2009-11-11 15:24 • by Brian (unregistered)
290486 in reply to 290476
Dennis:
Ha! Everybody knows there's "Eight Days a Week."
Haha, Beatles. I'm a Stones man, myself.

Captcha: paratus. Semper Paratus.

Re: The Long Week

2009-11-11 15:27 • by NameNotFoundException (unregistered)
I think this is called a "leap week". Didn't they use stuff like that back in the 16th century?

Re: The Long Week

2009-11-11 15:33 • by avflinsch
290488 in reply to 290457
Anon Coward:
But...why only 13 days? 14 maybe, there might be some code requiring fortnight processing or something. But 13? Bizarre


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.

Re: The Long Week

2009-11-11 15:35 • by Ibi-Wan Kentobi (unregistered)
290489 in reply to 290468
SarahE:
Rumen:
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'.)

You've piqued my curiosity... how did you get that last (real) 'e' in there? Alt + 101? Or were you just faking it?

Assuming a non-fake-out, why on earth is your keyboard doing that?


If a fake-out, would he have said "an"?

Re: The Long Week

2009-11-11 15:35 • by Ibi-Wan Kentobi (unregistered)
290490 in reply to 290489
Damn. I meant NON-fake-out.

Re: The Long Week

2009-11-11 15:40 • by Finance programmer (unregistered)
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.

Re: The Long Week

2009-11-11 15:48 • by Leo (unregistered)
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.)

Re: The Long Week

2009-11-11 15:51 • by evanm
Alex Papadimoulis:
since the Code SOD from earlier today was already posted... last week


Last week? Try two days ago. I think a little more sleep is still in order.

Re: The Long Week

2009-11-11 16:09 • by My Namp? (unregistered)
290495 in reply to 290490
Ibi-Wan Kentobi:
Damn. I meant NON-fake-out.


Muphry's law strikps again!

Re: The Long Week

2009-11-11 16:11 • by fatty (unregistered)
290496 in reply to 290494
Last week if he used the modulo method...

Re: The Long Week

2009-11-11 16:21 • by d (unregistered)
The real WTF: They forgot Case Else...

Re: The Long Week

2009-11-11 16:29 • by Yakov Smirnoff (unregistered)
290498 in reply to 290456
The real WTF is hardcoded first day of week. In Russia first day is Monday.


In Soviet Russia we have no WFT's

Re: The Long Week

2009-11-11 16:34 • by Doug (unregistered)
290499 in reply to 290465
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!

Re: The Long Week

2009-11-11 16:52 • by Maurits
290500 in reply to 290493
Leo:
Actually the 7 day week has probably been around longer than just about any other timekeeping convention, and likely without any interruption.


Gory details:

http://en.wikipedia.org/wiki/Seven-day_week

Re: The Long Week

2009-11-11 16:54 • by C (unregistered)
290501 in reply to 290489
Ibi-Wan Kentobi:
SarahE:
Rumen:
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'.)

You've piqued my curiosity... how did you get that last (real) 'e' in there? Alt + 101? Or were you just faking it?

Assuming a non-fake-out, why on earth is your keyboard doing that?

If a [non-]fake-out, would he have said "an"?
SarahE: copy + paste. This would also explain the "an"... but there's still the problem of switched "p" and "e". The statement should've been
Sorry, pvpry timp I kpy thp lpttpr 'e' I gpt a 'p'.
-- maybe someone missed their coffee for the day?

Re: The Long Week

2009-11-11 16:58 • by Mason Wheeler
290502 in reply to 290498
Yakov Smirnoff:
The real WTF is hardcoded first day of week. In Russia first day is Monday.


In Soviet Russia we have no WFT's


In Soviet Russia, WTF code executes you!

Re: The Long Week

2009-11-11 17:09 • by W.A. ten Brink (unregistered)
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.

Re: The Long Week

2009-11-11 17:13 • by W.A. ten Brink (unregistered)
290504 in reply to 290460
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...

Re: The Long Week

2009-11-11 17:35 • by Frankyboy (unregistered)
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

Sabbath

2009-11-11 17:44 • by Caffeine (unregistered)
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....

Re: The Long Week

2009-11-11 20:20 • by frist (unregistered)
TRWTF is that Apple is now reinventing the week, and TRRWTF is that they're calling it the iDay instead of the iWeek. Typical.

Re: The Long Week

2009-11-12 00:19 • by halcyon1234
290515 in reply to 290457
Anon Coward:
But...why only 13 days? 14 maybe, there might be some code requiring fortnight processing or something. But 13? Bizarre


Nope. Every time DayOfTheWeek is called, it's called like this:


sDayOfTheWeek = DayOfTheWeek(iDayOfTheWeek);

if (! sDayOfTheWeek == true && (iDayOfTheWeek < 1)==true){
sDayOfTheWeekOk = STR_DAY_BEFORE_THE_FIRST_NAME
}
else
{
sDayOfTheWeekOk = DayOfTheWeek(iDayOfTheWeek);
}

sDayOfTheWeek = sDayOfTheWeekOk

Re: The Long Week

2009-11-12 01:07 • by BentFranklin
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

Re: The Long Week

2009-11-12 01:14 • by Agod (unregistered)
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.

Re: The Long Week

2009-11-12 01:44 • by Lee K-T (unregistered)
Case 14
DayOfTheWeek = FILE_NOT_FOUND

Re: The Long Week

2009-11-12 02:40 • by Billy (unregistered)
290521 in reply to 290457
Anon Coward:
But...why only 13 days? 14 maybe, there might be some code requiring fortnight processing or something. But 13? Bizarre


13 days of the week should be enough for anyone.

Re: The Long Week

2009-11-12 02:49 • by Watson
290523 in reply to 290468
SarahE:
Rumen:
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'.)

You've piqued my curiosity... how did you get that last (real) 'e' in there? Alt + 101? Or were you just faking it?
Rumen's post contains two 'e's....

Re: The Long Week

2009-11-12 03:09 • by Hobo (unregistered)

Case 13
DayOfTheWeek = STR_PANTS_FREE_FRIDAY


Yup, much better now.

Re: The Long Week

2009-11-12 03:13 • by Rodnas (unregistered)
Hahaha,

Alex, how are the drinks at the convention?

Sandor

Re: The Long Week

2009-11-12 03:18 • by Federico
290526 in reply to 290456
undefined:
The real WTF is hardcoded first day of week. In Russia first day is Monday.


Same story here: the week-end is the end of the week.

Re: The Long Week

2009-11-12 03:29 • by z f k (unregistered)
290527 in reply to 290468
SarahE:
Rumen:
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'.)

You've piqued my curiosity... how did you get that last (real) 'e' in there? Alt + 101? Or were you just faking it?

Assuming a non-fake-out, why on earth is your keyboard doing that?


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
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment