• undefined (unregistered)

    The real WTF is hardcoded first day of week. In Russia first day is Monday.

  • Anon Coward (unregistered)

    But...why only 13 days? 14 maybe, there might be some code requiring fortnight processing or something. But 13? Bizarre

  • WTF (unregistered)

    ok so theres only two comments on this right now, WTF? don't think i've ever seen it

  • Marvin the Martian (unregistered) in reply to WTF
    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.

  • 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

  • Scott M (unregistered)

    Friday the 13th!

    Which coincidentally also happens this week.

  • 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'.)

  • 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.

  • 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!

  • (cs) in reply to Rumen
    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?

  • 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).

  • 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.

  • 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.

  • 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.

  • Dennis (unregistered)

    Ha! Everybody knows there's "Eight Days a Week."

  • 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.

  • 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.

  • Eh? (unregistered) in reply to Nobody You Know
    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.

  • 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.

  • Brian (unregistered) in reply to Dennis
    Dennis:
    Ha! Everybody knows there's "Eight Days a Week."
    Haha, Beatles. I'm a Stones man, myself.

    Captcha: paratus. Semper Paratus.

  • NameNotFoundException (unregistered)

    I think this is called a "leap week". Didn't they use stuff like that back in the 16th century?

  • (cs) in reply to Anon Coward
    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.

  • Ibi-Wan Kentobi (unregistered) in reply to SarahE
    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"?

  • Ibi-Wan Kentobi (unregistered) in reply to Ibi-Wan Kentobi

    Damn. I meant NON-fake-out.

  • 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.

  • 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.)

  • (cs)
    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.

  • My Namp? (unregistered) in reply to Ibi-Wan Kentobi
    Ibi-Wan Kentobi:
    Damn. I meant NON-fake-out.

    Muphry's law strikps again!

  • fatty (unregistered) in reply to evanm

    Last week if he used the modulo method...

  • d (unregistered)

    The real WTF: They forgot Case Else...

  • Yakov Smirnoff (unregistered) in reply to undefined
    The real WTF is hardcoded first day of week. In Russia first day is Monday.

    In Soviet Russia we have no WFT's

  • Doug (unregistered) in reply to Rumen

    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!

  • (cs) in reply to Leo
    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

  • C (unregistered) in reply to Ibi-Wan Kentobi
    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?
  • (cs) in reply to Yakov Smirnoff
    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!

  • 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.

  • W.A. ten Brink (unregistered) in reply to My Name?

    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...

  • 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

  • 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....

  • 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.

  • (cs) in reply to Anon Coward
    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

  • (cs)

    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

  • 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.

  • Lee K-T (unregistered)

    Case 14 DayOfTheWeek = FILE_NOT_FOUND

  • Billy (unregistered) in reply to Anon Coward
    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.

  • (cs) in reply to SarahE
    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....
  • Hobo (unregistered)
        Case 13
            DayOfTheWeek = STR_PANTS_FREE_FRIDAY
    

    Yup, much better now.

  • Rodnas (unregistered)

    Hahaha,

    Alex, how are the drinks at the convention?

    Sandor

  • (cs) in reply to undefined
    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.

  • z f k (unregistered) in reply to SarahE
    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

Leave a comment on “The Long Week”

Log In or post as a guest

Replying to comment #290487:

« Return to Article