Display Business Hours Adjusted for the Visitor's Time Zone

Discussion in 'Javascript' started by Monty, Sep 4, 2003.

  1. Monty

    Monty Guest

    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.
    Monty, Sep 4, 2003
    #1
    1. Advertising

  2. Monty

    Sean Jorden Guest

    (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());
    Sean Jorden, Sep 4, 2003
    #2
    1. Advertising

  3. JRS: In article <>, seen
    in news:comp.lang.javascript, Monty <> 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.
    Dr John Stockton, Sep 5, 2003
    #3
  4. In article <>, Monty
    <> 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:
    John G Harris, Sep 5, 2003
    #4
  5. Monty

    Monty Guest

    Dr John Stockton <> wrote in message news:<TE54NIHXRMW$>...
    > JRS: In article <>, seen
    > in news:comp.lang.javascript, Monty <> 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
    Monty, Sep 8, 2003
    #5
  6. JRS: In article <>, seen
    in news:comp.lang.javascript, Monty <> 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.
    Dr John Stockton, Sep 8, 2003
    #6
  7. JRS: In article <Xns93EC9A350982Csjorden@198.80.55.250>, seen in
    news:comp.lang.javascript, Sean Jorden <_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.
    Dr John Stockton, Sep 8, 2003
    #7
  8. Monty

    Sean Jorden Guest

    Dr John Stockton <> wrote in news:MHIPdACXcOX
    $:

    > 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
    Sean Jorden, Sep 9, 2003
    #8
  9. JRS: In article <Xns93F0B1A27DF0Bsjorden@198.80.55.250>, seen in
    news:comp.lang.javascript, Sean Jorden <_o_r_a.d.
    a.com> posted at Mon, 8 Sep 2003 23:28:46 :-
    >Dr John Stockton <> wrote in news:MHIPdACXcOX
    >$:
    >
    >> 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.
    Dr John Stockton, Sep 9, 2003
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=

    prevent a postback when moving web parts from zone to zone.

    =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=, Feb 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    576
    =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=
    Feb 8, 2006
  2. Rahmi Acar
    Replies:
    0
    Views:
    549
    Rahmi Acar
    Jul 17, 2003
  3. Phrogz
    Replies:
    2
    Views:
    126
    Phrogz
    Apr 6, 2007
  4. Sławosz Sławiński

    Business hours processing

    Sławosz Sławiński, Jun 11, 2010, in forum: Ruby
    Replies:
    4
    Views:
    122
    Sławosz Sławiński
    Aug 3, 2010
  5. rutherf
    Replies:
    2
    Views:
    410
    rutherf
    Oct 28, 2006
Loading...

Share This Page