Re: date functions
JRS: In article <290e65a0.04061 10751.351e2f4f@ posting.google. com>, seen
in news:comp.lang. javascript, rh <codeHanger@yah oo.ca> posted at Fri, 11
Jun 2004 08:51:44 :[color=blue]
>Dr John Stockton wrote:
>
><snip>
>[color=green][color=darkred]
>> >IIRC, there is much to be said for use of "prototype" as part of the
>> >test.[/color]
>>[/color]
>
>Too subtle, I see :). I believe you intended to use:
>
> if (! Date.prototype. getFullYear)
>
>in place of:
>
> if (!Date.getFullY ear)
>
>in the test(s) for pre-existence. Otherwise, a browser supported
>getFullYear will be overridden, which I would think to be neither the
>intention nor desirable.[/color]
Your "intended" is perhaps a bit strong - "ought to have intended",
maybe. It does come from a rather tentative bit of the Web page. Page
master now changed, thanks.
[color=blue]
><snip>
>[color=green]
>> That needs further thought and testing before use. My js-date1,htm is
>> updated.[/color]
>
>I'll defer to your expertise and further testing on the enhanced
>version.[/color]
Updated again. This function seems likely to be OK, for >= AD 100 :-
function getFY(D) { var YE // needs full test in all browsers
YE = Math.round(D.ge tTime() / 31556952000) + 1970
return YE + (D.getYear()-YE)%100 }
Read it backwards; the result takes only the last 2 digits of getYear,
and is independent of the last two digits of YE; YE is about right, but
has misplaced Leap Years. The result of %100 is about mid-range; its
range is -99..+99. 31556952000 = 864e5 * 365.2425. The value of 1970
has a tolerance of over +-95; the divisor will also have a generous
tolerance.
--
© 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 <290e65a0.04061 10751.351e2f4f@ posting.google. com>, seen
in news:comp.lang. javascript, rh <codeHanger@yah oo.ca> posted at Fri, 11
Jun 2004 08:51:44 :[color=blue]
>Dr John Stockton wrote:
>
><snip>
>[color=green][color=darkred]
>> >IIRC, there is much to be said for use of "prototype" as part of the
>> >test.[/color]
>>[/color]
>
>Too subtle, I see :). I believe you intended to use:
>
> if (! Date.prototype. getFullYear)
>
>in place of:
>
> if (!Date.getFullY ear)
>
>in the test(s) for pre-existence. Otherwise, a browser supported
>getFullYear will be overridden, which I would think to be neither the
>intention nor desirable.[/color]
Your "intended" is perhaps a bit strong - "ought to have intended",
maybe. It does come from a rather tentative bit of the Web page. Page
master now changed, thanks.
[color=blue]
><snip>
>[color=green]
>> That needs further thought and testing before use. My js-date1,htm is
>> updated.[/color]
>
>I'll defer to your expertise and further testing on the enhanced
>version.[/color]
Updated again. This function seems likely to be OK, for >= AD 100 :-
function getFY(D) { var YE // needs full test in all browsers
YE = Math.round(D.ge tTime() / 31556952000) + 1970
return YE + (D.getYear()-YE)%100 }
Read it backwards; the result takes only the last 2 digits of getYear,
and is independent of the last two digits of YE; YE is about right, but
has misplaced Leap Years. The result of %100 is about mid-range; its
range is -99..+99. 31556952000 = 864e5 * 365.2425. The value of 1970
has a tolerance of over +-95; the divisor will also have a generous
tolerance.
--
© 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