Comment On Nondeterministic Months

"There's been a lot of talk that 2012 will exclude the month of December," writes Jon-Paul Murrow, "you know, end of world, Mayan calendar, Nostradamus, and all that. Even if this doesn't happen, there's no guarantee that future years will have twelve months." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Nondeterministic Months

2012-01-05 12:02 • by Mayan (unregistered)
FOOLS!!!!
BWAAHAHAHA!!!

(FRIST)

Re: Nondeterministic Months

2012-01-05 12:06 • by ContraCorners
Unless, of course, you're using the Ethopian Calendar.

http://www.tourismethiopia.org/

Re: Nondeterministic Months

2012-01-05 12:09 • by Mason Wheeler
I used to write functions like that, but then I took an arrow in the knee.

Re: Nondeterministic Months

2012-01-05 12:09 • by Coyne
Or if some fool changes the number of months in the calendar. Then it'll be inaccurate for the new years...or the old.

Re: Nondeterministic Months

2012-01-05 12:15 • by zelmak

Re: Nondeterministic Months

2012-01-05 12:16 • by PedanticCurmudgeon
Lousy Smarch weather!

Re: Nondeterministic Months

2012-01-05 12:17 • by PedanticCurmudgeon
371120 in reply to 371118
zelmak:
inb4 lame comment about how lame linking to xkcd is.

Re: Nondeterministic Months

2012-01-05 12:17 • by 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.

Re: Nondeterministic Months

2012-01-05 12:19 • by 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.

Re: Nondeterministic Months

2012-01-05 12:20 • by AP2 (unregistered)
Well, this code is obviously buggy; it didn't work at Kodak.

Re: Nondeterministic Months

2012-01-05 12:21 • by frits
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)

{
}

Re: Nondeterministic Months

2012-01-05 12:22 • by Zylon
371125 in reply to 371118
zelmak:

That's, uhhh.... not really applicable here. You fail.

Re: Nondeterministic Months

2012-01-05 12:22 • by some guy (unregistered)
371126 in reply to 371120
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.

Re: Nondeterministic Months

2012-01-05 12:27 • by 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.

Re: Nondeterministic Months

2012-01-05 12:29 • by Joe (unregistered)
function returnTwelve(){
return 12;
}

Re: Nondeterministic Months

2012-01-05 12:31 • by 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.

Re: Nondeterministic Months

2012-01-05 12:31 • by da Doctah
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!

Re: Nondeterministic Months

2012-01-05 12:31 • by MojoMonkeyfish (unregistered)
Btw, why is twelve such a strange word to say and spell?

Re: Nondeterministic Months

2012-01-05 12:34 • by the beholder (unregistered)
371132 in reply to 371122
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?

Re: Nondeterministic Months

2012-01-05 12:37 • by 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.

Re: Nondeterministic Months

2012-01-05 12:40 • by Anketam
371134 in reply to 371125
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.

Re: Nondeterministic Months

2012-01-05 12:42 • by WTF-land braver (unregistered)
371135 in reply to 371132
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.

Re: Nondeterministic Months

2012-01-05 12:45 • by 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!)

Re: Nondeterministic Months

2012-01-05 12:46 • by 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?

Re: Nondeterministic Months

2012-01-05 12:49 • by 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!

Re: Nondeterministic Months

2012-01-05 12:51 • by 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.

Re: Nondeterministic Months

2012-01-05 12:54 • by Nagesh (unregistered)
In al mune-base calanders, there is sometime being extra munth aded.

Re: Nondeterministic Months

2012-01-05 12:58 • by C-Octothorpe
371141 in reply to 371137
me:
Who is askimet?
An evil, racist AI bent on stopping the dissemination of funny and/or applicable content.

Re: Nondeterministic Months

2012-01-05 12:59 • by Jack (unregistered)
371142 in reply to 371122
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.

Re: Nondeterministic Months

2012-01-05 13:02 • by Nagesh (unregistered)
On years with extra munth, Hindu calander is requiring appropriate secrifise.

Re: Nondeterministic Months

2012-01-05 13:03 • by You laugh, but... (unregistered)
371144 in reply to 371129
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."

Re: Nondeterministic Months

2012-01-05 13:03 • by usitas (unregistered)
371145 in reply to 371122
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)?

Re: Nondeterministic Months

2012-01-05 13:04 • by Jack (unregistered)
371146 in reply to 371131
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...

Re: Nondeterministic Months

2012-01-05 13:08 • by EatenByAGrue (unregistered)
371148 in reply to 371138
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.

Re: Nondeterministic Months

2012-01-05 13:08 • by Nagesh (unregistered)
Many time year is having extra munth. I am on far left at last adhik mas festival.

Re: Nondeterministic Months

2012-01-05 13:09 • by Jack (unregistered)
371150 in reply to 371145
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?

Re: Nondeterministic Months

2012-01-05 13:16 • by 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

Re: Nondeterministic Months

2012-01-05 13:17 • by EatenByAGrue (unregistered)
371152 in reply to 371145
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.

Re: Nondeterministic Months

2012-01-05 13:18 • by 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.

Re: Nondeterministic Months

2012-01-05 13:26 • by Anonymous Guy (unregistered)
there you go:

function getDayCountForSelectedWeek()
{
# return 6;
return 7;
}

Re: Nondeterministic Months

2012-01-05 13:28 • by Anonymous Guy (unregistered)
371155 in reply to 371154
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 :)

Re: Nondeterministic Months

2012-01-05 13:46 • by Will (unregistered)
function isDaysCommentFunny (today) {

return "no"
}

Re: Nondeterministic Months

2012-01-05 13:55 • by undefined (unregistered)
371157 in reply to 371129
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.

Re: Nondeterministic Months

2012-01-05 14:01 • by snoofle
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)!

Re: Nondeterministic Months

2012-01-05 14:02 • by dlevy (unregistered)
The function should really have a parameter for "planet" in case the code is exported.

Re: Nondeterministic Months

2012-01-05 14:04 • by Foobar (unregistered)
371160 in reply to 371131
"Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.

Now you know.

Re: Nondeterministic Months

2012-01-05 14:18 • by 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.

Re: Nondeterministic Months

2012-01-05 14:21 • by Silfax
371162 in reply to 371137
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.

Re: Nondeterministic Months

2012-01-05 14:23 • by Pham Nuwen (unregistered)
371163 in reply to 371152
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.

Re: Nondeterministic Months

2012-01-05 14:26 • by J.R.R. Trollkein (unregistered)
371164 in reply to 371160
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.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment