JRS: In article <bl**********@news7.svr.pol.co.uk>, seen in
news:comp.lang.javascript, Philip WATTS <PR*****@syringa.freeserve.co.uk
posted at Mon, 6 Oct 2003 19:40:14 :-
Can anyone help me with the following code. What ever entry I make for
variable "year" the function excecuted is "checkleapdays" and not
"checkdays". I know from the alert that leap works out correctly, ie 0 on a
leap year and non-zero otherwise, but always the "checkleapdays" function is
called.
Any advise?
Code
var leap=year % 4
alert(leap)
if (leap=0){
checkleapdays(day,month)
}
else{
checkdays(day,month)}
(leap==0).
But you do not need to write code like that, unless you ate using the
Julian Calendar or some other non-Gregorian one; there is always a
better way of doing it, employing the power of the Date Object.
The following, for example, should determine whether a YMD triple
represents a valid date on the proleptic astronomical Gregorian
calendar, up to AD 275760-09-13. It may only be guaranteed after 1970.
It will be wrong, in MSIE4 at least, for the Year Zero, since new Date
there takes a Y in 0..99 to be in 1900..1999. Otherwise it is probably
OK back to -271821 April 21.
function ValidDate(y, m, d) { // m = 0..11 ; y m d integers
with (new Date(y, m, d))
return ((getMonth()==m) && (getDate()==d)) /* was y, m */ }
Read the FAQ; see below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.