• (cs)

    "I said I wanted pretty week code, not pretty weak code!"

  • jay (unregistered)

    I don't see any reason why this code wouldn't work in leap years. Leap years don't affect the flow of the days of the week -- it's not like we have two Tuesdays in a row in leap years.

    But it WON'T work on the days when we transition to or from Daylights Savings Time. Two days a year are NOT 24 hours long. There is one that is 23 hours and one that is 25 hours.

  • Joe (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?
    Cuz it's the only kind of date they can get screwed on?
  • jay (unregistered)

    Among the funny things here is that the problem with the commented-out code has nothing to do with rolling over month boundaries. The comment indicates he wants "next Tuesday", but the code will give the upcoming Tuesday if that starting date is Sunday or Monday and the preceding Tuesday if the starting date is Wednesday through Saturday. It looks like he wrote code with a bug and when it didn't work, jumped to the conclusion that the library code had a bug.

  • (cs)

    Advanced lessons in computing, please learn:

    1. Logicals (True, False, FILE_NOT_FOUND)
    2. Dates (Your language has a library, use it)
    3. Endianness. (Your machine can be different from others)
    4. Sorts. (No, a bubble sort is not efficient).
    5. Databases. (We warned you about Bobby Tables!).

    I'm sure there are others, and they will be added later. See the followons.

  • jay (unregistered) in reply to Valued Service
    Valued Service:
    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.

    It matters a great deal if I have a bill that is due on Thursday and I need my next paycheck to pay it.
    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.
    Umm, yes, that would be the point. Most people in America and Europe don't have to go to work on Saturdays and Sundays, and some go to church on Sunday or to synagogue on Saturday, so they care what day of the week it is.
    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.

    If you mean that a holiday is on, say, "Monday", rather than "the second day of the week", I guess that's true.

    All told, I'm not sure what your point is.

    Where it really matters what the "first day of the week" is comes when you say something like "we will do that next week". You have to know when a week starts and ends to properly interpret the date referenced by such a statement.

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

    Come on, be serious. The real rule is this: If the 28th day of February in a leap year is Monday, then the 1st day of March in that same year is Tuesday. The day of week for the 29th of February is FILE NOT FOUND.

  • lolatu (unregistered) in reply to Gyxi

    GIGO!

  • (cs) in reply to Noughmad
    Noughmad:
    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.
    The real WTF is that the coder doesn't seem to know the intent of this code.
  • someguy (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, this is a subtle point that has led to the creation of the religion known as Seventh-Day Adventists. The idea is that the Jewish tradition actually holds Saturday as the day of rest, and due to some date issues with Christ's rising the early Christian church decided that Sunday was a more memorable day than Saturday. In one of the Gospels there's a bit about how on that day "It was then the first day of the week." Add that to the dating of Easter Sunday on... well... Sunday and you get that at the time of writing, Sunday was considered the first day of the week.

  • (cs) in reply to someguy

    [quote user="someguy"][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, this is a subtle point that has led to the creation of the religion known as Seventh-Day Adventists. The idea is that the Jewish tradition actually holds Saturday as the day of rest, and due to some date issues with Christ's rising the early Christian church decided that Sunday was a more memorable day than Saturday. In one of the Gospels there's a bit about how on that day "It was then the first day of the week." Add that to the dating of Easter Sunday on... well... Sunday and you get that at the time of writing, Sunday was considered the first day of the week.[/quote]

    Just an addendum: Jewish tradition holds that Saturday is the day of rest because it is the weekly anniversary of the seventh day of creation, on which the creator rested.

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

    I don't know what Western country you are from, but here in the states we start our weeks on Monday. And from my experience working with people in Europe and Canada so do they. In fact, even working with contractors from eastern Asian countries their days start on Monday as well.

  • aptent (unregistered)

    That's awesome. It's also friendly for changing when number of days in a week change.

  • Brent Seidel (unregistered) in reply to garrywong

    I don't know what kind of a sadist decided that the week should start on Monday. It makes it hardly worth getting out of bed. The week should really start on Friday, then you can work one day and immediately get two days off. This would be much better, in my opinion.

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

    Heck, if even Shirley Temple could get it right....

  • (cs)

    In the beginning Java was created. This has made a lot of people very angry and been widely regarded as a bad move.

  • rjiofer90 (unregistered) in reply to Chelloveck
    Chelloveck:
    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.
    That would make sense if it was called "the weekends", but "the end" as a singular generally means the opposite of "the beginning".
  • DarrenC (unregistered) in reply to Brent Seidel
    I don't know what kind of a sadist decided that the week should start on Monday. It makes it hardly worth getting out of bed. The week should really start on Friday, then you can work one day and immediately get two days off. This would be much better, in my opinion.

    No, no. It's much better the way it is now. One day off at the start of the week, and one day off at the end.

  • anonymous (unregistered)

    'end' does not always mean 'opposite of beginning.' Think of bookends. The devices sit at both ends of a row of books. "both ends."

    "week starts on monday"... well, the "work week" starts on monday for those that work monday through friday (or through whenever). There are plenty of people in the US who work different hours. And there are plenty of people int he US who count "sunday" as the start of the week. In fact, look at a typical calendar sold in the US and you'll see weeks starting on sunday and ending on saturday - sunday starts each row and saturday ends each row.

  • rjiofer90 (unregistered) in reply to anonymous
    anonymous:
    'end' does not always mean 'opposite of beginning.' Think of bookends. The devices sit at both ends of a row of books. "both ends."
    Yes, that's why they're called bookendS, plural. I know it's a subtle point, but if you'd bothered to, y'know, read the part of my post where I explicitly pointed it, you might have had a chance.
  • (cs)

    And now "end" is the opposite of "end." Awesome. We're brilliant here.

    yes, I'm being pedantic, but I'm no less deconstructive than the other comments here

  • F (unregistered) in reply to jay
    jay:
    I don't see any reason why this code wouldn't work in leap years. Leap years don't affect the flow of the days of the week -- it's not like we have two Tuesdays in a row in leap years.

    But it WON'T work on the days when we transition to or from Daylights Savings Time. Two days a year are NOT 24 hours long. There is one that is 23 hours and one that is 25 hours.

    Provided you're running the code no earlier than when the clocks change, and more than an hour before midnight, you're still OK.

    The better approach would be to adjust the base time to midday before adding days; then the code is fine no matter when it's run. Five microseconds to midnight excepted, of course.

  • F (unregistered) in reply to rjiofer90
    rjiofer90:
    anonymous:
    'end' does not always mean 'opposite of beginning.' Think of bookends. The devices sit at both ends of a row of books. "both ends."
    Yes, that's why they're called bookendS, plural. I know it's a subtle point, but if you'd bothered to, y'know, read the part of my post where I explicitly pointed it, you might have had a chance.

    Ah. You expect people to respond to what you said, rather than to something rather like what you said that suits their argument better.

    You must be new here. Don't panic - you'll get used to it.

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

    Come on, be serious. The real rule is this: If the 28th day of February in a leap year is Monday, then the 1st day of March in that same year is Tuesday. The day of week for the 29th of February is FILE NOT FOUND.

    It's hardly going to matter, the s/w's not going to be around long enough to last till the next leap year anyway. That's like 3 years away. Nearly. We'll have upgraded way before then.

  • Proud Graduate April 2013 (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?
    because dates should be easy (I been using them since I was about 3), yet all the available libraries seem unnecessarily complex when I want to program with them.

    I have a degree. I must be able to make a nice simple date thingummy to do what I want

    switch you sarcasm detector on

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

    I just read that it was a bad idea here, and never bothered trying.

    I laugh when I see people do wierd things like use an existing Date class, then extract all the bits (Day, Month year) play with them, and then re-create a date. Seems to defeat the purpose a little, but I spose they're 1/2 way there

  • Kiwi (unregistered) in reply to Zylon
    Zylon:
    [image]

    MONDAY TUESDAY WTF SATURDAY SUNDAY

    FTFY

  • Figs (unregistered) in reply to Edmund
    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.
    Agree. It's sort of ironic that recruitment processes find people with big egos, but one of the biggest issues for programmers is not realising their limitations.
  • Figs (unregistered) in reply to pscs
    pscs:
    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) )

    And in Italian Sabato (Sabbath)= Saturday, Domenico = Sunday And in German samstag = Saturday, Sonntag (note the capital S) = Sunday (literally). because Christianity stole so much from the pagans And bucking the trend a little in Latvian Sezdiena (six-day**) = Saturday, Svetdiena (Holy day) = Sunday I think all three of the baltics follow this trend....

    ** yup, they is boring enough to have first-day (pirmdiena), second-day (otradiena), third-day (trezhdiena), fourth-day (ceturdiena), fifth-day (piekdiena), sizth-day (sezdiena) and holy-day (Svetdiean))

  • Mack (unregistered)

    i think they could've just used a slider to show the current week's window so you can work out the tuesday in the week

  • a'woih (unregistered) in reply to jay
    jay:
    Valued Service:
    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.

    It matters a great deal if I have a bill that is due on Thursday and I need my next paycheck to pay it.
    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.
    Umm, yes, that would be the point. Most people in America and Europe don't have to go to work on Saturdays and Sundays, and some go to church on Sunday or to synagogue on Saturday, so they care what day of the week it is.
    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.

    If you mean that a holiday is on, say, "Monday", rather than "the second day of the week", I guess that's true.

    All told, I'm not sure what your point is.

    Where it really matters what the "first day of the week" is comes when you say something like "we will do that next week". You have to know when a week starts and ends to properly interpret the date referenced by such a statement.

    with the last bit, I thought he meant New Years day (for example) is on Jan 01, not "the first monday in January".
  • Shine (unregistered) in reply to anonymous
    anonymous:
    'end' does not always mean 'opposite of beginning.' Think of bookends. The devices sit at both ends of a row of books. "both ends."

    "week starts on monday"... well, the "work week" starts on monday for those that work monday through friday (or through whenever). There are plenty of people in the US who work different hours. And there are plenty of people int he US who count "sunday" as the start of the week. In fact, look at a typical calendar sold in the US and you'll see weeks starting on sunday and ending on saturday - sunday starts each row and saturday ends each row.

    Why does everyone care when the week starts? It still has the same days in it irrespective. The revolution to start the year on April 1 begins.
  • Jim (unregistered) in reply to chubertdev
    chubertdev:
    And now "end" is the opposite of "end." Awesome. We're brilliant here.

    yes, I'm being pedantic, but I'm no less deconstructive than the other comments here

    Yes, exactly - one end is opposite the other....

    how long is a piece of string? Twice the distance from one end to the middle

  • Gary B (unregistered) in reply to gnasher729

    Actually that's incorrect. The early Christians purposely set Sunday as a day of celebration of Christ's rising, and explicit rejection of the need to honor the Jewish Shabbat (which runs from sunset Friday to sunset Saturday), demonstrating that the rules of the Old Testament were no longer controlling. As Christ said, "The law was made for man, not man for the law, the Sabbath was made for man, not man for the Sabbath".

  • Almafuerte (unregistered) in reply to ubersoldat

    TRWTF is using Java.

  • Almafuerte (unregistered) in reply to Gary B

    Actually, that is incorrect. The law was made by man, just like christ, god, the shabbat, the old testament, and every other crackpottery you just mentioned where created by man.

    We're talking about technology here. The imagination of a group of jews ~1800 years ago has nothing to do with anything.

  • abcdefg (unregistered) in reply to faoileag

    a unit test would be useful.

  • Friedrice The Great (unregistered) in reply to cellocgw
    cellocgw:
    Zylon:
    [image]

    MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY

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

    Had a rather gloomy friend who used these day names all the time: FIRST MONDAY SECOND MONDAY THIRD MONDAY FOURTH MONDAY FIFTH MONDAY

  • Norman Diamond (unregistered) in reply to OldCoder
    OldCoder:
    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.

    int actually works rather well for old calendar weeks. Day 1, day 2, ..., day 10. Some villages are still named for which day of the week they had their market day, for example Fifth Day Market town in Tokyo, and Fourth Day Market and Tenth Day Market in other prefectures.

  • Failing (unregistered)

    Welcome to the Daily Wednesday Thursday Friday.

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

    According to this list, the majority of countries actually defines Monday as the starting day (add both sections of Sunday start vs both sections of Monday start).

    If you weigh by population, Sunday might still win because you have China, India and the US in there.

  • just me (unregistered) in reply to chubertdev
    chubertdev:
    And now "end" is the opposite of "end." Awesome. We're brilliant here.

    yes, I'm being pedantic, but I'm no less deconstructive than the other comments here

    The beginning is the end is the beginning

  • EuroGuy (unregistered)

    I like how code that is not tested to work in leap years was still committed. After all, only 25% of years are leap years, who cares about those?

  • Paul (unregistered)

    All rejoice then, in the new 'java.time' package in Java 1.8.

    Maybe.

  • Alex (unregistered) in reply to Coyne

    [quote user="Coyne"][quote user="someguy"][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, this is a subtle point that has led to the creation of the religion known as Seventh-Day Adventists. The idea is that the Jewish tradition actually holds Saturday as the day of rest, and due to some date issues with Christ's rising the early Christian church decided that Sunday was a more memorable day than Saturday. In one of the Gospels there's a bit about how on that day "It was then the first day of the week." Add that to the dating of Easter Sunday on... well... Sunday and you get that at the time of writing, Sunday was considered the first day of the week.[/quote]

    Just an addendum: Jewish tradition holds that Saturday is the day of rest because it is the weekly anniversary of the seventh day of creation, on which the creator rested.[/quote]

    Of course the real reason why the day of worship was moved to Sunday is that Romans literally worshiped the Sun on Sundays, and it was pretty much impossible to convince new Christians to forgo their flashy Sunday rituals for the boring Sabbath, so the practical minds at the church thought they could keep the 4th commandment while attracting new converts by merging both celebrations.

    For bonus trivia points: a similar reason explains why Jesus' birthday was declared to coincide with the winter solstice.

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

    She is doing well, but her dates keep getting messed up...

  • SztupY (unregistered) in reply to geocities

    TRWTF that according to that list Hungary is broken on Windows 2k (Wednesday as the first day? come on...)

    On the other hand Monday in Hungarian (hétfő) actually means the "head of the week".

  • bambam (unregistered) in reply to EuroGuy
    EuroGuy:
    I like how code that is not tested to work in leap years was still committed. After all, only 24.25% of years are leap years, who cares about those?
    FTFY

    Centuries not evenly divisible by 400 are not leap years.

  • Bill C. (unregistered) in reply to DB
    DB:
    Dario:
    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.
    She is doing well, but her dates keep getting messed up...
    At least that's better than her father getting messed up. In my case, my date got messed up.
  • Krzysiek (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'

    OK, so TRWTF is numbering days beginning from 1 instead of holy 0 ;-)

Leave a comment on “Nine Ways to Tuesday”

Log In or post as a guest

Replying to comment #:

« Return to Article