473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Display Business Hours Adjusted for the Visitor's Time Zone

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
8 9215
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steevo | last post by:
Is there a way of producing a script to automatically update and show: "Updated x hours and x minutes ago on xx/xx/xx" I currently have a script to automatically show the date and time the page...
5
by: mitchchristensen | last post by:
I have a transaction log that tracks issues from a call center. Each time an issue is assigned to someone else, closed, etc. I get a time stamp. I have these time stamps for the beginning of an...
2
by: David Berman | last post by:
Suppose you have a bulletin board where of course people can post messages and read messages composed by other people. Each message has a time stamp on it. When someone in California comes to the...
5
by: rgrandidier | last post by:
I have a SQL table that stores the UTC time for a column, I then want to display the UTC time to the user in their local time. My approach is to have the user set their time zone via their user...
0
by: Vendell | last post by:
Join one of Canada's finest business men... Dear entrepreneur colleague: Here is a message from the founder.... Let me introduce myself. My name is Ariel Topf. I am 42 years old and I have...
3
by: Beowulf | last post by:
I have data coming from a telephony system that keeps track of when an employee makes a phone call to conduct a survey and which project number is being billed for the time the employee spends on...
23
by: tatata9999 | last post by:
Hi, What time zones tend to use 24 hours time format? Googling hasn't been able to answer the question. Thank you.
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
1
by: audiokarate | last post by:
Well here is my program. I'm new to C++ and new to this forum. Hopefully someone can tell me how to get over this hurdle. I need to use a for loop to change the years to year 1, year 2 etc. My...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.