Link to home
Start Free TrialLog in
Avatar of alvin_stokes
alvin_stokes

asked on

Daylight Savings Time enabled timezone clock

I need a clock where every TimeZone will have different cities/locations that either adopt or do not adopt DST.  The clock should have two listboxes, one for current time and one for destination time zone.  Here is some pertinent information regarding  cities to be used and when DST starts in each location.  
------------------------------------------------------------ The world is split up into many different time zones, all usually described by their difference from Greenwich Mean Time (GMT) or Universal Coordinated Time (UTC). The difference is not constant, as most countries add 1 hour to the clock during summer months, for daylight savings. However, they don't all make the change at the same time or on the same day, or even in the same direction, as summer in the northern hemisphere is winter in the southern. It isn't surprising that people sometimes have difficulty keeping up with the time in other countries and, as some countries span several time zones,  you sometimes need to know the location of the city to get the correct time.

If you have a 482D Master Clock, this greatly simplifies the tracking of time in up to 15 world time zones, automatically adjusting the time for summer and winter in each zone on the correct date and at the correct time. When used to drive a 400A series multi-zone time display (or a number of individual time or calendar displays), you can be sure that each zone will display the correct time all the time.

The tables below will help you identify the correct time zone for each country or city you wish to identify. You'll also find a description of how to program zone offsets and seasonal time changes here.

Disclaimer: The information in the tables below is accurate to the best of our knowledge, and has been checked against numerous references. You should regard it as a guide only, and check both the offset and the daylight savings information with an appropriate body in the country concerned.


--------------------------------------------------------------------------------

Europe

In Europe, each country sits wholly within a single time zone. The table below lists countries alphabetically, each preceded by the name of the principal city and followed by the number of hours offset from UTC. Most European countries adopt daylight savings time on the last Sunday in March until the last Sunday in October. Some adopt the British pattern of adding an hour at 1am and putting back the clock at 2am, but most use the European pattern where the clock is put back at 3am. The 482D Master Clock allows you to select either pattern when programming a zone.




Andorra la Vella Andorra +1, Tirana Albania +1, Vienna Austria +1
Brussels Belgium +1, Sofia Bulgaria +2
Nicosia Cyprus +2, Prague Czech Republic +1
Copenhagen Denmark +1
Tallinn Estonia +2
Helsinki Finland +2, Paris France +1
Budapest Hungary +1
Reykjavik Iceland +0, Dublin Ireland +0, Milan Rome Italy +1
Riga Latvia +2, Vilnius Lithuania +2, Luxembourg +1
Valetta Malta +1
Amsterdam The Netherlands +1, Oslo Norway +1
Warsaw Poland +2, Lisbon Portugal +0
Bucharest Romania +2, Moscow Russian Federation +3
Belgrade Serbia +1, Bratislava Slovakia +1, Ljubljana Slovenia +1, Barcelona Madrid Spain +1, Stockholm Sweden +1, Geneva Zurich Switzerland +1
Istanbul Ankara Turkey +2
Cardiff Edinburgh London UK +0, Kiev Ukraine +2




--------------------------------------------------------------------------------

United States of America

The USA spans many time zones, but most individual states sit wholly within one or other zone, (Idaho, Oklahoma, Texas and Tennessee each span two zones). States are listed below alphabetically, preceded by principal cities and followed by the number of hours behind UTC. Daylight savings time is adopted on the first Sunday in April, and ends on the last Sunday in October. Select the "US" change pattern on the 482D Master Clock to advance by an hour at 2am in the spring and drop back an hour at 3am in autumn.




Montgomery Alabama -6, Anchorage Alaska -9, Phoenix Arizona -7, Little Rock Arkansas -6
Los Angeles, Sacramento, San Francisco California -8, Aspen, Boulder Colorado -7, Hartford Connecticut -5
Newark Delaware -5, Washington DC -5
Miami Florida -5
Atlanta Georgia -5
Honolulu Hawaii -10
Boise Idaho -7, Moscow Idaho -8, Chicago Illinois -6, Indianapolis Indiana -5, Des Moines Iowa -6
Topeka Kansas -6, Danville Kentucky -6
Baton Rouge Louisiana -6
Augusta Maine -5, Baltimore Maryland -5, Boston Cambridge Massachusetts -5, Detroit Michigan -5,
Minneapolis Minnesota -6, Jackson Mississippi -6, Jefferson City Missouri -6, Helena Montana -7
Lincoln Nebraska -6, Las Vegas Nevada -7, Concord New Hampshire -5, Trenton New Jersey -5,
Albuquerque New Mexico -7, New York New York -5, Raleigh North Carolina -5, Bismarck North Dakota -6
Cleveland Ohio -5, Oklahoma City Oklahoma -6, Portland Oregon -8
Philadelphia Pennsylvania -5
Providence Rhode Island -5
Columbia South Carolina -5, Pierre South Dakota -6
Memphis Nashville Tennessee -6, Knoxville Tennessee -5, Austin Dallas Texas -6, El Paso Texas -7
Salt Lake City Utah -7
Montpelier Vermont -5, Richmond Virginia -5
Seattle Washington -8, Charleston West Virginia -5, Madison Wisconsin -6




--------------------------------------------------------------------------------

Canada

Canada spans 5 time zones, four of which correspond to the main time zones in the USA (Eastern, Central, Mountain & Pacific) while the eastern side of Newfoundland is in the Atlantic time zone. Canada follows the same date and pattern of daylight savings time changes that is used in the USA, so set the 482D Master Clock to "US".




