JRS: In article <64**************************@posting.google.com >, seen
in news:comp.lang.javascript, Monty <lm*****@my-deja.com> posted at Thu,
4 Sep 2003 13:19:11 :-
Let's say you provide an online service from 7:00AM to 6:00PM Eastern
Time (daylight time in the summer). Is there way of showing these
hours of availability on a web page in the user's local time?
Firstly, you have to determine what Eastern Time actually is, in
relation to the real time (GMT). I believe that they have it in
America; they may also have it in, for example, Australia or Russia, and
the EU has an easternmost zone too. Other than UTC & GMT, time zone
acronyms are not standardised.
Then you should determine the start and stop times of ET Summer Time,
for the current year, in UTC, remembering that the user's system does
not intrinsically know the ET rules. If you can rely on the page source
being updated sufficiently often - annually at least - you can work out
the times by reference to the current year's calendar or diary, if it
applies to ET, and insert them as millisecond numbers.
Or you can automate it.
Fortunately, since no-one starts or finishes Summer Time on Dec 31 or
Jan 1, there is no difficulty in determining the current year without
important ambiguity. Simple logic then determines the dates and times
of the Summer Time transition, in UTC ms.
Then you can determine, using the user's system, the start/stop times
for the current day in UTC. Remember that the user's current day may
differ from yours.
Then just display the corresponding date object in user's local time.
To show the user whether the service should currently be available,
however, it would be better to determine, from the UTC, the time in ET;
and compare that with the stated limits.
You did not, as would have been wise, indicate your location or that of
your customers. If all are within the USA, excluding Hawaii, and
ignoring those isolationist parts that do not themselves have Summer
Time, then ET is presumably New York Time.
In that case, as the whole of the CONUS changes time while the service
is off, then with either no error or unimportant error, you can just
subtract from the times stated above one hour for each time zone west of
NYC, and you will not even need to change the AM/PM indicator or
understand the 24-h clock. On second thoughts, that will probably be
correct for Hawaii too. But surely every true American is well aware of
how local time relates to NYC time?
Did you read the newsgroup FAQ?
To others : my newest code (and perhaps fastest) for the UNIX
milliseconds of the EU change in Year Y month M (1..12) is
function EUch(Y, M) { // return ms of change
var J = Date.UTC(Y, M-1, 31) // last of month is 31st
return J - 864e5*((4+J/864e5)%7) + 36e5 /* Sun, 0100 GMT */ }
Comment? BTW, M = 10 - 7*SummerStarting // a boolean
For the NA change : add 7*864e5+36e5 for Autumn; and add the time zone
shift in ms - I think.
--
© 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.