Re: firefox global variables woes
JRS: In article <1108071509.672 729.193150@o13g 2000cwo.googleg roups.com>
, dated Thu, 10 Feb 2005 13:38:29, seen in news:comp.lang. javascript, rh
<codeHanger@yah oo.ca> posted :[color=blue]
>Mick White wrote:[/color]
[color=blue][color=green]
>> Why not hard code it?
>> function GMLen(m,yyyy){//m 0-11
>> return [31,yy%4==0?new
>> Date(yyyy,m+1,0 ).getDate():28, 31,30,31,30,31, 31,30,31,30,31][m]
>> }[/color][/color]
[color=blue]
>First of all, what you've presented doesn't fit my definition of "hard
>code". Secondly, it wouldn't appear to have been tested. And thirdly,
>it doesn't account for leap years properly.[/color]
It has a couple of missing 'y's; but, with that fixed, it handles
Gregorian leap year properly AFAICS.
[color=blue]
>This is a case where efficiency happened to be predominant in the
>choice, particularly given the context in which the response was made.[/color]
ISTM that the above constructs a whole 12-element array whenever called,
including the calculation of an element not wanted 11 times out of 12.
In expression yyyy%4==0?new Date(yyyy,m+1,0 ).getDate():28 the %4 does
optimise 3 out of 4 years; but
Y%4 != 0 ? 28 : Y%100 !=0 ? 29 : Y%400 != 0 ? 28 : 29
seems easy enough and must be cheaper than a Date Object.
For aesthetic but presumably inefficient expressions,
28 + (y%4==0) ^ (y%100==0) ^ (y%400==0)
or 28 + (!(y%4)) ^ (!(y%100)) ^ (!(y%400))
or 28 | !(y%4)^!(y%100) ^!(y%400)
But I was asking whether = 30 + ((3*m+1)%5 < 3) could be improved,
not whether any better routines existed; in other words, I was after
something generating the lengths arithmetically, as Zeller would.
That = 30 | (m>>3^m) is indeed good, covering 1,3-12 as it does.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
JRS: In article <1108071509.672 729.193150@o13g 2000cwo.googleg roups.com>
, dated Thu, 10 Feb 2005 13:38:29, seen in news:comp.lang. javascript, rh
<codeHanger@yah oo.ca> posted :[color=blue]
>Mick White wrote:[/color]
[color=blue][color=green]
>> Why not hard code it?
>> function GMLen(m,yyyy){//m 0-11
>> return [31,yy%4==0?new
>> Date(yyyy,m+1,0 ).getDate():28, 31,30,31,30,31, 31,30,31,30,31][m]
>> }[/color][/color]
[color=blue]
>First of all, what you've presented doesn't fit my definition of "hard
>code". Secondly, it wouldn't appear to have been tested. And thirdly,
>it doesn't account for leap years properly.[/color]
It has a couple of missing 'y's; but, with that fixed, it handles
Gregorian leap year properly AFAICS.
[color=blue]
>This is a case where efficiency happened to be predominant in the
>choice, particularly given the context in which the response was made.[/color]
ISTM that the above constructs a whole 12-element array whenever called,
including the calculation of an element not wanted 11 times out of 12.
In expression yyyy%4==0?new Date(yyyy,m+1,0 ).getDate():28 the %4 does
optimise 3 out of 4 years; but
Y%4 != 0 ? 28 : Y%100 !=0 ? 29 : Y%400 != 0 ? 28 : 29
seems easy enough and must be cheaper than a Date Object.
For aesthetic but presumably inefficient expressions,
28 + (y%4==0) ^ (y%100==0) ^ (y%400==0)
or 28 + (!(y%4)) ^ (!(y%100)) ^ (!(y%400))
or 28 | !(y%4)^!(y%100) ^!(y%400)
But I was asking whether = 30 + ((3*m+1)%5 < 3) could be improved,
not whether any better routines existed; in other words, I was after
something generating the lengths arithmetically, as Zeller would.
That = 30 | (m>>3^m) is indeed good, covering 1,3-12 as it does.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Comment