This is a story about my trying to print a date using javascript.
I was working on an ajax component and had to display a date in the following
format: YYYY.MM.DD.
First of all js (javascript) doesn't supply a formating method. At least
I didn't find one.
Then I tried to get the months using the js method Date.getMonth().
It comes out that the months are in the range 0-11, and not 1-12 as
expected. WTF?
After that I try to print the day, logically using the Date.getDay(). Wrong.
The getDay() returns the day of the week (0=Sunday, 6=Saturday). I read
a little more. The correct method is Date.getDate(). I expect the range
0-30, again wrong. The range is 1-31. Go figure...
Then I try to print the year. Again a surprise. Years before the year
2000 are returned in a two-digit format. The year 1997 is returned as
97. And the biggest problem there is that the js calendar (a fancy
js thing that we use to choose a date) sees 97 as the year 97
and not 1997. Crazy!
JavaScript sucks. Sucks big time.
How about a good naming convention?
And if you think java is better, look at this:
If you have a java.util.Calendar object and want to see the time in
milliseconds since the start of the Era (00:00:00 01.01.1970) you have
to write this:
calendar.getTime().getTime()
\________________/
returns a Date
\__________________________/
returns a long
Does this look clean or neat? Would it be clear if I didn't tell you
what it did? For me - not really.
Again, how about a good naming convention.
And don't even get me started on inline conditionals - in java and in
javascript they have different priority. Again: go figure... One has to
put extra brackets just to make sure.