• Gyxi (unregistered)

    What a great idea to consistently name all method parameters "in".

  • DirtyDick (unregistered)

    Devan L. forgot that today is WTFday.

  • Tractor (unregistered)

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

  • RandomGuy (unregistered)

    // Not sure if this comment is visible in leap years

  • olaf (unregistered)

    The real WTF is a week starting with Sunday.

  • It'sMeMario (unregistered)

    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); }

  • Noughmad (unregistered)

    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.

  • faoileag (unregistered)

    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.

  • (cs) in reply to olaf

    The first day of the week is different in different locales.

  • faoileag (unregistered) in reply to Gyxi
    Gyxi:
    What a great idea to consistently name all method parameters "in".
    Copy & paste is really helpful in a programmer's quest to achieve consistency!
  • ZoomST (unregistered)

    Quite convenient! For Frogdays, just need to add by copy-pasting:

     public Date getFrogdayInWeek(Date in) {
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(in);
            return new Date(in.getTime() + (Calendar.FROGDAY - gc.get(Calendar.DAY_OF_WEEK))*24*3600*1000);
        }
    And add the correspondent value to the switch entry:
    case Calendar.CATURDAY:  return getFrogdayInWeek(in);

    EDIT: Oops! I made a copy-paste mistake on the case statement. WTF!

  • Pero perić (unregistered) in reply to faoileag

    Judging from the name of the last method (getReleaseDateInWeek) I'd say the code was tested only for Tuesday/Frogday.

  • Michele (unregistered)

    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.

  • (cs) in reply to Michele

    TRWTF is using Java's Calendars, Dates, etc. Use JodaTime and pray for this to make sense in Java8

  • Maciej (unregistered) in reply to faoileag
    faoileag:
    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.

    That might be because it's the only method used.

  • faoileag (unregistered) in reply to Maciej
    Maciej:
    faoileag:
    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.

    That might be because it's the only method used.

    Erm... I think I should have used [humor] tags in my original post :-(

  • Shinobu (unregistered)

    Why is it that date handling code, which is notoriously easy to screw up, is such a favourite target for reinvention by beginner programmers?

  • Swedish tard (unregistered) in reply to Shinobu
    Shinobu:
    Why is it that date handling code, which is notoriously easy to screw up, is such a favourite target for reinvention by beginner programmers?

    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.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    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.

  • (cs) in reply to Shinobu
    Shinobu:
    Why is it that date handling code, which is notoriously easy to screw up, is such a favourite target for reinvention by beginner programmers?
    This may be a necessary step in becoming a mature programmer. I found the experience of struggling with date/time code to be incredibly educational (and humbling).

    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.

  • Edmund (unregistered)

    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.

  • faoileag (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    And it's not like you can't run a program with a bunch of loops to actually, you know, TEST shit like this?
    That's been baffling me as well - I mean, if I'm not sure what a method does on some specific condition, I hardcode the in parameter to fit that condition, call the method and have a look at what happens. That's 5 minutes work - if that much.
  • (cs) in reply to dgvid
    dgvid:
    Shinobu:
    Why is it that date handling code, which is notoriously easy to screw up, is such a favourite target for reinvention by beginner programmers?
    This may be a necessary step in becoming a mature programmer. I found the experience of struggling with date/time code to be incredibly educational (and humbling).

    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.

    That gives me an idea -- use the Daily WTF as a class. Sort of a "curious perversion" of Havard Business Cases. Present some of the more classic examples and ask the class, "OK, what SHOULD have happened?" The beautiful examples here demonstrate so many "IT life lessons" like: never modify directly in production, always understand the requirements, make sure the company you are interviewing with isn't insane, when in doubt unroll loops, and time/date library functions are for luzers.

    Alex, that is your next project after BuildMaster -- the Daily WTF IT Business Case Library.

  • Dario (unregistered)

    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.

  • (cs) in reply to Bruce W
    Bruce W:
    That gives me an idea -- use the Daily WTF as a class. Sort of a "curious perversion" of Havard Business Cases. Present some of the more classic examples and ask the class, "OK, what SHOULD have happened?" The beautiful examples here demonstrate so many "IT life lessons"
    It's true, a significant portion of the things I know about IT I learned from TDWTF.
  • faoileag (unregistered) in reply to mrsparkyman
    mrsparkyman:
    Bruce W:
    That gives me an idea -- use the Daily WTF as a class. Sort of a "curious perversion" of Havard Business Cases. Present some of the more classic examples and ask the class, "OK, what SHOULD have happened?" The beautiful examples here demonstrate so many "IT life lessons"
    It's true, a significant portion of the things I know about IT I learned from TDWTF.
    "I've found this great site, where they publish code snippets that solve various problems. It's called 'The Daily WTF' - don't know what the acronym stands for, but I use their code wherever I can." Right?
  • (cs) in reply to olaf
    olaf:
    The real WTF is a week starting with Sunday.

    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'

  • OldCoder (unregistered)

    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.

  • gnasher729 (unregistered) in reply to pscs
    pscs:
    olaf:
    The real WTF is a week starting with Sunday.

    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'

    Quick web search finds this:

    According to the international standard ISO 8601, Monday shall be the first day of the week ending with Sunday as the seventh day of the week. Although this is the international standard, countries such as the United States still have their calendars refer to Sunday as the start of the seven-day week.
    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.

  • gnasher729 (unregistered) in reply to pscs

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

  • Joe (unregistered) in reply to faoileag
    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?

    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.

  • Paul M (unregistered) in reply to It'sMeMario

    How dull!

  • Missouri Buckeye (unregistered)

    I never could get the hang of Tuesdays.

  • (cs)
    [image]

    MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY

  • Chelloveck (unregistered) in reply to gnasher729
    gnasher729:
    And think about the word "weekend".

    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.

  • Joe (unregistered) in reply to faoileag
    faoileag:
    "I've found this great site, where they publish code snippets that solve various problems. It's called 'The Daily WTF' - don't know what the acronym stands for, but I use their code wherever I can." Right?
    It stands for "Want This Fixed?" So when you have a problem you want fixed, search here for an incredible way to fix it.
  • Valued Service (unregistered) in reply to cthart
    cthart:
    The first day of the week is different in different locales.

    I'm waiting for that distinction to attribute any meaning to life.

    ...

    Nope. Still don't get it.

  • (cs) in reply to Bruce W
    Bruce W:
    That gives me an idea -- use the Daily WTF as a class. Sort of a "curious perversion" of Havard Business Cases. Present some of the more classic examples and ask the class, "OK, what SHOULD have happened?" The beautiful examples here demonstrate so many "IT life lessons" like: never modify directly in production, always understand the requirements, make sure the company you are interviewing with isn't insane, when in doubt do not unroll loops (because if you have doubt then this is premature optimisation), and rewriting time/date library functions is for luzers.
    FTFY (and, yes, I do realise you were probably trying to be funny)
  • Valued Service (unregistered) in reply to Zylon
    Zylon:
    [image]

    MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY

    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.

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

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

  • Valued Service (unregistered) in reply to gnasher729

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

    1. To be distinct from the Jewish day of worship.
    2. Jesus supposedly rose on Sunday.
  • just me (unregistered) in reply to cthart
    cthart:
    The first day of the week is different in different locales.
    Absolutely; its right in some locales and wrong in others...
  • (cs) in reply to Zylon
    Zylon:
    [image]

    MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY

    FRIDAY FRIDAY FRIDAY FRIDAY FRIDAY I'm waiting for the Weeeeeekend!

  • nmare (unregistered) in reply to Edmund

    You are wrong!

    Your honest moron found a job for the government.

  • nmare (unregistered) in reply to Edmund

    sorry it didnt quote previously

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

    You are wrong!

    Your honest moron found a job for the government.

  • Paul Neumann (unregistered) in reply to nmare
    nmare:
    *sorry it didnt quote previously*
    Edmund:
    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.
    You are wrong!

    Your honest moron found a job for the government.

    I didn't vote for him!

  • HowItWorks (unregistered) in reply to just me
    just me:
    cthart:
    The first day of the week is different in different locales.
    Absolutely; its right in some locales and wrong in others...
    Exactly. One must not confuse big-endian and little-endian when eating soft-boiled eggs!
  • Chuck (unregistered) in reply to Swedish tard
    Swedish tard:
    Shinobu:
    Why is it that date handling code, which is notoriously easy to screw up, is such a favourite target for reinvention by beginner programmers?

    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.

    The existing methodology can also be really intimidating. Just look at Java dates >_<

  • RFoxmich (unregistered) in reply to Chuck

    No thank you

    Chuck:
    Swedish tard:
    Shinobu:
    Why is it that date handling code, which is notoriously easy to screw up, is such a favourite target for reinvention by beginner programmers?

    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.

    The existing methodology can also be really intimidating. Just look at Java dates >_<

  • Spewin Coffee (unregistered)
    // Not sure if this will work for leap years
    public Date writeFrist() {
        return +1;
    }
    

Leave a comment on “Nine Ways to Tuesday”

Log In or post as a guest

Replying to comment #:

« Return to Article