By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,190 Members | 2,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,190 IT Pros & Developers. It's quick & easy.

Display Business Hours Adjusted for the Visitor's Time Zone

P: n/a
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?

Thanks in advance for any advice.
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
lm*****@my-deja.com (Monty) wrote in news:646c8e08.0309041219.62acf566
@posting.google.com:
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?

Thanks in advance for any advice.

first, the 'master' time should be in UTC

then you could:

- use the setUTC[date part] functions to set the date in javascript
- use the normal date display functions in javascript, which will by
default display in users local time... whatever it is.

eg

var localdate = new Date();
localdate.setUTCMonth(1);
localdate.setUTCHours(10);
... etc..
document.write(localdate.toLocaleString());
Jul 20 '05 #2

P: n/a
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.
Jul 20 '05 #3

P: n/a
In article <64**************************@posting.google.com >, Monty
<lm*****@my-deja.com> writes
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?


Remember that some people's PCs are set to the wrong time zone. You
might consider giving the times in UTC (GMT) and in your time zone as
well.

John
--
John Harris
mailto:jo**@jgharris.demon.co.uk
Jul 20 '05 #4

P: n/a
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in message news:<TE**************@merlyn.demon.co.uk>...
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.


Eastern Standard Time is GMT-5 and Eastern Daylight time is GMT-4.
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.
We are in the Eastern US and our customers are worldwide. We were
attempting to say something like "This service is available Monday
through Saturday from 7:00 AM until 6:00 PM, Eastern (New York) Time.
To see the hours of availability in your time zone (based on your
computer's clock), click here." Then have javascript display the
adjusted hours. I'm not even going to worry about the day.

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?

Yeah but I didn't see a FAQ dealing with this issue. Did I miss
something?

Monty
Jul 20 '05 #5

P: n/a
JRS: In article <64**************************@posting.google.com >, seen
in news:comp.lang.javascript, Monty <lm*****@my-deja.com> posted at Mon,
8 Sep 2003 07:32:01 :-
Yeah but I didn't see a FAQ dealing with this issue. Did I miss
something?


Obviously you missed not only the part about quoting only what needs to
be quoted, but also the mention of "Manipulating times, dates and the
lastModified date and time in javascript".

GENERAL NOTICE :
My js-date1.htm had got too big; parts are now in the new Page 9. Allow
a day or two before mentioning any residual duplications. There _should_
be no losses.

--
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.
Jul 20 '05 #6

P: n/a
JRS: In article <Xn*********************@198.80.55.250>, seen in
news:comp.lang.javascript, Sean Jorden <s_***********@no.spam.n_o_r_a.d.
a.com> posted at Thu, 4 Sep 2003 21:10:27 :-

var localdate = new Date();
localdate.setUTCMonth(1);
localdate.setUTCHours(10);
.. etc..
document.write(localdate.toLocaleString());


To set a specific date, it is dangerous to use set[UTC]Month with a
single parameter. The intent appears to be to set February. That will
work up to the 28th of this month, after which the code will set March,
and a subsequent setDate() would remain in March (for parameter 1..31).

Conversely, if the Date is set first, to a number greater than 28, the
method will shift months if the current month is shorter.

Use, therefore, setYear(Y, M, D) or setMonth(M, D).

In the specific case, though, new Date(Date.UTC(Y,M,D,h,m,s)) - that
is, if the OP can cause the correct UTCs to be entered as data, but
their times will depend on the US season..

In fact, new Date() should not be used to create a Date Object, but
only to create one needed to hold the current date/time. For mere
creation, use new Date(0) which ensures consistent behaviour -
moreover, as it happens, it always gives a long month.

But the precaution is not omnipotent.

D = new Date(0) ; D.setMonth(1)

gives 1970 Feb 1st in Europe, Africa, Asia, etc.; but I expect 1969 Mar
3rd or thereabouts in the Americas and the Pacific.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #7

P: n/a
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in news:MHIPdACXcOX
$E***@merlyn.demon.co.uk:
In the specific case, though, new Date(Date.UTC(Y,M,D,h,m,s)) - that
is, if the OP can cause the correct UTCs to be entered as data, but
their times will depend on the US season..


So if you have a virtual shop setup in one timezone, and you need to
display that time in another time zone, this is impossible to do with stock
Javascript, no? You would have to be able to

- switch to timezone in which store resides
- enter time
- extract UTC time
- switch to visitor's timezone
- output in that timezone

So you need to store times in UTC,which are constant and not dependant on
the daylight savings cutover, correct? Only the offset from localtime to
UTC time varies throughout the year. Which would mean that if you are in a
timezone which practises daylight savings, to remain open from 9:00am to
5:00pm local time every day, your actual UTC hours of business will vary
+/- 1 hour throughout the year.

So to more completely answer the original poster,they would need to create
a table containing UTC hours of business for every day of the year, and
convert from that (if they are in a daylight savings timezone).
--
In theory there is no difference between theory and practice. In practice
there is. - YB
Jul 20 '05 #8

P: n/a
JRS: In article <Xn*********************@198.80.55.250>, seen in
news:comp.lang.javascript, Sean Jorden <s_***********@no.spam.n_o_r_a.d.
a.com> posted at Mon, 8 Sep 2003 23:28:46 :-
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in news:MHIPdACXcOX
$E***@merlyn.demon.co.uk:
In the specific case, though, new Date(Date.UTC(Y,M,D,h,m,s)) - that
is, if the OP can cause the correct UTCs to be entered as data, but
their times will depend on the US season..
So if you have a virtual shop setup in one timezone, and you need to
display that time in another time zone, this is impossible to do with stock
Javascript, no?


No, unless you impose a very restrictive meaning on "stock".

You would have to be able to

- switch to timezone in which store resides
- enter time
- extract UTC time
- switch to visitor's timezone
- output in that timezone
No, you would not do that. AFAIK, javascript does not support switching
the time-zone of a Web client, thank goodness.

So you need to store times in UTC,which are constant and not dependant on
the daylight savings cutover, correct?
No, you would not have to do that, though it is a possibility.

Only the offset from localtime to
UTC time varies throughout the year. Which would mean that if you are in a
timezone which practises daylight savings, to remain open from 9:00am to
5:00pm local time every day, your actual UTC hours of business will vary
+/- 1 hour throughout the year.
Correct, except that the difference is not everywhere one hour.

So to more completely answer the original poster,they would need to create
a table containing UTC hours of business for every day of the year, and
convert from that (if they are in a daylight savings timezone).


No, they would not need to do that. It is sufficient to give the
business hours in their own time, combined with the Time Rules for that
location. /* There will be a REAL problem for any business which
starts and/or stops during either the Missing or the Ambiguous hour of
its local civil year; it will have to make a decision about when it will
then actually open/close. */

You should read what the FAQ says about date and time.

Today, I have expanded what <URL:http://www.merlyn.demon.co.uk/js-
date5.htm#SRTL> has on the subject; it needs test by someone in another
Time Zone. There is a version for London and one for Chicago.

--
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.
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.