Calgary Edmonton Alberta -7
Vancouver British Columbia -8
Winnipeg Manitoba -6
Fredericton New Brunswick -4
St Johns Newfoundland -3.30, Goose Bay Newfoundland -4
Halifax Nova Scotia -4
Ottawa Toronto Ontario -5
Montreal Quebec -5
Saskatoon Saskatchewan -6
Whitehorse Yukon Territory -8




--------------------------------------------------------------------------------

Australia and New Zealand

Australia spans 3 time zones from 10 hours ahead of UTC to 8 hours ahead. Both north and south islands of New Zealand sit in 1 zone, 12 hours ahead of UTC. Some of the territorial islands of these two countries sit in different time zones again, but these have not been included here. Daylight savings time operate in Australia from the last Sunday in October until the last Sunday in March, using the European pattern of time change. New Zealand starts at the beginning of October and finishes in mid-March.




Canberra ACT +10
Brisbane Queensland +10
Sydney New South Wales +10
Auckland Wellington New Zealand +12
Darwin Northern Territory +9.30
Adelaide South Australia +9.30
Hobart Tasmania +10
Perth Western Australia +8
Melbourne Victoria +10




--------------------------------------------------------------------------------

The Middle East and Indian Sub-Continent

Not every country is listed here, but there is a representative selection for each time zone. The approach to daylight savings varies, so check with a local organisation to be sure that you get the correct information.




Kabul Afghanistan +4.30, Yerevan Armenia +4, Baku Azerbaijan +4
Al Manama Bahrain +3, Dhaka Bangladesh +6
Tbilisi Georgia +3
Bombay Calcutta Madras New Delhi India +5.30, Tehran Iran +3.30, Baghdad Iraq +3, Jerusalem Tel Aviv Israel +2
Amman Jordan +2
Al Kuwayt Kuwait +3
Beirut Lebanon +2
Muscat Oman +4
Islamabad Karachi Lahore Pakistan +5
Dhutan Qatar +3
Riyadh Saudi Arabia +3, Colombo Sri Lanka +5.30, Damascus Syria +2
Istanbul Turkey +2
Abu Dhabi Dubai United Arab Emirates +4
Aden Yemen +3




--------------------------------------------------------------------------------

The Far East and Pacific Rim

Not every country is listed here, but there is a representative selection for each time zone. Each country sits in a single zone, including all of mainland China.




Brunei +8, Rangoon Burma +6.30
Phnom Penh Cambodia +7, Beijing Shanghai China mainland +8
Kowloon Hong Kong +8
Java Sumatra Indonesia +7, Bali Borneo Indonesia +8, Irian Jaya Indonesia +9
Tokyo Japan +9
Kuala Lumpur Malaysia +8
Pyong Yang North Korea +9
Port Moresby Papua New Guinea +10, Manila Philippines +8
Seoul South Korea +9, Singapore +8
Bangkok Thailand +7
Hanoi Saigon Vietnam +7




--------------------------------------------------------------------------------

South America

South America is mainly in the southern hemisphere and those countries which adopt daylight savings generally do so from October to February. Brazil spans 3 time zones with the east coast 3 hours behind UTC, and all of Brazil follows the southern hemisphere daylight savings, despite part of the country being north of the equator.




Buenos Aires Argentina -3
La Paz Bolivia -4
Rio de Janeiro Sao Paulo Brazil -3
Santiago Chile -4
Bogota Colombia -5
Quito Equador -5
Asuncion Paraguay -4
Lima Peru -5
Montevideo Uruguay -3
Caracas Venezuela -4




--------------------------------------------------------------------------------

Africa

Not every country, but a representative selection from each time zone here. As with other countries predominantly in the equatorial region, daylight savings is not always adopted.




Algiers Algeria +1, Luanda Angola +1
Gaborone Botswana +2, Bujumbura Burundi +2
Yaounde Cameroon +1, Santiago Cape Verde -1, Ndjamena Chad +1
Cairo Egypt +2, Adis Ababa Ethiopia +3
Libreville Gabon +1, Banjul The Gambia +0, Accra Ghana +0
Nairobi Kenya +3
Maseru Lesotho +2, Monrovia Liberia +0, Tripoli Libya +1
Antananarivo Madagascar +3, Casablanca Morocco +0, Beira Mozambique +2
Windhoek Namibia +2, Lagos Nigeria +1
Dakar Senegal +0, Johannesburg Pretoria South Africa +2
Kampala Uganda +3
Harare Zimbabwe +2, Lusaka Zambia +2



Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Please do the grunt work. Change the above to

