Version: (using KDE KDE 3.3.2) Installed from: Gentoo Packages Compiler: gcc version 3.3.5 OS: Linux this javaScript will check if a date entered is a Saturday or a Sunday. It will work correctly in gecko or IE based browsers but returns a NaN (I am assuming Not a Number) in Konqueror. It gets its values from a form. The user will enter in a month day and year (all in separate drop-down boxes) This is the code on the page: //Check if the date entered is a saturday or sunday var month_index = form.month.selectedIndex; var month = form.month.options[month_index].text; var day_index = form.day.selectedIndex; var day = form.day.options[day_index].text; var year_index = form.year.selectedIndex; var year = form.year.options[year_index].text; var d=new Date(month + day + "," + year); var day_of_week = d.getDay(); if ((day_of_week == 6) || (day_of_week == 0)) { alert("You have chosen a date on the weekend"); form.day.focus(); return (false); }
I guess the form is the key here. getDay() works fine for me. What does "d" show for you?
d shows 'Invalid Date' in konqueror d shows 'Sat Jan 29 2005 00:00:00 GMT -0500 (Eastern Standard Time)' in Firefox Same form, same server, same exact input on the form
> ------- d shows 'Invalid Date' in konqueror > > d shows 'Sat Jan 29 2005 00:00:00 GMT -0500 (Eastern Standard Time)' in > Firefox > > Same form, same server, same exact input on the form So the problem is in the construction of the Date object. What is the exact text passed into "new Date()"?
each variable ends up as follows month: January Day: 29 Year: 2005 so... d should end up looking like: new Date(January + 29 + "," + 2005); this is where the problem is. I suppose it happens when the variables are attached together using the + sign.
On Thursday 27 January 2005 22:27, trpn@myrealbox.com wrote: > ------- each variable ends up as follows > > month: January > Day: 29 > Year: 2005 > > so... > > d should end up looking like: new Date(January + 29 + "," + 2005); > > this is where the problem is. I suppose it happens when the variables are > attached together using the + sign. So the real testcase is: d = new Date("January29,2005"); if (d.getDay() == NaN) { // failed } Mozilla is capable of parsing this date while KJS is not?
On January 27, 2005 10:42 pm, George Staikos wrote: > So the real testcase is: > > d = new Date("January29,2005"); > if (d.getDay() == NaN) { > // failed > } > > Mozilla is capable of parsing this date while KJS is not? That would be correct. Actually after looking at it I do not think that is proper code d = new Date("January29,2005"); should be: d = new Date("January 29, 2005"); changing the actual code to: d=new Date(month + " " + day + ", " + year) works...... I guess this is not a bug but rather kjs is not picking up user error while mozilla and IE are.
CVS commit by porten: parse date strings like "Apr17,2005" BUGS:98027 M +2 -0 ChangeLog 1.62 M +5 -0 date_object.cpp 1.97 --- kdelibs/kjs/ChangeLog #1.61:1.62 @@ -1,4 +1,6 @@ 2005-04-17 Harri Porten <porten@kde.org> + * date_object.cpp: parse date strings like "Apr17,2005" + * function.cpp: don't produce a null string result on unescape("") (spotted in the JSC ChangeLog) --- kdelibs/kjs/date_object.cpp #1.96:1.97 @@ -789,4 +789,9 @@ double KJS::KRFCDate_parseDate(const USt dateString++; } + // missing delimiter between month and day (like "January29")? + if (month == -1 && dateString && wordStart != dateString) { + month = findMonth(wordStart); + // TODO: emit warning about dubious format found + } while(*dateString && isspace(*dateString))
You need to log in before you can comment on or make changes to this bug.