Commits

Jon Nylander committed da47407

Set 2011 as reference year for the preliminary detection. This
should make the script more robust over time.

Also it fixed the problems with Pacific/Apia and Pacific/Fiji
being erroneously detected as Pacific/Tongataup and
Asia/Kamchatka respectively.

Comments (0)

Files changed (4)

   var jstz = (function () {
       'use strict';
       var HEMISPHERE_SOUTH = 's',
-
+          
+          /* This is the year used to do primary checkups */
+          REFERENCE_YEAR = 2011,
           /**
            * Gets the offset in minutes from UTC for a certain date.
            * @param {Date} date
 
           /**
            * This function does some basic calculations to create information about
-           * the user's timezone.
+           * the user's timezone. It uses REFERENCE_YEAR as a solid year for which
+           * the script has been tested rather than depend on the year set by the
+           * client device.
            *
            * Returns a key that can be used to do lookups in jstz.olson.timezones.
+           * eg: "720,1,2". 
            *
            * @returns {String}
            */
 
           lookup_key = function () {
-              var january_offset = get_january_offset(),
-                  june_offset = get_june_offset(),
-                  diff = get_january_offset() - get_june_offset();
+              var january_offset = get_january_offset(REFERENCE_YEAR),
+                  june_offset = get_june_offset(REFERENCE_YEAR),
+                  diff = january_offset - june_offset;
 
               if (diff < 0) {
                   return january_offset + ",1";
               var key = lookup_key();
               return new jstz.TimeZone(jstz.olson.timezones[key]);
           },
-          
+
           /**
            * This object contains information on when daylight savings starts for
            * different timezones.
                     'Asia/Gaza':            new Date(2009, 2, 28, 0, 30, 0, 0),
                     'Africa/Cairo':         new Date(2009, 3, 25, 0, 30, 0, 0),
                     'Pacific/Auckland':     new Date(2011, 8, 26, 7, 0, 0, 0),
-                    'Pacific/Fiji':         new Date(2010, 11, 29, 23, 0, 0, 0),
+                    'Pacific/Fiji':         new Date(2010, 10, 29, 23, 0, 0, 0),
                     'America/Halifax':      new Date(2011, 2, 13, 6, 0, 0, 0),
                     'America/Goose_Bay':    new Date(2011, 2, 13, 2, 1, 0, 0),
                     'America/Miquelon':     new Date(2011, 2, 13, 5, 0, 0, 0),
                     'Asia/Vladivostok':     ru_pre_dst_change,
                     'Asia/Kamchatka':       ru_pre_dst_change,
                     'Europe/Minsk':         ru_pre_dst_change,
+                    'Pacific/Apia':         new Date(2010, 10, 1, 1, 0, 0, 0),
                     'Australia/Perth':      new Date(2008, 10, 1, 1, 0, 0, 0)
                 };
 
               'Australia/Brisbane':   ['Asia/Yakutsk'],
               'Pacific/Noumea':       ['Asia/Vladivostok'],
               'Pacific/Tarawa':       ['Asia/Kamchatka'],
+              'Pacific/Tongatapu':    ['Pacific/Apia'],   
               'Africa/Johannesburg':  ['Asia/Gaza', 'Africa/Cairo'],
               'Asia/Baghdad':         ['Europe/Minsk']
           },
-/*! jstz - v1.0.5 - 2013-03-18 */
-(function(e){var t=function(){"use strict";var e="s",n=function(e){var t=-e.getTimezoneOffset();return t!==null?t:0},r=function(e,t,n){var r=new Date;return e!==undefined&&r.setFullYear(e),r.setDate(n),r.setMonth(t),r},i=function(e){return n(r(e,0,2))},s=function(e){return n(r(e,5,2))},o=function(e){var t=e.getMonth()>7?s(e.getFullYear()):i(e.getFullYear()),r=n(e);return t-r!==0},u=function(){var t=i(),n=s(),r=i()-s();return r<0?t+",1":r>0?n+",1,"+e:t+",0"},a=function(){var e=u();return new t.TimeZone(t.olson.timezones[e])},f=function(e){var t=new Date(2010,6,15,1,0,0,0),n={"America/Denver":new Date(2011,2,13,3,0,0,0),"America/Mazatlan":new Date(2011,3,3,3,0,0,0),"America/Chicago":new Date(2011,2,13,3,0,0,0),"America/Mexico_City":new Date(2011,3,3,3,0,0,0),"America/Asuncion":new Date(2012,9,7,3,0,0,0),"America/Santiago":new Date(2012,9,3,3,0,0,0),"America/Campo_Grande":new Date(2012,9,21,5,0,0,0),"America/Montevideo":new Date(2011,9,2,3,0,0,0),"America/Sao_Paulo":new Date(2011,9,16,5,0,0,0),"America/Los_Angeles":new Date(2011,2,13,8,0,0,0),"America/Santa_Isabel":new Date(2011,3,5,8,0,0,0),"America/Havana":new Date(2012,2,10,2,0,0,0),"America/New_York":new Date(2012,2,10,7,0,0,0),"Asia/Beirut":new Date(2011,2,27,1,0,0,0),"Europe/Helsinki":new Date(2011,2,27,4,0,0,0),"Europe/Istanbul":new Date(2011,2,28,5,0,0,0),"Asia/Damascus":new Date(2011,3,1,2,0,0,0),"Asia/Jerusalem":new Date(2011,3,1,6,0,0,0),"Asia/Gaza":new Date(2009,2,28,0,30,0,0),"Africa/Cairo":new Date(2009,3,25,0,30,0,0),"Pacific/Auckland":new Date(2011,8,26,7,0,0,0),"Pacific/Fiji":new Date(2010,11,29,23,0,0,0),"America/Halifax":new Date(2011,2,13,6,0,0,0),"America/Goose_Bay":new Date(2011,2,13,2,1,0,0),"America/Miquelon":new Date(2011,2,13,5,0,0,0),"America/Godthab":new Date(2011,2,27,1,0,0,0),"Europe/Moscow":t,"Asia/Yekaterinburg":t,"Asia/Omsk":t,"Asia/Krasnoyarsk":t,"Asia/Irkutsk":t,"Asia/Yakutsk":t,"Asia/Vladivostok":t,"Asia/Kamchatka":t,"Europe/Minsk":t,"Australia/Perth":new Date(2008,10,1,1,0,0,0)};return n[e]};return{determine:a,date_is_dst:o,dst_start_for:f}}();t.TimeZone=function(e){"use strict";var n={"America/Denver":["America/Denver","America/Mazatlan"],"America/Chicago":["America/Chicago","America/Mexico_City"],"America/Santiago":["America/Santiago","America/Asuncion","America/Campo_Grande"],"America/Montevideo":["America/Montevideo","America/Sao_Paulo"],"Asia/Beirut":["Asia/Beirut","Europe/Helsinki","Europe/Istanbul","Asia/Damascus","Asia/Jerusalem","Asia/Gaza"],"Pacific/Auckland":["Pacific/Auckland","Pacific/Fiji"],"America/Los_Angeles":["America/Los_Angeles","America/Santa_Isabel"],"America/New_York":["America/Havana","America/New_York"],"America/Halifax":["America/Goose_Bay","America/Halifax"],"America/Godthab":["America/Miquelon","America/Godthab"],"Asia/Dubai":["Europe/Moscow"],"Asia/Dhaka":["Asia/Yekaterinburg"],"Asia/Jakarta":["Asia/Omsk"],"Asia/Shanghai":["Asia/Krasnoyarsk","Australia/Perth"],"Asia/Tokyo":["Asia/Irkutsk"],"Australia/Brisbane":["Asia/Yakutsk"],"Pacific/Noumea":["Asia/Vladivostok"],"Pacific/Tarawa":["Asia/Kamchatka"],"Africa/Johannesburg":["Asia/Gaza","Africa/Cairo"],"Asia/Baghdad":["Europe/Minsk"]},r=e,i=function(){var e=n[r],i=e.length,s=0,o=e[0];for(;s<i;s+=1){o=e[s];if(t.date_is_dst(t.dst_start_for(o))){r=o;return}}},s=function(){return typeof n[r]!="undefined"};return s()&&i(),{name:function(){return r}}},t.olson={},t.olson.timezones={"-720,0":"Pacific/Majuro","-660,0":"Pacific/Pago_Pago","-600,1":"America/Adak","-600,0":"Pacific/Honolulu","-570,0":"Pacific/Marquesas","-540,0":"Pacific/Gambier","-540,1":"America/Anchorage","-480,1":"America/Los_Angeles","-480,0":"Pacific/Pitcairn","-420,0":"America/Phoenix","-420,1":"America/Denver","-360,0":"America/Guatemala","-360,1":"America/Chicago","-360,1,s":"Pacific/Easter","-300,0":"America/Bogota","-300,1":"America/New_York","-270,0":"America/Caracas","-240,1":"America/Halifax","-240,0":"America/Santo_Domingo","-240,1,s":"America/Santiago","-210,1":"America/St_Johns","-180,1":"America/Godthab","-180,0":"America/Argentina/Buenos_Aires","-180,1,s":"America/Montevideo","-120,0":"America/Noronha","-120,1":"America/Noronha","-60,1":"Atlantic/Azores","-60,0":"Atlantic/Cape_Verde","0,0":"UTC","0,1":"Europe/London","60,1":"Europe/Berlin","60,0":"Africa/Lagos","60,1,s":"Africa/Windhoek","120,1":"Asia/Beirut","120,0":"Africa/Johannesburg","180,0":"Asia/Baghdad","180,1":"Europe/Moscow","210,1":"Asia/Tehran","240,0":"Asia/Dubai","240,1":"Asia/Baku","270,0":"Asia/Kabul","300,1":"Asia/Yekaterinburg","300,0":"Asia/Karachi","330,0":"Asia/Kolkata","345,0":"Asia/Kathmandu","360,0":"Asia/Dhaka","360,1":"Asia/Omsk","390,0":"Asia/Rangoon","420,1":"Asia/Krasnoyarsk","420,0":"Asia/Jakarta","480,0":"Asia/Shanghai","480,1":"Asia/Irkutsk","525,0":"Australia/Eucla","525,1,s":"Australia/Eucla","540,1":"Asia/Yakutsk","540,0":"Asia/Tokyo","570,0":"Australia/Darwin","570,1,s":"Australia/Adelaide","600,0":"Australia/Brisbane","600,1":"Asia/Vladivostok","600,1,s":"Australia/Sydney","630,1,s":"Australia/Lord_Howe","660,1":"Asia/Kamchatka","660,0":"Pacific/Noumea","690,0":"Pacific/Norfolk","720,1,s":"Pacific/Auckland","720,0":"Pacific/Tarawa","765,1,s":"Pacific/Chatham","780,0":"Pacific/Tongatapu","780,1,s":"Pacific/Apia","840,0":"Pacific/Kiritimati"},typeof exports!="undefined"?exports.jstz=t:e.jstz=t})(this);
+/*! jsTimezoneDetect - v1.0.5 - 2013-04-01 */
+(function(e){var t=function(){"use strict";var e="s",n=2011,r=function(e){var t=-e.getTimezoneOffset();return t!==null?t:0},i=function(e,t,n){var r=new Date;return e!==undefined&&r.setFullYear(e),r.setDate(n),r.setMonth(t),r},s=function(e){return r(i(e,0,2))},o=function(e){return r(i(e,5,2))},u=function(e){var t=e.getMonth()>7?o(e.getFullYear()):s(e.getFullYear()),n=r(e);return t-n!==0},a=function(){var t=s(n),r=o(n),i=t-r;return i<0?t+",1":i>0?r+",1,"+e:t+",0"},f=function(){var e=a();return new t.TimeZone(t.olson.timezones[e])},l=function(e){var t=new Date(2010,6,15,1,0,0,0),n={"America/Denver":new Date(2011,2,13,3,0,0,0),"America/Mazatlan":new Date(2011,3,3,3,0,0,0),"America/Chicago":new Date(2011,2,13,3,0,0,0),"America/Mexico_City":new Date(2011,3,3,3,0,0,0),"America/Asuncion":new Date(2012,9,7,3,0,0,0),"America/Santiago":new Date(2012,9,3,3,0,0,0),"America/Campo_Grande":new Date(2012,9,21,5,0,0,0),"America/Montevideo":new Date(2011,9,2,3,0,0,0),"America/Sao_Paulo":new Date(2011,9,16,5,0,0,0),"America/Los_Angeles":new Date(2011,2,13,8,0,0,0),"America/Santa_Isabel":new Date(2011,3,5,8,0,0,0),"America/Havana":new Date(2012,2,10,2,0,0,0),"America/New_York":new Date(2012,2,10,7,0,0,0),"Asia/Beirut":new Date(2011,2,27,1,0,0,0),"Europe/Helsinki":new Date(2011,2,27,4,0,0,0),"Europe/Istanbul":new Date(2011,2,28,5,0,0,0),"Asia/Damascus":new Date(2011,3,1,2,0,0,0),"Asia/Jerusalem":new Date(2011,3,1,6,0,0,0),"Asia/Gaza":new Date(2009,2,28,0,30,0,0),"Africa/Cairo":new Date(2009,3,25,0,30,0,0),"Pacific/Auckland":new Date(2011,8,26,7,0,0,0),"Pacific/Fiji":new Date(2010,10,29,23,0,0,0),"America/Halifax":new Date(2011,2,13,6,0,0,0),"America/Goose_Bay":new Date(2011,2,13,2,1,0,0),"America/Miquelon":new Date(2011,2,13,5,0,0,0),"America/Godthab":new Date(2011,2,27,1,0,0,0),"Europe/Moscow":t,"Asia/Yekaterinburg":t,"Asia/Omsk":t,"Asia/Krasnoyarsk":t,"Asia/Irkutsk":t,"Asia/Yakutsk":t,"Asia/Vladivostok":t,"Asia/Kamchatka":t,"Europe/Minsk":t,"Pacific/Apia":new Date(2010,10,1,1,0,0,0),"Australia/Perth":new Date(2008,10,1,1,0,0,0)};return n[e]};return{determine:f,date_is_dst:u,dst_start_for:l}}();t.TimeZone=function(e){"use strict";var n={"America/Denver":["America/Denver","America/Mazatlan"],"America/Chicago":["America/Chicago","America/Mexico_City"],"America/Santiago":["America/Santiago","America/Asuncion","America/Campo_Grande"],"America/Montevideo":["America/Montevideo","America/Sao_Paulo"],"Asia/Beirut":["Asia/Beirut","Europe/Helsinki","Europe/Istanbul","Asia/Damascus","Asia/Jerusalem","Asia/Gaza"],"Pacific/Auckland":["Pacific/Auckland","Pacific/Fiji"],"America/Los_Angeles":["America/Los_Angeles","America/Santa_Isabel"],"America/New_York":["America/Havana","America/New_York"],"America/Halifax":["America/Goose_Bay","America/Halifax"],"America/Godthab":["America/Miquelon","America/Godthab"],"Asia/Dubai":["Europe/Moscow"],"Asia/Dhaka":["Asia/Yekaterinburg"],"Asia/Jakarta":["Asia/Omsk"],"Asia/Shanghai":["Asia/Krasnoyarsk","Australia/Perth"],"Asia/Tokyo":["Asia/Irkutsk"],"Australia/Brisbane":["Asia/Yakutsk"],"Pacific/Noumea":["Asia/Vladivostok"],"Pacific/Tarawa":["Asia/Kamchatka"],"Pacific/Tongatapu":["Pacific/Apia"],"Africa/Johannesburg":["Asia/Gaza","Africa/Cairo"],"Asia/Baghdad":["Europe/Minsk"]},r=e,i=function(){var e=n[r],i=e.length,s=0,o=e[0];for(;s<i;s+=1){o=e[s];if(t.date_is_dst(t.dst_start_for(o))){r=o;return}}},s=function(){return typeof n[r]!="undefined"};return s()&&i(),{name:function(){return r}}},t.olson={},t.olson.timezones={"-720,0":"Pacific/Majuro","-660,0":"Pacific/Pago_Pago","-600,1":"America/Adak","-600,0":"Pacific/Honolulu","-570,0":"Pacific/Marquesas","-540,0":"Pacific/Gambier","-540,1":"America/Anchorage","-480,1":"America/Los_Angeles","-480,0":"Pacific/Pitcairn","-420,0":"America/Phoenix","-420,1":"America/Denver","-360,0":"America/Guatemala","-360,1":"America/Chicago","-360,1,s":"Pacific/Easter","-300,0":"America/Bogota","-300,1":"America/New_York","-270,0":"America/Caracas","-240,1":"America/Halifax","-240,0":"America/Santo_Domingo","-240,1,s":"America/Santiago","-210,1":"America/St_Johns","-180,1":"America/Godthab","-180,0":"America/Argentina/Buenos_Aires","-180,1,s":"America/Montevideo","-120,0":"America/Noronha","-120,1":"America/Noronha","-60,1":"Atlantic/Azores","-60,0":"Atlantic/Cape_Verde","0,0":"UTC","0,1":"Europe/London","60,1":"Europe/Berlin","60,0":"Africa/Lagos","60,1,s":"Africa/Windhoek","120,1":"Asia/Beirut","120,0":"Africa/Johannesburg","180,0":"Asia/Baghdad","180,1":"Europe/Moscow","210,1":"Asia/Tehran","240,0":"Asia/Dubai","240,1":"Asia/Baku","270,0":"Asia/Kabul","300,1":"Asia/Yekaterinburg","300,0":"Asia/Karachi","330,0":"Asia/Kolkata","345,0":"Asia/Kathmandu","360,0":"Asia/Dhaka","360,1":"Asia/Omsk","390,0":"Asia/Rangoon","420,1":"Asia/Krasnoyarsk","420,0":"Asia/Jakarta","480,0":"Asia/Shanghai","480,1":"Asia/Irkutsk","525,0":"Australia/Eucla","525,1,s":"Australia/Eucla","540,1":"Asia/Yakutsk","540,0":"Asia/Tokyo","570,0":"Australia/Darwin","570,1,s":"Australia/Adelaide","600,0":"Australia/Brisbane","600,1":"Asia/Vladivostok","600,1,s":"Australia/Sydney","630,1,s":"Australia/Lord_Howe","660,1":"Asia/Kamchatka","660,0":"Pacific/Noumea","690,0":"Pacific/Norfolk","720,1,s":"Pacific/Auckland","720,0":"Pacific/Tarawa","765,1,s":"Pacific/Chatham","780,0":"Pacific/Tongatapu","780,1,s":"Pacific/Apia","840,0":"Pacific/Kiritimati"},typeof exports!="undefined"?exports.jstz=t:e.jstz=t})(this);

test/smoke_tests.sh

 # the timezone of the system by copying the timezone to /etc/localtime.
 #
 
-timezones=( 'Pacific/Pago_Pago' 
-			'America/Adak'
-			'Pacific/Honolulu'
-			'Pacific/Marquesas'
-			'Pacific/Gambier'
-			'America/Anchorage'
-			'America/Los_Angeles'
-			'Pacific/Pitcairn'
-			'America/Phoenix'
-			'America/Denver'
-			'America/Guatemala'
-			'America/Chicago'
-			'Pacific/Easter'
-			'America/Bogota'
-			'America/New_York'
-			'America/Caracas'
-			'America/Halifax'
-			'America/Santo_Domingo'
-			'America/Santiago'
-			'America/St_Johns'
-			'America/Godthab'
-			'America/Argentina/Buenos_Aires'
-			'America/Montevideo'
-			'America/Noronha'
-			'Atlantic/Azores'
-			'Atlantic/Cape_Verde'
-			'UTC'
-			'Europe/London'
-			'Europe/Berlin'
-			'Africa/Lagos'
-			'Africa/Windhoek'
-			'Asia/Beirut'
-			'Africa/Johannesburg'
-			'Asia/Baghdad'
-      		'Asia/Tehran'
-			'Asia/Dubai'
-			'Asia/Baku'
-			'Asia/Kabul'
-      		'Asia/Karachi'
-			'Asia/Kolkata'
-			'Asia/Kathmandu'
-			'Asia/Dhaka'
-			'Asia/Rangoon'
-			'Asia/Jakarta'
-			'Asia/Shanghai'
-			'Australia/Eucla'
-			'Asia/Tokyo'
-			'Australia/Darwin'
-			'Australia/Adelaide'
-			'Australia/Brisbane'
-			'Australia/Sydney'
-			'Pacific/Noumea'
-      		'Pacific/Norfolk'
-			'Pacific/Auckland'
-			'Pacific/Tarawa'
-			'Pacific/Chatham'
-			'Pacific/Tongatapu'
-			'Pacific/Apia'
-			'Pacific/Kiritimati')
+timezones=('Pacific/Pago_Pago'
+'America/Adak'
+'Pacific/Honolulu'
+'Pacific/Marquesas'
+'Pacific/Gambier'
+'America/Anchorage'
+'America/Los_Angeles'
+'Pacific/Pitcairn'
+'America/Phoenix'
+'America/Denver'
+'America/Guatemala'
+'America/Chicago'
+'Pacific/Easter'
+'America/Bogota'
+'America/New_York'
+'America/Caracas'
+'America/Halifax'
+'America/Santo_Domingo'
+'America/Santiago'
+'America/St_Johns'
+'America/Godthab'
+'America/Argentina/Buenos_Aires'
+'America/Montevideo'
+'America/Noronha'
+'Atlantic/Azores'
+'Atlantic/Cape_Verde'
+'UTC'
+'Europe/London'
+'Europe/Berlin'
+'Africa/Lagos'
+'Africa/Windhoek'
+'Asia/Beirut'
+'Africa/Johannesburg'
+'Asia/Baghdad'
+'Asia/Tehran'
+'Asia/Dubai'
+'Asia/Baku'
+'Asia/Kabul'
+'Asia/Karachi'
+'Asia/Kolkata'
+'Asia/Kathmandu'
+'Asia/Dhaka'
+'Asia/Rangoon'
+'Asia/Jakarta'
+'Asia/Shanghai'
+'Australia/Eucla'
+'Asia/Tokyo'
+'Australia/Darwin'
+'Australia/Adelaide'
+'Australia/Brisbane'
+'Australia/Sydney'
+'Pacific/Noumea'
+'Pacific/Norfolk'
+'Pacific/Auckland'
+'Pacific/Tarawa'
+'Pacific/Chatham'
+'Pacific/Tongatapu'
+'Pacific/Apia'
+'Pacific/Kiritimati')
 
 ambigous_zones=('America/Mazatlan'
-			    'America/Mexico_City'
-			    'America/Asuncion'
-			    'America/Campo_Grande'
-			    'America/Sao_Paulo'
-			    'Asia/Gaza'
-			    'Europe/Helsinki'
-			    'Europe/Istanbul'
-			    'Asia/Damascus'
-			    'Asia/Jerusalem'
-			    'Pacific/Fiji'
-			    'America/Santa_Isabel'
-			    'America/Havana'
-			    'America/Goose_Bay'
-			    'America/Miquelon'
-			    'Africa/Cairo'
-				'Europe/Moscow'
-			    'Asia/Yekaterinburg'
-			    'Asia/Omsk'
-			    'Asia/Krasnoyarsk'
-			    'Asia/Irkutsk'
-			    'Asia/Yakutsk'
-			    'Asia/Vladivostok'
-			    'Asia/Kamchatka'
-			    'Europe/Minsk'
-          		'Australia/Perth')
+'America/Mexico_City'
+'America/Asuncion'
+'America/Campo_Grande'
+'America/Sao_Paulo'
+'Asia/Gaza'
+'Europe/Helsinki'
+'Europe/Istanbul'
+'Asia/Damascus'
+'Asia/Jerusalem'
+'Pacific/Fiji'
+'America/Santa_Isabel'
+'America/Havana'
+'America/Goose_Bay'
+'America/Miquelon'
+'Africa/Cairo'
+'Europe/Moscow'
+'Asia/Yekaterinburg'
+'Asia/Omsk'
+'Asia/Krasnoyarsk'
+'Asia/Irkutsk'
+'Asia/Yakutsk'
+'Asia/Vladivostok'
+'Asia/Kamchatka'
+'Europe/Minsk'
+'Australia/Perth')
 
 failure_count=0
 for tz in "${timezones[@]}"
-<!doctype html>
+<!DOCTYPE html>
 <html>
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     <script type="text/javascript" src="../jstz.js"></script>
     <script type="text/javascript">
+         var TimeZoneTester = function () {
+             var self = this;
+             
+             self.tested_timezones = [];
+             
+             self.detect = function () {
+                 var tz_name = jstz.determine().name();
+             };
+         };
         function detect() {
             var tz = jstz.determine();
-            document.write(tz.name());
+            
             setTimeout("window.location.reload()", 2000);
         }
     </script>