cities = new Array(
new city("Andorra la Vella","Andorra",+1,0),
new city("Tirana","Albania",+1,0),
new city("Vienna","Austria",+1,0),
..
..
..
..
..
..
new city("Montgomery","Alabama",-6,1),
new city("Anchorage","Alaska",-9,1),
..
..
..
new city("Calgary Edmonton","Alberta",-7,1),
new city("Vancouver","British Columbia",-8,1),
..
..
new city("Canberra","ACT",+10,2),
..
..
new city("Kabul","Afghanistan",+4.30,3),
new city("Yerevan","Armenia",+4,3),


and so on - where the 0,1,2,3, are the different versions of daylight implementation

Michel
Avatar of vmolot
vmolot

I fixed at last nasty "Central time zone bug",
(wrong DLT calculation for some time zones)
which I have noted only today,
because I am in Eastrn European time zone, where the bug did not appear.

Below is given prerelease beta version code
(some things of aesthetical nature are to be done yet, e.g. ordering of time zones
by their difference from GMT).

<html>
<head>
<title>JS TimeZone</title>
<script language="javascript" src="TZones.js">
</script>
<script language="javascript">
<!--
function Show(){
      time = new Date();
      str = "toString: "+time.toString()+"\n";
      str += "toGMTstring: "+time.toGMTString()+"\n";
      str += "toUTCstring: "+time.toUTCString()+"\n";
      str += "toLocalestring: "+time.toLocaleString()+"\n";
      str += "String(Date): "+String(time)+"\n";
      alert(str);
}

function Init(){
      var time = new Date();
      currYear = time.getYear();
      //Local Time Zone offset in minutes
      TZoffset = time.getTimezoneOffset( )*60000;
      //Set Remote = Local;
      TZoffset1 = TZoffset;
      //Place in first select box all possible local time zones:
      Ind = new Array;
      ind = fillLocalTZones();
      ind1 = ind;
      //Place in second select box all time zones:
      el = document.Clock.TZone.options;
      el.length = 0;
      for(i=0; i<DST.length; i++){
            star = "";
            if(DST[i].TZI[0]==0) star = "*";//Show TZones without DLT
            el[i] = new Option(DST[i].Display+star,DST[i].Bias);
      }
      el[ind].selected = true;
      DLTEnd = endDLT(currYear,DST[ind]);
      DLTBeg = beginDLT(currYear,DST[ind]);
      DLTEnd1 = DLTEnd;
      DLTBeg1 = DLTBeg;
      DLTvalue = DSTvalue(DST[ind]);
      DLTvalue1 = DLTvalue;
      JSClock();
}

function fillLocalTZones(){
      el = document.Clock.TZone0.options;
      el.length = 0;
      for(i=0; i<DST.length; i++){
            if((DST[i].Bias-DSTvalue(DST[i])*60)*60000==TZoffset){
                  star = "";
                  if(DST[i].TZI[0]==0) star = "*";//Show TZones without DLT
                  el[el.length] = new Option(DST[i].Display+star,DST[i].Bias);
                  Ind[Ind.length] = i;
                  //if(el.length==1) ind = i;
            }
      }
      el[0].selected = true;
      return Ind[0];//ind;
}


function setTZone(){
      ind = Ind[document.Clock.TZone0.selectedIndex];
      TZoffset = (DST[ind].Bias-DSTvalue(DST[ind])*60)*60000;
      DLTEnd = endDLT(currYear,DST[ind]);
      DLTBeg = beginDLT(currYear,DST[ind]);
      DLTvalue = DSTvalue(DST[ind]);
}

function setTZone1(){
      ind1 = document.Clock.TZone.selectedIndex;
      TZoffset1 = (DST[ind1].Bias-DSTvalue(DST[ind1])*60)*60000;
      DLTEnd1 = endDLT(currYear,DST[ind1]);
      DLTBeg1 = beginDLT(currYear,DST[ind1]);
      DLTvalue1 = DSTvalue(DST[ind1]);
}

function time2string(time,DLT) {
      var date = time.getDate();
      var day = time.getDay();
      var month = time.getMonth();
      var year = time.getYear();
      var hour = time.getHours();
      var minute = time.getMinutes();
      var second = time.getSeconds();
      var temp = " ";
      switch (month) {
            case 0:
                  temp += "Jan ";
                  break;
            case 1:
                  temp += "Feb ";
                  break;
            case 2:
                  temp += "Mar ";
                  break;
            case 3:
                  temp += "Apr ";
                  break;
            case 4:
                  temp += "May ";
                  break;
            case 5:
                  temp += "Jun ";
                  break;
            case 6:
                  temp += "Jul ";
                  break;
            case 7:
                  temp += "Aug ";
                  break;
            case 8:
                  temp += "Sep ";
                  break;
            case 9:
                  temp += "Oct ";
                  break;
            case 10:
                  temp += "Nov ";
                  break;
            case 11:
                  temp += "Dec ";
                  break;
            default:
      }
      temp += date + " ";
      if (year<80)
            year += 2000;
      else
      if (year<100)
            year += 2000 - 80;
      else
      if (year<200)
            year += 1900;

      temp += year + " ";

      temp += ((hour > 12) ? hour - 12 : hour);
      temp += ((minute < 10) ? ":0" : ":") + minute;
  temp += ((second < 10) ? ":0" : ":") + second;
      temp += (hour >= 12) ? " PM" : " AM";
      if(DLT)
            temp += " DLT";
      else
            temp += " SDT";
      return temp;
}

function JSClock() {
      var time = new Date();
      temp = time2string(time,DLTvalue)
      document.Clock.digits.value=temp;
      if(DLTBeg!=0){
            temp = "DLT: "+(DLTBeg.getMonth()+1)+"/"+DLTBeg.getDate()+" "+DLTBeg.getHours()+":00 AM;";
            temp += "  SDT: "+(DLTEnd.getMonth()+1)+"/"+DLTEnd.getDate()+" "+DLTEnd.getHours()+":00 AM";
      }
      else
            temp = "No DLT for this time zone";
      document.Clock.DLT.value=temp;

      var msecs = time.getTime();
      msecs += TZoffset - TZoffset1;//Offset has inverse sign!
      time.setTime(msecs);
      //Check for possible changes of DLT correction:
      mm = time.getMinutes();
      ss = time.getSeconds();
      if(mm==0 && ss==1){//See whether DLT settings are changed:
            DLTvalue1new = DSTvalue(DST[ind1]);
            if(DLTvalue1new!=DLTvalue1){//DLT settings are just changed!
                  msecs += (DLTvalue1new-DLTvalue1)*60*60000;
                  DLTvalue1 = DLTvalue1new;
            }
      }
      temp = time2string(time,DLTvalue1);
      document.Clock.digits1.value=temp;
      if(DLTBeg1!=0){
            temp = "DLT: "+(DLTBeg1.getMonth()+1)+"/"+DLTBeg1.getDate()+" "+DLTBeg1.getHours()+":00 AM;";
            temp += "  SDT: "+(DLTEnd1.getMonth()+1)+"/"+DLTEnd1.getDate()+" "+DLTEnd1.getHours()+":00 AM";
      }
      else
            temp = "No DLT for this time zone";
      document.Clock.DLT1.value=temp;
      id = setTimeout("JSClock()",1000);
}
//-->
</script>

</head>

<body bgcolor="aqua" onLoad="Init();">

<form name="Clock">
<table>
<tr>
<td>Local Time Zones (* means no DLS):
<td>All Time Zones (* means no DLS):
<tr>
<td><SELECT NAME="TZone0" onChange="setTZone();">
<!-- The "virtual" options below are needed for NS only -->
<OPTION>(CHOOSE YOUR CURRENT TIME ZONE*****
<OPTION>
<OPTION>
<OPTION>
</SELECT>

<td><SELECT NAME="TZone" onChange="setTZone1();">
<!-- The "virtual" options below are needed for NS only -->
<OPTION>(CHOOSE YOUR CURRENT TIME ZONE**************)
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
</SELECT>
</table>


<br>
<br>

<table>
<tr>
<td><b>Local Time:</b>
<td><input type="text" name="digits" size=32>
<td>&nbsp;&nbsp;<input type="text" name="DLT" size=40>
<tr>
<td><b>Remote Time:</b>
<td><input type="text" name="digits1" size=32>
<td>&nbsp;&nbsp;<input type="text" name="DLT1" size=40>
</table>
<br><input type=button value="Show time formats" onClick="Show();">
</form>

</body>
</html>


*************************************
// TZones.js
var DSTlength = 62;

var DST = new Array;
for(i=0; i<DSTlength; i++) DST[i] = new Object;

// The DST array below is produced from
// exported registry Key ...\Time Zones on NT4+SP5
// using Multi-Edit for cut/paste & search/replace.
//
// Format of TZI:
// TZI=[month,DayOfWeek,week,hour,month,DayOfWeek,week,hour]
// where first 4 elements determine the moment when DST ends,
// another two --  the moment when DST starts; if month==0,
// there is no DST for the corresponding time zone; week==5
// means that is taken the biggest date with given DayOfWeek
// (the latter is 0 (=sunday) in most cases, but not always!)

DST[0].Display="(GMT+04:30) Kabul";
DST[0].TZI= [0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[1].Display="(GMT-09:00) Alaska";
DST[1].TZI= [0xa,0x0,0x5,0x2,0x4,0x0,0x1,0x2];


DST[2].Display="(GMT+04:00) Abu Dhabi, Muscat";
DST[2].TZI= [0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[3].Display="(GMT-04:00) Atlantic Time (Canada)";
DST[3].TZI= [0xa,0x0,0x5,0x2,0x4,0x0,0x1,0x2];


DST[4].Display="(GMT+09:30) Darwin";
DST[4].TZI= [0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[5].Display="(GMT-01:00) Azores, Cape Verde Is.";
DST[5].TZI= [0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[6].Display="(GMT+07:00) Bangkok, Hanoi, Jakarta";
DST[6].TZI= [0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[7].Display="(GMT-06:00) Saskatchewan";
DST[7].TZI= [0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[8].Display="(GMT+04:00) Baku, Tbilisi";
DST[8].TZI= [0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[9].Display="(GMT+09:30) Adelaide";
DST[9].TZI= [0x3,0x0,0x5,0x2,0xa,0x0,0x5,0x2];


DST[10].Display="(GMT+06:00) Almaty, Dhaka";
DST[10].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[11].Display="(GMT+01:00) Bratislava, Budapest, Ljubljana, Prague, Warsaw";
DST[11].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[12].Display="(GMT+01:00) Belgrade, Sarajevo, Skopje, Zagreb";
DST[12].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[13].Display="(GMT+11:00) Magadan, Solomon Is., New Caledonia";
DST[13].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[14].Display="(GMT-06:00) Central Time (US & Canada)";
DST[14].TZI=[0xa,0x0,0x5,0x2,0x4,0x0,0x1,0x2];


DST[15].Display="(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi";
DST[15].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[16].Display="(GMT-12:00) Eniwetok, Kwajalein";
DST[16].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[17].Display="(GMT+03:00) Nairobi";
DST[17].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[18].Display="(GMT+10:00) Brisbane";
DST[18].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[19].Display="(GMT+02:00) Bucharest, Sofia";
DST[19].TZI=[0x9,0x0,0x5,0x1,0x3,0x0,0x5,0x0];


DST[20].Display="(GMT-03:00) Brasilia";
DST[20].TZI=[0x2,0x0,0x2,0x2,0xa,0x0,0x3,0x2];


DST[21].Display="(GMT-05:00) Eastern Time (US & Canada)";
DST[21].TZI=[0xa,0x0,0x5,0x2,0x4,0x0,0x1,0x2];


DST[22].Display="(GMT+02:00) Cairo";
DST[22].TZI=[0x9,0x3,0x5,0x2,0x5,0x5,0x1,0x2];


DST[23].Display="(GMT+05:00) Ekaterinburg";
DST[23].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[24].Display="(GMT+12:00) Fiji, Kamchatka, Marshall Is.";
DST[24].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[25].Display="(GMT+02:00) Helsinki, Riga, Tallinn";
DST[25].TZI=[0xa,0x0,0x5,0x4,0x3,0x0,0x5,0x3];


DST[26].Display="(GMT+02:00) Athens, Istanbul, Minsk";
DST[26].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[27].Display="(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London";
DST[27].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[28].Display="(GMT) Casablanca, Monrovia";
DST[28].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[29].Display="(GMT-10:00) Hawaii";
DST[29].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[30].Display="(GMT+05:30) Bombay, Calcutta, Madras, New Delhi";
DST[30].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[31].Display="(GMT+03:30) Tehran";
DST[31].TZI=[0x9,0x2,0x4,0x2,0x3,0x0,0x1,0x2];


DST[32].Display="(GMT+02:00) Israel";
DST[32].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[33].Display="(GMT+09:00) Seoul";
DST[33].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[34].Display="(GMT-06:00) Mexico City, Tegucigalpa";
DST[34].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[35].Display="(GMT-02:00) Mid-Atlantic";
DST[35].TZI=[0x9,0x0,0x5,0x2,0x3,0x0,0x5,0x2];


DST[36].Display="(GMT-07:00) Mountain Time (US & Canada)";
DST[36].TZI=[0xa,0x0,0x5,0x2,0x4,0x0,0x1,0x2];


DST[37].Display="(GMT+12:00) Auckland, Wellington";
DST[37].TZI=[0x3,0x0,0x3,0x2,0xa,0x0,0x1,0x2];


DST[38].Display="(GMT-03:30) Newfoundland";
DST[38].TZI=[0xa,0x0,0x5,0x2,0x4,0x0,0x1,0x2];


DST[39].Display="(GMT-08:00) Pacific Time (US & Canada); Tijuana";
DST[39].TZI=[0xa,0x0,0x5,0x2,0x4,0x0,0x1,0x2];


DST[40].Display="(GMT+01:00)  Amsterdam, Copenhagen, Madrid, Paris, Vilnius";
DST[40].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[41].Display="(GMT+03:00) Moscow, St. Petersburg, Volgograd";
DST[41].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[42].Display="(GMT-03:00) Buenos Aires, Georgetown";
DST[42].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[43].Display="(GMT-05:00) Bogota, Lima, Quito";
DST[43].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[44].Display="(GMT-04:00) Caracas, La Paz";
DST[44].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[45].Display="(GMT-11:00) Midway Island, Samoa";
DST[45].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[46].Display="(GMT+03:00) Baghdad, Kuwait, Riyadh";
DST[46].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[47].Display="(GMT+08:00) Singapore";
DST[47].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[48].Display="(GMT+02:00) Harare, Pretoria";
DST[48].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[49].Display="(GMT+06:00) Colombo";
DST[49].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[50].Display="(GMT+10:00) Canberra, Melbourne, Sydney";
DST[50].TZI=[0x3,0x0,0x5,0x2,0xa,0x0,0x5,0x2];


DST[51].Display="(GMT+08:00) Taipei";
DST[51].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[52].Display="(GMT+10:00) Hobart";
DST[52].TZI=[0x3,0x0,0x5,0x2,0xa,0x0,0x1,0x2];


DST[53].Display="(GMT+09:00) Osaka, Sapporo, Tokyo";
DST[53].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[54].Display="(GMT-05:00) Indiana (East)";
DST[54].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[55].Display="(GMT-07:00) Arizona";
DST[55].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[56].Display="(GMT+10:00) Vladivostok";
DST[56].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[57].Display="(GMT+08:00) Perth";
DST[57].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[58].Display="(GMT+01:00) Brussels, Berlin, Bern, Rome, Stockholm, Vienna";
DST[58].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];


DST[59].Display="(GMT+05:00) Islamabad, Karachi, Tashkent";
DST[59].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[60].Display="(GMT+10:00) Guam, Port Moresby";
DST[60].TZI=[0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0];


DST[61].Display="(GMT+09:00) Yakutsk";
DST[61].TZI=[0xa,0x0,0x5,0x3,0x3,0x0,0x5,0x2];

//**********************************************
function GetDate(yy,mm,d,week){
      time = new Date(yy,mm,1);
      firstDay = time.getDay();
      var diff = (d-firstDay>=0)?d-firstDay:7+(d-firstDay);
      //fistDate = 1+diff;
      if(week<5){
            var date = 7*(week-1)+diff+1;
      }
      else{
            var date = 22 + diff;
            time.setDate(date+7);
            if(time.getDate()==date+7) date +=7;
      }
      return date;
}

//alert(GetDate(2000,8,0,5));//OK
//alert(GetDate(2000,8,6,5));//OK

function beginDLT(currYear,DSTZone) {
      if(DSTZone.TZI[0]==0) return 0;
      var date = GetDate(currYear,DSTZone.TZI[4]-1,DSTZone.TZI[5],DSTZone.TZI[6]);
      return new Date(currYear,DSTZone.TZI[4]-1,date,DSTZone.TZI[7],0,0);
}

function endDLT(currYear,DSTZone) {
      if(DSTZone.TZI[0]==0) return 0;
      var date = GetDate(currYear,DSTZone.TZI[0]-1,DSTZone.TZI[1],DSTZone.TZI[2]);
      return new Date(currYear,DSTZone.TZI[0]-1,date,DSTZone.TZI[3],0,0);
}

function DSTvalue(DSTZone) {
      if(!DSTZone.TZI[0] && !DSTZone.TZI[5]) return 0;//No DST Zone;
      //Absense of "var" below was the reason of nasty "Eastern time bug":
      //for some time zones (e.g. Central Time Zone) DSTvalue was zero.
      var time = new Date();//Local time! So neeeds to be corrected:
      var msecs = time.getTime();
      msecs += (time.getTimezoneOffset( )-DSTZone.Bias)*60000;
      time.setTime(msecs);//This is remote STD time already
      currYear = time.getYear();
      var DLTend = endDLT(currYear,DSTZone);
      var DLTbeg = beginDLT(currYear,DSTZone);
      //One more correction is needed (1 hour from DLTend):
      var diff = time.getTime() + 60*60*1000 - DLTend.getTime();
      //if(DSTZone.Bias==0) alert(diff);//OK
      if(diff>=0 && diff <=60*60*1000) return 0;
      //return 1;//The bug is somewhere here!
      if(DLTbeg.getTime()<DLTend.getTime()){//Northern hemisphere
            return (time<DLTend && time>DLTbeg)?1:0;
            //return (msecs<DLTend && msecs>DLTbeg)?1:0;//OK with msecs, bad with "time"?!
      }
      else{//Southern hemisphere
            return (time<DLTbeg && time>DLTend)?0:1;
      }
}
      /*
      var time = new Date();
      str = "diff="+(DLTEnd1-time)+"\n";
      str += "diff1="+(time-DLTBeg1)+"\n";
      str += "true="+((time>DLTBeg1) && (time<DLTBeg1))+"\n";
      alert(str);
      */

function GetBias(str){
      re = /((\+|\-)\d\d):(\d\d)/;
      if(!str) alert("BadString!");
      found = str.match(re);
      if(!found) return 0;
      if(!found[1]) alert("BadString: "+str);
      if(!found[3]) alert("BadString: "+str);
      bias = eval(found[1]*60) + eval(found[3]);
      return -bias;
}

function SetBias(){
      for(i=0; i<DSTlength; i++){
            DST[i].Bias = GetBias(DST[i].Display);
      }
}
SetBias();

//To Do: write routine for sorting DST array and sort it

Vlad
You have too much time on your hands, Vlad!!!

Could be somewhat shorter?
Like this:
months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
temp = months[month];

if (year ==0)  year = 2000;
else if (year<100) year += 1900

Michel
Avatar of alvin_stokes

ASKER

vmolot:

I think I must be putting the code into the wrong format.  I am using the TZones.js in conjunction with the rest of the code in an .htm.  Is this correct?  Could you please give me a quick rundown of how to incorporate your code. thanks.
Alvin
alvin_strokes: I have checked that the code is not corrupted by submission:
if one pastes the part of above comment
from <html> to </html> into html file
(with arbitrary name), and then
one pastes the part

// TZones.js
................
//To Do: write routine for sorting DST array and sort it

(string  ********************* not included!)
into the file named "TZones.js",
and then place both files in one and
the same directory, then everything is
OK (excepting one minor bug).
At least in IE5.5 (I had not tested it
yet in NS. It is high time to do this as well.

mplangian: You are right about temp,
it is, evidently, shorter. Thanks.

As to Y2K bug: what about year==1 to, say, 30? Well, some branches of the code
(taken almost verbatim from my old
code for clock showing web server time)
are unnecessary in the present context
(time is to be>=2000 here), but I had yet
more serious problems to think about just at the moment. E.g. I have just noticed
a new small bug in the functions
DLTBeg/End, determining the exact
moment of transition from SDT to DLT
and vise versa (incorrect results if
transition hour is 0 for a given time zione).

Vlad

PS: I have just tested it on NS4.7.
I was hoping that this time, at least,
there will be no need to struggle with NS,
writing NS specific code. Because in this
respect (time handling) NS is definitely better than IE, permitting one, potentially,
to determine the local time zone exactly:
Date.toString() in NS version of JS
contains Time Zone specific info
(like "E. European Daylight Time", contrary to that of IE.

And what happened? "Eastern time bug"
now is present in all time zones, in my own
as well :((((! So the time for cosmetic&aesthetic corrections is not yet come -- helas -- the struggle continues!
The latter bug turned out to be much less
misterious and perverse, then yesterday's
"Eastern time bug". To fix it, just replace

getYear()

in the function DSTvalue
from TZones.js by

getFullYear().

In current IE both functions give the same result, whereas
in NS -- not, so in NS the interval
between DLT and SDT was always
in the neighbourhood of the beginning
of the new era!

By the way, if one makes
the above replacement
in HTML file as well, then the whole
"Y2K fix" code,
can be dropped out as well. I.e. the lines:

if (year<80)
year += 2000;
else
if (year<100)
year += 2000 - 80;
else
if (year<200)
year += 1900;

in time2string() will become superfluous
(which, I hope, will make mplungjan happy :))).



Vlad
Hehe - only in v4 browsers ;-)

getFullYear is JS 1.2

Michel
I believe people holding yet the "gold" NS3
can be safely neglected: so small their number is. Otherwise, why not to write
code for NS 1 as well? Or "Mosaic"?
(there was such a great-great browser one time ;-)

Vlad


alvin_stokes: in addition to above.

The code is split into .HTM and .JS,
according to natural modularity principles,
to be easily reusable in other applications
(or even on the same site on other pages).
If You wish to merge both files in one
HTML file, you are simply to drop the 2 lines

<script language="javascript" src="TZones.js">
</script>

(they load TZones.js) at the begin of HTML
file and to paste all content of TZones.js
into HTML file right after the 2 lines:

<script language="javascript">
<!--

As to TZones.js,
I think, it will be even more convenient
to split it into 2 .js files:
one, containing definitions of TZones
(i.e. DST[] array), another one -- containing
the corresponding routines, dealing with this data. The reason for this new separation is, that there exist several DB's with time zones. For example, Time Zone
info in NT4 registry differs from that in
W95 (62 zones in NT, 51 in W95), and
both differ from that of W98 SE (63 time
zones); there are bugs in versions for
NT and 98 (the time zone for Sofia, Bulgaria, where I live is 1 hour nearer
to GMT then it really is). So, in order
to easily replace tables with time zones,
it is convenient to separate the part,
containing definitions of this table.
I plan to create one alternative Time Zone
table from W98 registry, hope it has less
bugs than this of NT, besides, Time Zones there are naturally ordered from the very beginning.

Vlad
When you are done I can add my US areacodes and we will have a mean javascript app ;-)

Michel
I have to admit this is pretty impressive.  I still can't completely grasp how you are getting the current timezones to change when I reset my windows timezone to various ones.  That's cool stuff.  
alvin_stokes: in addition to above.

The code is split into .HTM and .JS,
according to natural modularity principles,
to be easily reusable in other applications
(or even on the same site on other pages).
If You wish to merge both files in one
HTML file, you are simply to drop the 2 lines

<script language="javascript" src="TZones.js">
</script>

(they load TZones.js) at the begin of HTML
file and to paste all content of TZones.js
into HTML file right after the 2 lines:

<script language="javascript">
<!--

As to TZones.js,
I think, it will be even more convenient
to split it into 2 .js files:
one, containing definitions of TZones
(i.e. DST[] array), another one -- containing
the corresponding routines, dealing with this data. The reason for this new separation is, that there exist several DB's with time zones. For example, Time Zone
info in NT4 registry differs from that in
W95 (62 zones in NT, 51 in W95), and
both differ from that of W98 SE (63 time
zones); there are bugs in versions for
NT and 98 (the time zone for Sofia, Bulgaria, where I live is 1 hour nearer
to GMT then it really is). So, in order
to easily replace tables with time zones,
it is convenient to separate the part,
containing definitions of this table.
I plan to create one alternative Time Zone
table from W98 registry, hope it has less
bugs than this of NT, besides, Time Zones there are naturally ordered from the very beginning.

Vlad
mplungjan: Got it! ;-)) The new table
produced from W98 registry is almost ready.


Sorry for doubling the comment.
I was underslept today, and exhausted
struggling with the bug. Now it seems
the only one is left: incorrect date
of change from DLT to STD is displayed
(1 hour less; for the local PC's Time Zone
only).
Hope to fix it tomorrow, and now am going
to sleep.

By!

Vlad
vmolot,
Have you had any success with the last fix: (incorrect date
of change from DLT to STD is displayed
(1 hour less; for the local PC's Time Zone only). )

Let me know when you've got it and I will award your points.
Alvin
It was really a very subtle bug,
to safely fix it I was to rewrite almost all routines from the scratch.
Though this bug acts less than 1% of time
((30 DLT zones * 2 "singular" hours)/365 days), I think the true solution
must be correct at any moment of time
in any timezone. I.e. if in the remote T.Z.
SDT-->DLT transition occurs, say,
on 3/26 00:00, the clock for remote time
zone must show 01:00:00 just after
23:59:59. Now, in fact, I almost finished
with the new code, but I have to test it
in 3 time zones at least in neighbourhoods
of transition points DLT-->SDT and
SDT-->DLT (both for local and remote time
zones), to be sure that all bugs are excluded. I hope to send You the
"release version" to the end of the day
(i.e. 11PM at my GMT-3 timezone :).
By the way, local time zone is determined now practically uniquelly.

In fact, I plan to add further, in addition to
real time clocks for local and remote time zones a Time Zone convertor -- to beat
http://www.timezoneconverter.com. Their
converter is realized very clumsily:
after one chooses sorce and target timezones,
a date/time on the source timezone,
one is to submit this data to the server,
where the calculation of remote time takes place. This is very far from elegance:
all calculations can be made on the client,
and instead of static data for a fixed
source date/time it would be better
to start a pair of real time clocks
for both timezones.

The good thing is that the realization
of this additional functionality
will not take much time, compared to the time spend already on the realization
of "Time Zone API". Just one more simple function is to add for conversion of
time between arbitrary 2 time zones.
At the moment I have realizations for Local time->Remote time
and Remote time-->Local time, so the function in question will be just the combination of these two.


Vlad
A mistake in my last comment:
GMT-3 must be read GMT+3, of course.
I am thinking now in terms of TimezoneOffsets, which have sign
opposite to that of "GMT suffix" :)).
Release version is delayed to tomorrow --Sep 22.
Some minor bugs in Time zones without
DLT are to be fixed yet. Routines for
conversion from one remote Time zone
to another remote one are written already,
but are not tested yet.

Vlad
Release version is not ready yet:
some small bugs in promized Time Zone Convertor are to be fixed. Bugs in
"World clock" seems to be fixed, nevertheless.
You can see the current version at
http://theo.inrne.bas.bg/~vmolot/JS/TimeZones/TZones.htm
(and to download it with IE, of course :).

Vlad
ASKER CERTIFIED SOLUTION
Avatar of vmolot
vmolot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow!  VERY NICE

Michel
Thanks! Your approval means much more
to me then the points expected.
Were I not so crazy, I could earn, of course, much more in this 3 weeks, answering easy questions.
But this would be too boring as an occupation :)).

BTW, the link "View Time Zone Info"
on my site was not working, because
I renamed some of JS functions, forgetting
to make  the corresponding changes in
HTML. Now this is corrected.
TZonesAPI.js is mofified as well to ver.1.32.

And now I am transferring to JS the Java
Time Zones DB (java.util.TimeZone.java
from JDK1.3). It contains 321 Time Zones in general, versus 130 or so
"split by cities" Time zones of MS.

Vlad
And we can now add the US area codes ;-)
OK!

Meanwhile, I have now a rough, not debugged,
version of Java Time Zones array
(included in TZones.zip, as well
as ShowTZI0.htm, working with
TZonesJava.js instead of TZonesW98.js).
So You can compare it with Your
US codes, to see the differences.

Vlad
Truly awesome work Vlad!  The Scholars Deming and Juran would be proud of your continual improvement for sure.  Talk about Total Quality Assurance :)
thanks again,
Alvin

fyi... I increased the points as much as I could but unfortunately thats all the points I have at this time.
Vlad,

I'm very impressed with your work.  I was playing with your code and trying to change the instant timezone converter.  I'm looking to have a converter that will show the machine time and will also display the time of two different cities in the world.  (i.e.  i live in Chicago, but i want to know what's the time in London and what's the time in Sydney.)  Is it possible to have the Source Time: updated when the From time zone drop down box is changed?  Currently, the user can change the From time zone, but then the Target Time is adjusted incorrectly.

Thanks, Dan.
alvin_strokes: Thanks. And sorry if my comment
about "expected points" has forced You
to give me all Your points -- it was not intended
to cause this effect. I simply wanted to say,
that the problem was so interesting per se,
that the process of its solving was a reword
by himself.

dan_paganelis: Of course, You can change the behavior of "Source time"
while selecting new TZ in "From TZ".
For the purpose You are to modify
the function setTZone2() in TZones.htm.
Currently this function does not change
the Date2.View, because, generally
speaking, the "Source time" is not linked
to current PC time (You can modify it
in "Start Date/time"  boxes).
As to the "Target time", it changes
CORRECTLY w.r.t. to SOURCE time
(not PC time in world clock, because,
it is not linked to that time).
Or, at least should change correctly, if there are no subtle bugs left.

Vlad
Vlad: I understood but felt for all your effort you probably deserved more like 400 points!  I was lucky someone actually enjoyed solving this problem.  Thanks again.
Or, more simple: clock 1 is synchronized  with clock 2,
clock 3 is synchronized to clock 4, but the first pair
of clocks is NOT synchronized with the second one.
Only, as default initial behavior, times and
time zones in all 4 clocks coincide up to
the moment when some time zone or
start Date/time is changed by the user.

You can change this logic as You like:
to have 3 clocks: one for local time,
and 2 for to different timezones synchronyzed both to the local one
(just repeat the code for clock 2
with obvious changes of indexes 1-->2).

Vlad
Vlad, Thanks for the suggestion.  I'm going to give it a try.  

FYI, if you change the time zone settings in your Date/Time properties, the converter will adjust correctly, but the drop down boxes are incorrect.  If you change the Time Zone to Eastern (US & Canada) the box reads (GMT - 5) Unknown Time Zone.

Dan
I tried to repeat the code of clock 2 but I continue to run into problems.  I'm going to post a question on the board, and hopefully you can help me out.  The title of the question is:

Time Converter: local, 2 destinations

Thanks, Dan
dan_paganelis: I've testid the
clock on my NT4 in all 31 time zones
with DLT, and it recognized Eastern time
correctly. I conjecture, that somebody
has changed the corresponding settings
for Eastern time (this can be done with
TZEdit.exe from Win 98). Or You use
old Win95, where this settings may be
different from those in W98 (I took my DB
for time zones from Win98 SE).
Otherwise
the PC should recognize this settings,
if only they are:
DLT: 4/2/ 2:00 SDT: 10/29/ 2:00
for this zone. Would You please write
me what exactly this settings are for
Your "Unknown Time Zone"?

As to the new question, I'll look for it
tomorrow. Now I am to catch the bus
for home.

By now.

Vlad
vmolot/mplungian

I would like to take this world clock and manipulate it to have the following functionality:

-add two radio buttons, one that uses the current script to calcutate current time, and a second radiobutton that will allow the user to manually enter a specific time, hit a calculate button and display the corresponding time based on the timezone selected and time entered.  

If this is possible just send me a quick note and I will open a new 300 point question for this topic.  I can also send some screenshots of the GUI that I would like to have created.

thanks,
Alvin