D
Dr John Stockton
I have been, and am still, working on improving Week Number programming,
now in <URL:http://www.merlyn.demon.co.uk/weekcalc.htm>.
I have added three parameterised functions each giving non-standard
(i.e. suitable for the USA) output [Y W D] for a Date Object, and their
reverses, for
Type 1. Year Number is Calendar Year, so partial weeks are required.
Type 2. Every Week has Seven Days, so the Year Number can differ from
the Calendar Year. ISO Week Numbers are a specific case.
Type 3. Week 01 begins on a Given Date.
Please tell me of any extant sort of Week Number which is not
accommodated by those.
(That general Type 2 code is *not* optimal for ISO Week Number)
I have noted that a routine using UTC methods is much faster than a
similar routine using local methods, and have made a couple of other
routines much faster by converting them from local to UTC internally.
Probably UTC is faster because there is no need to consult, repeatedly,
the Summer Time Rules.
NOTE that much common javascript date work does not *need* local date;
for example, much calendar work can be done in UTC. The present
date/time can easily be converted into a UTC date by applying
getTimezoneOffset. The reverse takes a little more thought, for the
worst case Summer Time rules, unless the obvious brute-force method is
used.
Also, using a routine found in 'The Calendar FAQ' and another derived
from the work of Zeller, ISO 8601 Y W D can be obtained by going via
CMJD, a standard daycount - and vice versa. That's about as fast as he
best of the rest, in my MSIE4.
The names of some of my javascript functions have changed.
now in <URL:http://www.merlyn.demon.co.uk/weekcalc.htm>.
I have added three parameterised functions each giving non-standard
(i.e. suitable for the USA) output [Y W D] for a Date Object, and their
reverses, for
Type 1. Year Number is Calendar Year, so partial weeks are required.
Type 2. Every Week has Seven Days, so the Year Number can differ from
the Calendar Year. ISO Week Numbers are a specific case.
Type 3. Week 01 begins on a Given Date.
Please tell me of any extant sort of Week Number which is not
accommodated by those.
(That general Type 2 code is *not* optimal for ISO Week Number)
I have noted that a routine using UTC methods is much faster than a
similar routine using local methods, and have made a couple of other
routines much faster by converting them from local to UTC internally.
Probably UTC is faster because there is no need to consult, repeatedly,
the Summer Time Rules.
NOTE that much common javascript date work does not *need* local date;
for example, much calendar work can be done in UTC. The present
date/time can easily be converted into a UTC date by applying
getTimezoneOffset. The reverse takes a little more thought, for the
worst case Summer Time rules, unless the obvious brute-force method is
used.
Also, using a routine found in 'The Calendar FAQ' and another derived
from the work of Zeller, ISO 8601 Y W D can be obtained by going via
CMJD, a standard daycount - and vice versa. That's about as fast as he
best of the rest, in my MSIE4.
The names of some of my javascript functions have changed.