Date Validation for 3 Dropdowns!?
|
|
Thread rating:  |
Ash - 25 Apr 2005 10:55 GMT Hi everyone,
This problem has been puzzling me for a fair time now, and has severely frustrated me!! Perhaps I'm just not getting the syntax right, but the problem is rather simple...
Take a look at: http://www.gasthofreiner.com/
The small booking form on the left, we're using the same one, but we need to add javascript validation to ensure the following...
- That a date cannot be selected thats in the past - That an invalid date cannot be selected, i.e. Feb 30th
I would also like it if when you make a selection in the first box, it mirrors it to the second, but perhaps a day later? I think this may be a little tricky?
REALLY appreciate anyones help, I've tried so many scripts, and just cannot get one working.
Cheers, Ash
Ash - 25 Apr 2005 11:06 GMT Actually, here's the lump of javascript that the form uses, you can see some Javascript that I tried to make sure one date wasn't before the other...but it didn't work!?
------------
<SCRIPT language="JavaScript" TYPE="text/javascript"> function doCheckAvail(){ if(validateFields()){ var form = document.myForm;
//collect your screen data var arrDay = form.ARRIVAL_DAY.value; var arrMon = form.ARRIVAL_MONTH.value; var arrYear = form.ARRIVAL_YEAR.value; var depDay = form.DEPARTURE_DAY.value; var depMon = form.DEPARTURE_MONTH.value; var depYear = form.DEPARTURE_YEAR.value; var adult = form.ADULTS.value; var child = form.CHILDREN.value;
var chainCode = "vones"; var hotelCode = "<%= TheHotelCode %>"; var email = "<%= TheHotelEmail %>"; var website = "http%3a%2f%2fwww.<%= TheHotelWebsite %>"; var barServer = "https://agent.synxis.com/bar/BarServlet?selector=Login";
//start creating the url var url = barServer+ "&cid="+chainCode+ //your chain code "&hid="+hotelCode+ //your hotel code "&hea="+email+ //your hotel contact email "&url="+website+ //your hotel website "&locale=en_GB"+ //the locale you are in "&checkAvailability=true"+ //alerts that you are going to the room page "&bam="+arrMon+ //arrival month "&bad="+arrDay+ //arrival day "&bay="+arrYear+ //arrival year "&bdm="+depMon+ //departure month "&bdd="+depDay+ //departure day "&bdy="+depYear+ //departure year "&noa="+adult+ //# of adults "&noc="+child; //# of children
//now pop-up the new window with this url. document.location = url; // window.open(url, "BAR", "width=778,height=600,status=yes,resizable=yes,scrollbars=yes"); } else{ alert("You must enter valid information"); } }
function validateFields() {
// ASH: Concatenate the two dates into single variables - OR AT LEAST TRY!!! // var form = document.myForm;
// var arrDay = parseInt(form.ARRIVAL_DAY.value); // var arrMon = parseInt(form.ARRIVAL_MONTH.value); // var arrYear = parseInt(form.ARRIVAL_YEAR.value); // var depDay = parseInt(form.DEPARTURE_DAY.value); // var depMon = parseInt(form.DEPARTURE_MONTH.value); // var depYear = parseInt(form.DEPARTURE_YEAR.value);
// var TheFromDate = arrDay+"/"+arrMon+"/"+arrYear // var TheToDate = depDay+"/"+depMon+"/"+depYear
// if (TheFromDate) > (TheToDate) { // alert('The Date of Arrival must be prior to the Date of Departures') // alert(TheFromDate+" & "+TheToDate) // }
return true; }
</SCRIPT>
Michael Winter - 25 Apr 2005 12:20 GMT > Actually, here's the lump of javascript that the form uses, [...] Rather than using that code to create the submission, why don't you just submit the form properly?
function isValidDate(dt, y, m, d) { return (y == dt.getFullYear()) && (m == dt.getMonth()) && (d = dt.getDate()); }
function isValidSubmission(form) { var elem = form.elements, now = new Date(), y, m, d, arr, dep;
arr = new Date( y = +elem.bay.value, m = elem.bam.value - 1, d = +elem.bad.value ); if(!isValidDate(arr, y, m, d)) { /* Arrival date is not valid. */ return false; } if(arr <= now) { /* Arrival date is before today. */ return false; }
dep = new Date( y = +elem.bdy.value, m = elem.bdm.value - 1, d = +elem.bdd.value ); if(!isValidDate(dep, y, m, d)) { /* Departure date is not valid. */ return false; } if(dep < arr) { /* Departure date is before arrival date. */ return false; } return true; }
<form method="get" action="https://agent.synxis.com/bar/BarServlet?selector=Login" onsubmit="return isValidSubmission(this);"> <input name="cid" type="hidden" value="vones"> <input name="hid" type="hidden" value="<%= TheHotelCode %>"> <input name="hea" type="hidden" value="<%= TheHotelEmail %>"> <input name="url" type="hidden" value="http://www.<%= TheHotelWebsite %>"> <input name="locale" type="hidden" value="en_GB"> <input name="checkAvailability" type="hidden" value="true"> <input name="noc" type="hidden" value="0">
<!-- Arrival month --> <select name="bam" size="1"> <!-- ... --> </select> <!-- Arrival day --> <select name="bad" size="1"> <!-- ... --> </select> <!-- Arrival year --> <select name="bay" size="1"> <!-- ... --> </select>
<!-- Departure month --> <select name="bdm" size="1"> <!-- ... --> </select> <!-- Departure day --> <select name="bdd" size="1"> <!-- ... --> </select> <!-- Departure year --> <select name="bdy" size="1"> <!-- ... --> </select>
<!-- Number of adults --> <select name="noa" size="1"> <!-- ... --> </select> </form>
The number of children (noc) is included amongst the hidden elements as you haven't provided any way to input that information.
At the present moment, an arrival date that matches the current day will be considered invalid. Changing it to be valid is not trivial. Are there enough hours left in the day to process the booking? If the visitor is thousands of miles away (and you don't know if they are or not), did they really intend to book today?
> //now pop-up the new window with this url. If you really do want to use a pop-up, then you could include this function:
function submitToPopup(form) { if('function' == typeof this.open) { this.open( '', form.target, 'width=778,height=600,status,resizable,scrollbars ); } return true; }
alter the submit listener to:
onsubmit="return isValidSubmission(this) && submitToPopup(this);"
and add a target attribute to the FORM element:
<form target="booking" ...>
[snip]
Hope that helps, Mike
 Signature Michael Winter Replace ".invalid" with ".uk" to reply by e-mail.
Ash - 25 Apr 2005 13:21 GMT > Rather than using that code to create the submission, why don't you just > submit the form properly? > > function isValidDate(dt, y, m, d) { > return (y == dt.getFullYear()) && (m == dt.getMonth()) > && (d = dt.getDate()); Wow thanks for your detailed response, thats excellent, I really struggle with Javascript - not to understand its logic, but to correctly set out its syntax, stumps me every time!
I see your reasoning behind suggesting to submit the form 'properly', trouble is the people behind the hotel booking application prefer us to follow their basic code model, with the addition of our own validation. I'm quite happy with this as it enables them to support any issues we have.
Taking your above function above (ValidDate), how could we simply expand on that, so as when the user clicks CHECK/BOOK, the current script will check that both are valid, and if either are invalid, it'll simply popup an alert to say so?
Cheers, Ash
Michael Winter - 26 Apr 2005 17:03 GMT > Taking your [...] function [...] (ValidDate), how could we simply expand on > that, so as when the user clicks CHECK/BOOK, the current script will check > that both are valid, and if either are invalid, it'll simply popup an alert > to say so? You can use the original function. All you really need to do is alter the control names I used. So, for example
elem.bay.value
would be changed to
elem.ARRIVAL_YEAR.value
There are six control references in all, used in the two Date constructors. The sequence 'ba' should be replaced by 'ARRIVAL_' and 'bd' by 'DEPARTURE_'. The remaining characters - 'y', 'm', and 'd' - are obviously 'YEAR', 'MONTH' and 'DAY'.
If you want to show warnings, the comments show where failures are found in the code and what caused them. You can use the alert function to display a string.
There really isn't that much to edit.
Mike
 Signature Michael Winter Replace ".invalid" with ".uk" to reply by e-mail.
Dr John Stockton - 25 Apr 2005 20:10 GMT JRS: In article <mo4be.19156$G8.5402@text.news.blueyonder.co.uk>, dated Mon, 25 Apr 2005 11:20:50, seen in news:comp.lang.javascript, Michael Winter <m.winter@blueyonder.co.invalid> posted :
>> Actually, here's the lump of javascript that the form uses, [...] > [quoted text clipped - 5 lines] > && (d = dt.getDate()); > } One does not need all three tests (possible exception is if the function must give the right answer for 0000-02-29 (that could be fixed with something like Arr = new Date(y+4000, m-48000, d) ), but that will not apply, it seems, in this case).
For drop-downs in which it is not possible to select an invalid Gregorian date, see in <URL:http://www.merlyn.demon.co.uk/js-date6.htm>. That code requires javascript to (re)build the day control, IIRC; but the code could be modified to put 31 days in every month by HTML and correct that only if javascript is available.
If there is to be a selector for arrival and then one for departure, the latter can likewise be made to offer only dates for which departure can, or must, follow arrival.
ISTM better, rather than having to validate the customer's choice, to arrange matters so that he can make only valid choices. Of course, if there is a server, there should at some stage be server-side validation.
If this is a short-stay business, how about Y M D drop-downs for arrival, then a selector for length of stay, then a display of the resultant departure date? For each selected date, the day-of-week should probably be shown; indeed, a D entries in a Y M D drop-down can show not only D but also its DoW.
An OP posting via BT should surely not be using FFF order, but Y M D.
 Signature © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 © <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Ash - 26 Apr 2005 10:30 GMT > JRS: In article <mo4be.19156$G8.5402@text.news.blueyonder.co.uk>, dated > Mon, 25 Apr 2005 11:20:50, seen in news:comp.lang.javascript, Michael > Winter <m.winter@blueyonder.co.invalid> posted : Thanks for your incredibly detailed reply, my understanding of other logical languages is fairly good, but its the actual implementation of any javascript that my ability to get the correct syntax seems to fail - I will give it a go, but I'm sure I'll fail in actually amending my existing page to incorporate this code.
In the current script, you'll notice a function...
function validateFields(){ return true; }
To keep things simple, I would like to insert a code block into this function that will simply...
//1. Arrival date is at least today (you may have more restrictions) //2. Departure date is after arrival //3. Arrival and Departure dates are valid dates.
I feel real guilty asking for this, but would it be possible to construct the actual code that I could dump straight into this function?
Really appreciate your help, at least from there I can see how the syntax works in the context, and perhaps learn something for the future, hehe!
Cheers, Ash
Dr John Stockton - 26 Apr 2005 23:06 GMT JRS: In article <d4l1n2$f0o$1@hercules.btinternet.com>, dated Tue, 26 Apr 2005 09:30:10, seen in news:comp.lang.javascript, Ash <spam_ash@a- hall.com> posted :
>> JRS: In article <mo4be.19156$G8.5402@text.news.blueyonder.co.uk>, dated >> Mon, 25 Apr 2005 11:20:50, seen in news:comp.lang.javascript, Michael [quoted text clipped - 25 lines] >Really appreciate your help, at least from there I can see how the syntax >works in the context, and perhaps learn something for the future, hehe! Addressing MW : if validating date drop-downs, the year and month will be plausible, so one should only need (UNTESTED)
function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0 return new Date(y, m, d).getDate() == d /* was y, m */ }
FFF = Fred Flintstone Format - M/D/Y.
Addressing Ash - here's a start, lightly tested as mentioned :
AY = "2003" ; AM = "02" ; AD = "26" // Arr DY = "2009" ; DM = "04" ; DD = "28" // Dep
function InvalidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0 with (D=new Date(y, m, d)) return (getMonth()==m && getDate()==d) ? D : NaN /* was y, m */ }
if (!(Arr = InvalidDate(AY, AM-1, AD))) alert('Bad Arr') if (!(Dep = InvalidDate(DY, DM-1, DD))) alert('Bad Dep') if (Arr >= Dep) alert('Bad stay') if (Arr < new Date()) alert('Too soon') Stay = Math.round((Dep-Arr)/864e5)
There may be a micro-bug if the code is run at exactly midnight.
If you have a TARDIS, do not use the above code for bookings starting or ending on 1st Jan 1970, in locations where the OS thinks the clock was then GMT. But here, it wasn't; we had British Standard Time then ( as BST but all year). But MS does not know that.
Maybe return (getMonth()==m && getDate()==d) ? D : NaN /* was y, m */ }
InvalidDate needs renaming.
Only the first alert, if more than one, is necessarily valid.
If it is necessary to force D = new Date() [which is 'NOW'] to the beginning of today or tomorrow, use D.setHours(X, 0, 0, 0) with X=0 or X=24.
NOTE : that allows a booking for Apr 27 to be made as late as Apr 26 23:59:59.99.
NOTE : remember that American clocks are generally 5-10 hours slow, and Australian ones nearly half a day fast - if you allow foreign visitors.
 Signature © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 © <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Michael Winter - 26 Apr 2005 18:12 GMT > JRS: In article <mo4be.19156$G8.5402@text.news.blueyonder.co.uk>, dated > Mon, 25 Apr 2005 11:20:50, seen in news:comp.lang.javascript, Michael > Winter <m.winter@blueyonder.co.invalid> posted : [snip]
>> function isValidDate(dt, y, m, d) { >> return (y == dt.getFullYear()) && (m == dt.getMonth()) >> && (d = dt.getDate()); >> } > > One does not need all three tests [...] Perhaps not. I don't see any particular reason not to include them all, however it would probably be better to change the order of evaluation as the year is only likely to change in December (when input restrictions are imposed). It would potentially shorten the time necessary to discover invalid dates, but still add little overhead to valid ones.
> [...] <URL:http://www.merlyn.demon.co.uk/js-date6.htm>. > [...] the code could be modified to put 31 days in every month by > HTML and correct that only if javascript is available. And probably should be. I'll probably post something later.
> If there is to be a selector for arrival and then one for departure, the > latter can likewise be made to offer only dates for which departure can, > or must, follow arrival. True. However it would still be prudent to assume that such a selector cannot be created, and 'basic' validation should still be carried out on the client (and the server, of course).
> [...] Of course, if there is a server, there should at some stage be > server-side validation. I get the impression that the third-party service relies on client-side validation created by its users. I'm not about to test that theory through an account that belongs to someone else, though.
[snip]
> An OP posting via BT should surely not be using FFF order [...] FFF?
Mike
 Signature Michael Winter Replace ".invalid" with ".uk" to reply by e-mail.
Lasse Reichstein Nielsen - 26 Apr 2005 20:11 GMT >> One does not need all three tests [...] > [quoted text clipped - 4 lines] > necessary to discover invalid dates, but still add little overhead to > valid ones. A good choice. It is a rare error that changes the year and not the month. Indeed, most non-deliberate errors will be only a few days off (e.g., 31st of April) and will error on both date and month.
Moving the year check last will guarantee that it is only performed for valid dates (but that goes for any of the checks if placed third).
(btw, remember to change the "=" to "==" in the date comparison).
>> An OP posting via BT should surely not be using FFF order [...] > > FFF? "Fred Flintstone Format", Dr. Stockton's own name for MM/DD/YY format. <URL:http://www.merlyn.demon.co.uk/datefmts.htm>
/L
 Signature Lasse Reichstein Nielsen - lrn@hotpop.com DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'
Michael Winter - 26 Apr 2005 21:08 GMT [snip]
> (btw, remember to change the "=" to "==" in the date comparison). Oops. Thank you. That was careless of me.
In case the OP doesn't quite know what Lasse is referring to, the isValidDate function should read:
function isValidDate(dt, y, m, d) { return (dt.getDate() == d) && (dt.getMonth() == m) && (dt.getFullYear() == y); }
I also thought I'd take my own advice and reverse the order of the operands so that the method call, which cannot be assigned to without causing a run-time error, is on the left-hand side.
Mike
 Signature Michael Winter Replace ".invalid" with ".uk" to reply by e-mail.
Dr John Stockton - 27 Apr 2005 15:43 GMT JRS: In article <1x8xe4kl.fsf@hotpop.com>, dated Tue, 26 Apr 2005 21:11:22, seen in news:comp.lang.javascript, Lasse Reichstein Nielsen <lrn@hotpop.com> posted :
>>> One does not need all three tests [...] >> [quoted text clipped - 11 lines] >Moving the year check last will guarantee that it is only performed >for valid dates (but that goes for any of the checks if placed third). Omitting the year check allows the validation to be used for years given as 00..99 meaning 1900..1999, and for years 00..99 meaning 0000..0099 if an error for 0000-02-29 can be tolerated. It also avoids any doubt about the availability of getFullYear.
>>> An OP posting via BT should surely not be using FFF order [...] >> >> FFF? > >"Fred Flintstone Format", Dr. Stockton's own name for MM/DD/YY format. ><URL:http://www.merlyn.demon.co.uk/datefmts.htm> No, not my own name, but one that I came across, possibly on the Web but more likely in News - maybe news:misc.metric-system, and probably in conjunction with FFU, the system of measurement units that the Americans use and refer to as English (unfair to Welsh, Scots, and Irish) although the proper name in English is Imperial Units.
 Signature © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 © <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Mick White - 25 Apr 2005 13:18 GMT > Actually, here's the lump of javascript that the form uses, you can see some > Javascript that I tried to make sure one date wasn't before the other...but > it didn't work!? > > ------------ http://www.mickweb.com/b_and_b/index1.html
Mick
> <SCRIPT language="JavaScript" TYPE="text/javascript"> > function doCheckAvail(){ [quoted text clipped - 71 lines] > > </SCRIPT> Ash - 25 Apr 2005 13:24 GMT Very smart, will take a look at the logic behind that now.
Thanks!
>> Actually, here's the lump of javascript that the form uses, you can see >> some Javascript that I tried to make sure one date wasn't before the [quoted text clipped - 3 lines] > > http://www.mickweb.com/b_and_b/index1.html @sh - 26 Apr 2005 16:03 GMT Before I try something more complex, I'm staying simple and have tried this...
function validateFields() {
if (document.myForm.ARRIVAL_DAY.value = '02') && (document.myForm.ARRIVAL_MONTH.value > '28') { alert('Invalid date'); return false; } else { return true; }
...But it doesn't work, what am I doing wrong? I get a 'Syntax Error'.
Cheers, Ash
@sh - 26 Apr 2005 16:19 GMT Ooooops, ignore my last post....I see a few errors there but thats another story...
I'm starting from the top now and outputing the variables I'm trying to deal with to an alert() prompt, however I'm just getting '[object]' popping up, does this mean it cannot interpret the value??
Cheers, Ash
Mick White - 26 Apr 2005 16:23 GMT > Before I try something more complex, I'm staying simple and have tried > this... [quoted text clipped - 12 lines] > > ...But it doesn't work, what am I doing wrong? I get a 'Syntax Error'. function validateFields() { var d=document.myForm if (parseInt(d.ARRIVAL_DAY.value,10) == 2 && d.ARRIVAL_MONTH.value > 28) { alert('Invalid date'); return false; } return true; } Mick
Dr John Stockton - 26 Apr 2005 23:27 GMT JRS: In article <O1tbe.8126$XF3.3938@twister.nyroc.rr.com>, dated Tue, 26 Apr 2005 15:23:26, seen in news:comp.lang.javascript, Mick White <mwhite13BOGUS@rochester.rr.com> posted :
>function validateFields() { >var d=document.myForm [quoted text clipped - 5 lines] > return true; >} Funny calendar you have in your part of the USA - months after the 28th don't have a Day 2.
Take a local copy of <URL:http://www.merlyn.demon.co.uk/js-quick.htm> - DO NOT use the web copy repeatedly, for bandwidth reasons - and you can then easily test little bits of code before posting them.
For dates in 2001-2099, and I guess that's enough for the OP, who should by then be promoted/sacked/retired, it should be sufficient to test that D <= 31 - (M==4 || M==6 || M==9 || M==11) and if M==2 that D <= 28 + (Y%4==0) .
But the test with a Date Object will be better.
GENERAL : a proportion of news posts (not only mine) uploaded to my ISP in the last week or so have been delayed, apparently before being offered to servers and peers; they are now appearing.
 Signature © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. © Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Mick White - 27 Apr 2005 00:27 GMT > <mwhite13BOGUS@rochester.rr.com> posted : [snip]
>> if (parseInt(d.ARRIVAL_DAY.value,10) == 2 && >> d.ARRIVAL_MONTH.value > 28) { [snip]
> Funny calendar you have in your part of the USA - months after the 28th > don't have a Day 2. Oops, perhaps I have the month and the date reversed...
> Take a local copy of <URL:http://www.merlyn.demon.co.uk/js-quick.htm> - > DO NOT use the web copy repeatedly, for bandwidth reasons - and you can > then easily test little bits of code before posting them. Mea culpa. I have some trouble with your site using Safari. The date object is, well, different.
> For dates in 2001-2099, and I guess that's enough for the OP, who should > by then be promoted/sacked/retired, it should be sufficient to test that > D <= 31 - (M==4 || M==6 || M==9 || M==11) and if M==2 that > D <= 28 + (Y%4==0) . > > But the test with a Date Object will be better. I agree since you are, at most, creating 2 date objects. Mick
@sh - 27 Apr 2005 10:37 GMT > Oops, perhaps I have the month and the date reversed...
> function isValidDate(dt, y, m, d) { > return (dt.getDate() == d) && (dt.getMonth() == m) > && (dt.getFullYear() == y); > } Just to say a massive thanks to all that contributed here, I really do wish I had the javascript understanding that you guys clearly have, its just the syntax that gets me, and the data subtypes, I hope to get there in the end.
Its unfortunate that there are such within other threads so as to spoil the experience for Usenet newbies. I appreciate you must get some silly questions on here, but some must sit staring at their screen just waiting to post their negative picky shite.
Thanks once again though for your help here, I'll stick around for a bit incase of further troubles ;o)
p.s. it was my fault that the date/months were reversed...a typo I noticed shortly after, hehe!
Cheers, Ash
Dr John Stockton - 27 Apr 2005 22:28 GMT JRS: In article <L7Abe.8694$Bc7.4504@twister.nyroc.rr.com>, dated Tue, 26 Apr 2005 23:27:39, seen in news:comp.lang.javascript, Mick White <mwhite13BOGUS@rochester.rr.com> posted :
> I have some trouble with your site using Safari. The date >object is, well, different. AIUI, Safari is at least moderately often used, though I know nothing of it myself, not even what it runs on. In that case, let's investigate : for example, how does it differ from ECMA-262, what on my site does not work, etc.? Can feature detection help? What should the FAQ say? Is there a Safari FAQ? a Safari javascript FAQ? a Safari javascript date FAQ?
 Signature © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. © Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Mick White - 28 Apr 2005 13:06 GMT > JRS: In article <L7Abe.8694$Bc7.4504@twister.nyroc.rr.com>, dated Tue, > 26 Apr 2005 23:27:39, seen in news:comp.lang.javascript, Mick White [quoted text clipped - 10 lines] > FAQ? > Safari will render only dates from ~1900 to ~2035. And it had trouble with "setting" the date
function getWeekday(year,weekday){ var weekdays=new Array(); var starter=getNthDayInMonth(1,weekday,"January",year); //1st monday of year
var D=new Date("January "+starter+", "+year).getTime() for(var t=D;t<D+52*6048e5;t+=6048e5){ weekdays[weekdays.length]=new Date(t); } return weekdays; }
In the loop, you'd think the following would work, but no.
for(var t=0;t<52*7;t+=7){ weekdays[weekdays.length]=D.setDate(t); }
Likewise: var t=0,Y=D.getFullYear(),NY=D+1; while(year<NY){ t+=7; weekdays[weekdays.length]=D.setDate(t) } Mick
while(year <+1
Mick White - 28 Apr 2005 13:10 GMT [snip]
> var D=new Date("January "+starter+", "+year).getTime(); [snip]
> var t=0,Y=D.getFullYear(),NY=D+1; > while(year<NY){ > t+=7; > weekdays[weekdays.length]=D.setDate(t) > } > Mick Forget the while clause , D is, of course, a timestamp, not a date object.
Mick
Dr John Stockton - 28 Apr 2005 22:49 GMT JRS: In article <fl4ce.11735$mG3.6961@twister.nyroc.rr.com>, dated Thu, 28 Apr 2005 12:06:35, seen in news:comp.lang.javascript, Mick White <mwhite13BOGUS@rochester.rr.com> posted :
>> JRS: In article <L7Abe.8694$Bc7.4504@twister.nyroc.rr.com>, dated Tue, >> 26 Apr 2005 23:27:39, seen in news:comp.lang.javascript, Mick White [quoted text clipped - 11 lines] >> > Safari will render only dates from ~1900 to ~2035. All Safari, or just some versions?
My js-dates.htm : I hear that Safari 1.2.3 on Mac OS 10.3. shows a range of +-2^31 seconds from zero - 1901-12-13 to 2038-01-19 GMT.
ECMA requires +-10^8 days. Safari's fault is grievous. In it, 30-year look-ahead for US mortgages will fail in under 33 months from now. The true range will probably be -2^31 to 2^31-1.
<URL:http://www.merlyn.demon.co.uk/js-index.htm#SDB>, first yellow box, should show that range, for Safari users; it determines the borders outside which new Date(x) gives NaN.
>And it had trouble with "setting" the date > ... Without knowing what you get, and what you expected, I can't really comment on that. Remember that you (probably) see effects of Summer Time.
 Signature © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 © <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
|
|
|