- 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
<FONT face="Courier New" size=2>that's not "caching".</FONT>
Admin
I don't think anyone's mentioned it, but the odd indenting suggests to me server side scripting. Why you would mix server and client scripts in this way is still a WTF (javascript for the month and day, but PHP or whatever for the year? WTF??), but I thought it deserved mentioning.
Admin
They are not claiming that it's a last update date. They merely display current time of a client's system. Not an unusual occurance on the web, but it is kind of pointless.
Admin
Er, you mean the Y2.1K people?
Admin
Read the code again and if you still don't agree keep reading it until you understand what it is doing.
Admin
The real WTF is that a language created in the late 1990s has the Y2K bug built into its API.
Admin
I was refering to http://www.netcoast.nl/. Their JS doesn't have document.write("Last Update:");
Admin
That's why Alex should stop posting JS WTFs. JS stopped being funny in 1999.
Admin
Hmmm... allow me to quote from the ECMA spec...
-- begin quote --
B.2.4 Date.prototype.getYear ( )
NOTE
The getFullYear method is preferred for nearly all purposes, because it avoids the “year 2000
problem.”
When the getYear method is called with no arguments the following steps are taken:
1. Let t be this time value.
2. If t is NaN, return NaN.
3. Return YearFromTime(LocalTime(t)) - 1900.
-- end quote --
There's no Y2K bug here. You can get the full year via d.getYear() + 1900 under all circumstances. Or you can get the two-digit year via d.getYear() % 100.
Of course, getFullYear() is preferable.
Admin
Not quite -- JScript in MSIE will return a four-digit year when you use getYear() on dates after December 31, 1999. (Non-standard, yes, but done on purpose to automagically fix customer-created bugs. Of course, that does little to help the folks who used getYear() correctly in the first place.)
Admin
OMG...
And also on dates before 1/1/1900, too, it seems...
IE:
j a v a s c r i p t: alert(new Date("1/1/1899").getYear()) // 1899
j a v a s c r i p t: alert(new Date("1/1/1900").getYear()) // 0
j a v a s c r i p t: alert(new Date("1/1/1999").getYear()) // 99
j a v a s c r i p t: alert(new Date("1/1/2000").getYear()) // 2000
Firefox / Standard:
j a v a s c r i p t: alert(new Date("1/1/1899").getYear()) // -1
j a v a s c r i p t: alert(new Date("1/1/1900").getYear()) // 0
j a v a s c r i p t: alert(new Date("1/1/1999").getYear()) // 99
j a v a s c r i p t: alert(new Date("1/1/2000").getYear()) // 100
I have to consider that a bug in IE.
Admin
You assumed I was referring to ECMAScript. The ECMAScript specification is an after-the-fact attempt to standardize Netscape's JavaScript (nee LiveScript) and Microsoft's JScript. As others have pointed out, these two languages behave differently from each other relative to the Date.getYear() method.
The fact remains that some idiot at Netscape thought it was a grand idea to have Date.getYear() return a two digit year. Pick your poison: either they 1) built the Y2K bug in and came up with the (year - 1900) thing later after realizing what dolts they were or 2) thought that a method returning (year - 1900) called getYear() was much more useful than a getYear() method that returns the year unmolested. So if you like your useful values linearly translated by constants guaranteed to be useless in less than 10 years, this is the language for you!
If you are still not convinced that this is a WTF, please write some JS meeting the following requirements:
Does something easily recognizable as useful to a viewer of a web page
Uses Date.getYear() as in the ECMAScript specification (not the JScript version (see, I'm not even asking for cross-browser compatibility))
Doesn't use the magic number 1900 either directly or indirectly (i.e., 191010 is out)
Applies Date.getYear() to the current date
Works the same no matter what century it is
Could not be simplified or unobfuscated via the use of Date.getFullYear()
Good luck.
Cool -- the CAPTCHA was "zork".
Admin
Search for writedate in the following link: http://www.conzz.com/jsLibrary.txt
Looks to me like someone snagged the code, couldn't figure out how to do 4-digit years and hardcoded it.
Admin
I agree it's a WTF. I disagree that it's a bug, though. You should see some of the C time-handling functions. For example, months go from 0 to 11, but days-in-the-month go from 1 to 31. Just have to get used to it.
But, anyway...
var today = getDate();
document.write("Welcome to TheDailyWTF, '" + (today.getYear() % 100) + " edition");
Admin
I'm betting that they employed a highly paid "Search Engine Optimiser" to do this for them - if you don't have new content, fake it, right?
Admin
document.write("Last Update: " + document.lastModified);
Admin
This isn't really a WTF, it's just code written by a very pessimistic individual.
Admin
Fails requirement #6.
Also, this would print out "Welcome to TheDailyWTF, 5 edition" this year and "Welcome to TheDailyWTF, 0 edition" in 2000.
Furthermore I'm going to say it fails #5 because as the year changes century, the edition goes backwards.
In case you failed to notice, ECMAScript (and Netscape JavaScript and JScript) have the same issues with Date.getDate() and Date.getMonth() that you accuse C of having. (BTW, I love the fact we have a Date.getDate() method. And don't get me started on Date.getDay() vs Date.getDate().)
Admin
Most hilarious part of the site:
Admin
Condensing the above: Just because it's a spec doesn't mean it isn't stupid. This is why all browsers have extensions and non-conforming areas. (Netscape had a golden opportunity when rejigging mozilla to let the old moronic definition go and embrace IE's less brain-damaged interpretation, but they blew it. Maybe pique, maybe just a slavish adherence to specs good or bad.)
Admin
That site's beautiful, really. A WTF in its own regard.
Admin
Man, who wrote this forum software? It's surely eligible for the front page! Sorry everyone.
Admin
Uh, no. If I define and publish an API, I'd sure as hell better go out of my way to ensure that it continues to operate the way I defined it indefinitely. If getYear() was defined as returning the difference between the year of the date stored in the Date object and 1900, then it had better continue to do that for as long as the language exists. That's why getFullYear() was added to the language -- so one could make use of a "less brain-damaged" method without forcing anybody to change working, spec-compliant code currently in production.
Admin
FYI - here is the latest version, two years after the original. From http://www.netcoast.nl/:
<font size="-7" color="#0066FF"> <script language="JavaScript">var now = new Date();
var dayName = now.getDay() +1; var dayNumber = now.getDate(); var monthName = now.getMonth() + 1;
if(dayName==1) Day = "Sunday"; if(dayName==2) Day = "Monday"; if(dayName==3) Day = "Tuesday"; if(dayName==4) Day = "Wednesday"; if(dayName==5) Day = "Thursday"; if(dayName==6) Day = "Friday"; if(dayName==7) Day = "Saturday";
if(monthName==1) Month="Jan."; if(monthName==2) Month="Feb."; if(monthName==3) Month="Mar."; if(monthName==4) Month="Apr."; if(monthName==5) Month="May"; if(monthName==6) Month="Jun."; if(monthName==7) Month="Jul."; if(monthName==8) Month="Aug."; if(monthName==9) Month="Sept."; if(monthName==10) Month="Oct."; if(monthName==11) Month="Nov."; if(monthName==12) Month="Dec.";
document.open(); document.write( Day + ", " + dayNumber + " " + Month);
</script>Admin
Someone should have mercy, hack the site and fix it. It hurts me to see that it is still a real WTF after 4 years. :-( Tonight, I'm gonna cry because of things like this ...