- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
FOOLS!!!! BWAAHAHAHA!!!
(FRIST)
Admin
Unless, of course, you're using the Ethopian Calendar.
http://www.tourismethiopia.org/
Admin
I used to write functions like that, but then I took an arrow in the knee.
Admin
Or if some fool changes the number of months in the calendar. Then it'll be inaccurate for the new years...or the old.
Admin
Obligatory XKCD reference
H8 akismet
Admin
Lousy Smarch weather!
Admin
Admin
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.
Admin
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.
Admin
Well, this code is obviously buggy; it didn't work at Kodak.
Admin
One can only assume there is a function somewhere to set the selected year. I'll bet it looks something like this:
Admin
Admin
nb4 lame comment on how lame it is to complain about xkcd lamely.
Admin
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.
Admin
function returnTwelve(){ return 12; }
Admin
There, I fixed it. Totally didn't account for twelve changing. Could have been a real pain in the butt.
Admin
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!
Admin
Btw, why is twelve such a strange word to say and spell?
Admin
Admin
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.
Admin
Admin
I tip my hat to you now.
Admin
Admin
#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?
Admin
Admin
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.
Admin
In al mune-base calanders, there is sometime being extra munth aded.
Admin
Admin
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.
Admin
On years with extra munth, Hindu calander is requiring appropriate secrifise.
[image]Admin
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."
Admin
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)?
Admin
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...
Admin
10, of course, if you ask the French Republicans.
Admin
Many time year is having extra munth. I am on far left at last adhik mas festival.
[image]Admin
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?
Admin
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
Admin
By a "globally used calendar", you're talking about the one with:
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.
Admin
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.
Admin
there you go:
function getDayCountForSelectedWeek() {
return 6;
return 7; }
Admin
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 :)
Admin
Admin
I like JavaScript and plain C mixed together.
Admin
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)!
Admin
The function should really have a parameter for "planet" in case the code is exported.
Admin
"Twelve" is so strange because it is a word invented by elves. It is a subtle fairy revenge against the English.
Now you know.
Admin
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.
Admin
Imet is the guy who wrote the code, I think he is a friend of Nagesh... Go ask him.
Admin
Admin
Good thing we didn't anger the dwarves. Counting "Ten, Eleven, Twarf" would just be silly.