![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
10) { |
#2
| |||
| |||
|
|
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. |
#3
| ||||
| ||||
|
|
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. |
|
var yearA = new Array(); .... for(var i=0;i<10;i++) { yearA[i]=gy(i); } |
|
function gy(num) { var mydate = new Date(); return (eval(mydate.getYear()) - 4 + num); } |
|
function gm(num) { var mydate = new Date(); mydate.setDate(1); mydate.setMonth(num-1); var datestr = "" + mydate; return datestr.substring(4,7); |
#4
| |||
| |||
|
|
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. |
#5
| |||
| |||
|
|
effendi (AT) epitome (DOT) com.sg (Fendi Baba) writes: Please don't make your post unreadable without the subject. The body should be self contained. [Can anyhelp me, what does this javascript calendar give error for dates before year 2000?] The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. I have a pretty good idea, but the code is generally so lousy that I would consider scrapping it and starting over. I am sure whatever it is doing can be done shorter, smarter, and less error prone (taking the numerous occurences of "eval" as a clear sign of an programmer that doesn't know the language very well). Anyway: var yearA = new Array(); ... for(var i=0;i<10;i++) { yearA[i]=gy(i); } This fills an array with ten years. function gy(num) { var mydate = new Date(); return (eval(mydate.getYear()) - 4 + num); } For arguments between 0 and 9 (as it is called above), this function returns values between 2000 and 2009 (generally, current year - 4 and forward). As a side note, the call to eval does nothing here, except transform a number to a string and parse it as an expression to get the number back ... huge overhead for nothing. So, your table only contains years between 2000 and 2009. I guess you'll get errors for dates after 2009 too. function gm(num) { var mydate = new Date(); mydate.setDate(1); mydate.setMonth(num-1); var datestr = "" + mydate; return datestr.substring(4,7); This line stood out as particulary fragile. You can not assume anything about the format of the string representation of a date. In my browser, the above function gives: gm(4) == " 01" That is the date set to 1, not the month. Consider using another script. It'll be easier than patching up this one. /L |
#6
| |||
| |||
|
|
effendi (AT) epitome (DOT) com.sg (Fendi Baba) writes: Please don't make your post unreadable without the subject. The body should be self contained. [Can anyhelp me, what does this javascript calendar give error for dates before year 2000?] The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. I have a pretty good idea, but the code is generally so lousy that I would consider scrapping it and starting over. I am sure whatever it is doing can be done shorter, smarter, and less error prone (taking the numerous occurences of "eval" as a clear sign of an programmer that doesn't know the language very well). Anyway: var yearA = new Array(); ... for(var i=0;i<10;i++) { yearA[i]=gy(i); } This fills an array with ten years. function gy(num) { var mydate = new Date(); return (eval(mydate.getYear()) - 4 + num); } For arguments between 0 and 9 (as it is called above), this function returns values between 2000 and 2009 (generally, current year - 4 and forward). As a side note, the call to eval does nothing here, except transform a number to a string and parse it as an expression to get the number back ... huge overhead for nothing. So, your table only contains years between 2000 and 2009. I guess you'll get errors for dates after 2009 too. function gm(num) { var mydate = new Date(); mydate.setDate(1); mydate.setMonth(num-1); var datestr = "" + mydate; return datestr.substring(4,7); This line stood out as particulary fragile. You can not assume anything about the format of the string representation of a date. In my browser, the above function gives: gm(4) == " 01" That is the date set to 1, not the month. Consider using another script. It'll be easier than patching up this one. /L |
![]() |
| Thread Tools | |
| Display Modes | |
| |