• Mayan (unregistered)

    FOOLS!!!! BWAAHAHAHA!!!

    (FRIST)

  • (cs)

    Unless, of course, you're using the Ethopian Calendar.

    http://www.tourismethiopia.org/

  • (cs)

    I used to write functions like that, but then I took an arrow in the knee.

  • (cs)

    Or if some fool changes the number of months in the calendar. Then it'll be inaccurate for the new years...or the old.

  • (cs)
  • (cs)

    Lousy Smarch weather!

  • (cs) in reply to zelmak
    zelmak:
    inb4 lame comment about how lame linking to xkcd is.

  • Carl (unregistered)

    I'm shocked! Shocked, I tell you. Daily WTFs two days in a row!

    I was expecting more time to work on my clever comment. Now, all I have is this.

  • (cs)

    There are calendars where the number of months changes from year to year. The Jewish calendar roughly alternates between 12 and 13 in order to synchronize between the cycle of new moons and the solar year.

    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.

    Not really related, but amusing: http://www.improbable.com/2011/10/14/ig-nobel-winner-writes-best-abstract-ever/. Best scientific abstract ever.

  • AP2 (unregistered)

    Well, this code is obviously buggy; it didn't work at Kodak.

  • (cs)

    One can only assume there is a function somewhere to set the selected year. I'll bet it looks something like this:

    function setSelectedYear(year)
    {
    }
    
    
  • (cs) in reply to zelmak
    zelmak:
    That's, uhhh.... not really applicable here. You fail.
  • some guy (unregistered) in reply to PedanticCurmudgeon
    PedanticCurmudgeon:
    zelmak:
    inb4 lame comment about how lame linking to xkcd is.

    nb4 lame comment on how lame it is to complain about xkcd lamely.

  • JH (unregistered)

    Plausible explanation: it implements an interface designed to support calendars with variable years.

    The "selected" year is an object field.

    In this implementation getMonthCountForSelectedYear() always returns 12.

    In some other implementation for some other calendar, it makes a decision depending on the year.

  • Joe (unregistered)

    function returnTwelve(){ return 12; }

  • MojoMonkeyfish (unregistered)
    #DEFINE TWELVE = 12;
    
    function getMonthCountForSelectedYear()
    {
      return TWELVE;
    }
    

    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.

  • (cs)

    Code fails to pass standards for following reason: "12 is a magic number". Suggest defining a named literal and assigning it the suitable value, then returning that name from this function.

    Edit: curse you MonkeyMojoFish for looking over my shoulder as I type!

  • MojoMonkeyfish (unregistered)

    Btw, why is twelve such a strange word to say and spell?

  • the beholder (unregistered) in reply to Kivi
    Kivi:
    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.
    Gee, why can't people ever be satisfied?
    function getMonthCountForSelectedYear(string strMonthName)
    {
      return 12;
    }
    There you go. Happy now?
  • Captain Obvious (unregistered)

    I can see it being useful for fiscal years - especially when they change when they occur.

    Of course, I'm not saying it's a WTF...but it's probably a WTF.

  • (cs) in reply to Zylon
    Zylon:
    zelmak:
    That's, uhhh.... not really applicable here. You fail.
    Agreed, xkcd is 'random' this is static. Even though I admit as soon as I saw the article xkcd was the first thing to come to mind.
  • WTF-land braver (unregistered) in reply to the beholder
    the beholder:
    Kivi:
    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.
    Gee, why can't people ever be satisfied?
    function getMonthCountForSelectedYear(string strMonthName)
    {
      return 12;
    }
    There you go. Happy now?
    Congratulations sir! Between the parameter that doesn't relate to what the function is supposed to do, the hungarian notation, and the use of string where int would be a more sensible choice you managed to escalate this WTF to a new level.

    I tip my hat to you now.

  • Perry (unregistered)
    It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped.
    sub getDaysInAnyGivenWeek {
      my ($date) = @_;
    

    get integer value of first day in week

    my $intStart = getIntegerValueOfFirstDayInWeek ($date);

    get integer value of last day in week

    my $intDone = getIntegerValueOfLastDayInWeek ($date);

    error checking left as an exercise for the reader

    return $intDone - $intStart; }

    (It's nested function calls all the way down!)

  • me (unregistered)

    #DEFINE POSSIBLE_MONTHS_IN_THE_YEAR;

    function getMonthCountForSelectedYear(aYear) { int year_counter = 0;

    year_counter = year_counter + 1;

    for (var i=1; i <= POSSIBLE_MONTHS_IN_THE_YEAR; i++) { year_counter++; }

    if (year_counter == 12) { return 12; } else { //hmmmm.... } }

    Who is askimet?

  • Ant (unregistered)
    Jon-Paul continues, "I particularly like the way you don't even have to pass in the selected year to still get the correct return value. It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped."
    Try asking the Samoans how many days there were last week!
  • Thayla (unregistered)

    If you're going with days in a week method what about hours in a day method, or minutes in an hour method.

    I'm not a particular fan of constants, because sometimes they are wrong. I've found constants like months = 12 before when it should clearly be 42.

  • Nagesh (unregistered)

    In al mune-base calanders, there is sometime being extra munth aded.

  • (cs) in reply to me
    me:
    Who is askimet?
    An evil, racist AI bent on stopping the dissemination of funny and/or applicable content.
  • Jack (unregistered) in reply to Kivi
    Kivi:
    ... the lack of a parameter to the function is highly suspicious.

    I would guess that the "selected year" is stored in a global variable somewhere (which may be a WTF itself) ... except that the submitter, who presumably knows the system pretty well, was also surprised/amused by the missing parameter.

  • Nagesh (unregistered)

    On years with extra munth, Hindu calander is requiring appropriate secrifise.

    [image]
  • You laugh, but... (unregistered) in reply to MojoMonkeyfish

    I seriously worked on a group project with someone in CS college who did that.

    #define FORTY 40 ... for(i=0; i < FORTY; i++) { ... }

    I DO like doing something like,

    #define MONTHS_PER_YEAR 12

    because then later when you see code like,

    for(m=0; m < 12; m++) { do_something(m); }

    versus

    for(m=0; m < MONTHS_PER_YEAR; m++) { do_something(m); }

    ...it is self documenting. "Oh, he's iterating over the months in the year."

  • usitas (unregistered) in reply to Kivi
    Kivi:
    There are calendars where the number of months changes from year to year. The Jewish calendar roughly alternates between 12 and 13 in order to synchronize between the cycle of new moons and the solar year.

    Not that that keeps this from being worse than failure though: the lack of a parameter to the function is highly suspicious.

    Not really related, but amusing: http://www.improbable.com/2011/10/14/ig-nobel-winner-writes-best-abstract-ever/. Best scientific abstract ever.

    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?

  • Jack (unregistered) in reply to MojoMonkeyfish
    MojoMonkeyfish:
    Btw, why is twelve such a strange word to say and spell?

    Well, it's a hold-over from an old base-12 number system. That's why it's its own word, instead of "twoteen," or "ten-two," or something. I believe it's the same reason we have the word "dozen," and there are 12 inches in a foot. That probably doesn't answer your question, though...

  • EatenByAGrue (unregistered) in reply to Ant
    Ant:
    Jon-Paul continues, "I particularly like the way you don't even have to pass in the selected year to still get the correct return value. It's such a shame this guy has left now as I need to write a function that calculates the number of days in any given week and he could've helped."
    Try asking the Samoans how many days there were last week!

    10, of course, if you ask the French Republicans.

  • Nagesh (unregistered)

    Many time year is having extra munth. I am on far left at last adhik mas festival.

    [image]
  • Jack (unregistered) in reply to usitas
    usitas:
    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?

    They almost universally DO use the Gregorian calendar for anything non-religious, don't they? What do you care how they decide when their holidays will be?

  • S&H IT (unregistered)

    To be fair, the Hebrew calendar sometimes has 13 months, depending on if it's a leap year. http://en.wikipedia.org/wiki/Hebrew_calendar#Names_of_months

  • EatenByAGrue (unregistered) in reply to usitas
    usitas:
    When are all these religions out there finally get it: we have a globally used calendar, and stop using all other junk that relate to non-existing mythological creatures such as the god (deliberately lowecase)?

    By a "globally used calendar", you're talking about the one with:

    • a 7-day week from Genesis
    • days named after Tyr, Odin, Thor, Frig, and Saturn
    • months named after Janus, Mars, Maia, Juno, and the deified Julius and Augustus Because that clearly in no way involves mythological creatures.

    The One True Calendar, though, is obvious: Start at UTC midnight on what is conventionally called Jan 1, 1970, and count the number of seconds (defined by cesium atoms) since then.

  • DMAA (unregistered)

    Here's a tip for Jon-Paul regarding the week-length function, although I don't know JavaScript very well. Check if the API has a firstDayOfWeek() and lastDayOfWeek() function, or some equivalent, then subtract the former from the latter, and add one.

    daysOfWeek = lastDayOfWeek(n) - firstDayOfWeek(n) + 1

    This also elegantly handles cases where there are days between weeks. Those would have incorrectly been counted if you used just firstDayOfWeek(n+1) - firstDayOfweek(n).

    This algorithm fails, however, for weeks that end before they start. You may want to do a Math.Abs()-equivalent to handle that.

    Of course, all this assumes roughly equal-length days (give or take a leap second). Should the last day's length approach 0, you may want to leave out the final "+ 1".

    Hope this helps. In case you need more assistance, I can send you a library with thousands of important numerical constants for date calculations, from ONE through EIGHTYSIXTHOUSANDFOURHUNDRED and many more.

  • Anonymous Guy (unregistered)

    there you go:

    function getDayCountForSelectedWeek() {

    return 6;

    return 7; }

  • Anonymous Guy (unregistered) in reply to Anonymous Guy
    Anonymous Guy:
    there you go:

    function getDayCountForSelectedWeek() {

    return 6;

    return 7; }

    that was supposed to be a // not a # :)

    showed that if this guy had written one perhaps he would have prepared the week days go down to 6 :)

  • Will (unregistered)
    function isDaysCommentFunny (today) {
      return "no"
    }
  • undefined (unregistered) in reply to MojoMonkeyfish
    MojoMonkeyfish:
    #DEFINE TWELVE = 12;
    

    function getMonthCountForSelectedYear() { return TWELVE; }

    There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.

    I like JavaScript and plain C mixed together.

  • (cs)

    I asked my wife, and she definitively told me that you will be much happier in life if all your periods have 28 day cycles.

    I never argue with my wife because she is always right (she told me so)!

  • dlevy (unregistered)

    The function should really have a parameter for "planet" in case the code is exported.

  • Foobar (unregistered) in reply to MojoMonkeyfish

    "Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

    Now you know.

  • geoffrey (unregistered)

    Had the code's author used the number 12, Jon-Paul would have thrown the silly programmer "magic number" pet peeve out there. Had the author defined it in a constant, Jon-Paul would have lamented its lack of flexibility. Here he goes, makes it easy to read, and easy to change, and he still gets submitted to this site. Unbelievable.

  • (cs) in reply to me
    me:
    #DEFINE POSSIBLE_MONTHS_IN_THE_YEAR;

    Who is askimet?

    Imet is the guy who wrote the code, I think he is a friend of Nagesh... Go ask him.

  • Pham Nuwen (unregistered) in reply to EatenByAGrue
    EatenByAGrue:
    The One True Calendar, though, is obvious: Start at UTC midnight on what is conventionally called Jan 1, 1970, and count the number of seconds (defined by cesium atoms) since then.
    I'm Programmer-Archaeologist Pham Nuwen, and I approve of this message.
  • J.R.R. Trollkein (unregistered) in reply to Foobar
    Foobar:
    "Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

    Now you know.

    This makes perfect sense.

    Good thing we didn't anger the dwarves. Counting "Ten, Eleven, Twarf" would just be silly.

Leave a comment on “Nondeterministic Months”

Log In or post as a guest

Replying to comment #:

« Return to Article