Jon Nylander avatar Jon Nylander committed d711eec

Corrected the "olsen" typo which should be "olson" thoughout the code and documentation.

Comments (0)

Files changed (2)

detect_timezone.js

  * This code is  maintained at bitbucket.org as jsTimezoneDetect.
  */
 
-var ONE_HOUR_IN_MINUTES = 1000 * 60;
 var HEMISPHERE_SOUTH = 'SOUTH';
 var HEMISPHERE_NORTH = 'NORTH';
 var HEMISPHERE_UNKNOWN = 'N/A';
-var olsen = {}
+var olson = {}
 
 /**
  * The keys in this dictionary are comma separated as such:
- * First the offset compared to UTC time in minutes. 
+ * 
+ * First the offset compared to UTC time in minutes.
+ *  
  * Then a flag which is 0 if the timezone does not take daylight savings into account and 1 if it does.
  * Thirdly an optional 's' signifies that the timezone is in the southern hemisphere, only interesting for timezones with DST.
  * 
- * The values of the dictionary are objects of either TimeZone or NonOlsenTimeZone.
+ * The values of the dictionary are objects of either TimeZone.
  */
-olsen.timezones = {
+olson.timezones = {
 	'-720,0'   : new TimeZone('-12:00','Etc/GMT+12', false),
 	'-660,0'   : new TimeZone('-11:00','Pacific/Midway', false),
 	'-660,1,s' : new TimeZone('-11:00','Pacific/Apia', true),
 	'600,1'	   : new TimeZone('+10:00','Asia/Vladivostok', true),
 	'600,1,s'  : new TimeZone('+10:00','Australia/Melbourne', true),
 	'660,1'    : new TimeZone('+11:00','Asia/Magadan', true),
-	'660,0'    : new TimeZone('+11:00','Pacific/Ponape', false),
+	'660,0'    : new TimeZone('+11:00','Pacific/Pohnpei', false),
 	'720,1,s'  : new TimeZone('+12:00','Pacific/Auckland', true),
 	'720,0'    : new TimeZone('+12:00','Pacific/Wake', false),
 	'765,1,s'  : new TimeZone('+12:45','Pacific/Chatham', true),
  * 
  * Each value is a date denoting when daylight savings starts for that timezone.
  */
-olsen.dst_start_dates = {
+olson.dst_start_dates = {
 	'America/Denver' : new Date(2011, 2, 13, 3, 0, 0, 0),
 	'America/Chihuahua' : new Date(2011, 3, 3, 3, 0, 0, 0),
 	'America/Chicago' : new Date(2011, 2, 13, 3, 0, 0, 0),
 
 /**
  * The keys in this object are timezones that we know may be ambiguous after
- * a preliminary scan through the olsen_tz object.
+ * a preliminary scan through the olson_tz object.
  * 
  * The array of timezones to compare must be in the order that daylight savings
  * starts for the regions.
  */
-olsen.ambiguity_list = {
+olson.ambiguity_list = {
 	'America/Denver' : ['America/Denver','America/Chihuahua'],
 	'America/Chicago' : ['America/Chicago','America/Mexico_City'],
 	'America/Asuncion' : ['America/Asuncion', 'America/Santiago','America/Cuiaba'],
 }
 
 /**
- * A simple object containing information of utc_offset, which Olsen timezone key to use, 
+ * A simple object containing information of utc_offset, which olson timezone key to use, 
  * and if the timezone cares about daylight savings or not.
  * 
  * @constructor
  * @param {string} offset - for example '-11:00'
- * @param {string} olsen_tz - the olsen Identifier, such as "America/Denver"
+ * @param {string} olson_tz - the olson Identifier, such as "America/Denver"
  * @param {boolean} uses_dst - flag for whether the time zone somehow cares about daylight savings.
  */
-function TimeZone(offset, olsen_tz, uses_dst) {
+function TimeZone(offset, olson_tz, uses_dst) {
 	this.utc_offset = offset;
-	this.olsen_tz = olsen_tz;
+	this.olson_tz = olson_tz;
 	this.uses_dst = uses_dst;
 }
 
 TimeZone.prototype.display = function() {
 	this.ambiguity_check();
 	var response_text = '<b>UTC-offset</b>: ' + this.utc_offset + '<br/>';
-	response_text += '<b>Olsen database name</b>: ' + this.olsen_tz + '<br/>';
+	response_text += '<b>Olson database name</b>: ' + this.olson_tz + '<br/>';
 	response_text += '<b>Daylight Savings</b>: ' + (this.uses_dst ? 'yes' : 'no') + '<br>'
 	
 	return response_text;
  * timezones.
  */
 TimeZone.prototype.ambiguity_check = function() {
-	var local_ambiguity_list = olsen.ambiguity_list[this.olsen_tz];
+	var local_ambiguity_list = olson.ambiguity_list[this.olson_tz];
 	
 	if (typeof(local_ambiguity_list) == 'undefined') {
 		return;
 	for (var i = 0; i < length; i++) {
 		var tz = local_ambiguity_list[i]
 		
-		if (date_is_dst(olsen.dst_start_dates[tz])) {
-			this.olsen_tz = tz;
+		if (date_is_dst(olson.dst_start_dates[tz])) {
+			this.olson_tz = tz;
 			return;
 		}	
 	}
  * @returns {number}
  */
 function get_date_offset(date) {
-  var gmt_version = date.toGMTString();
+	var gmt_version = date.toGMTString();
 
-  gmt_version = gmt_version.substring(0, gmt_version.lastIndexOf(" ")); 
-  
-  var date2 = new Date(gmt_version);
-  var utc_offset = -date2.getTimezoneOffset();
+	gmt_version = gmt_version.substring(0, gmt_version.lastIndexOf(" ")); 
 
-  return utc_offset;
+	var date2 = new Date(gmt_version);
+
+	return -date2.getTimezoneOffset();
 }
 
 /**
 }
 
 /**
- * Uses get_timezone_info() to formulate a key to use in the olsen.timezones dictionary.
+ * Uses get_timezone_info() to formulate a key to use in the olson.timezones dictionary.
  * 
  * Returns a primitive object on the format:
  * {'timezone': TimeZone, 'key' : 'the key used to find the TimeZone object'}
 	
 	var tz_key = timezone_key_info.utc_offset + ',' + timezone_key_info.dst + hemisphere_suffix
 	
-	return {'timezone' : olsen.timezones[tz_key], 'key' : tz_key}
+	return {'timezone' : olson.timezones[tz_key], 'key' : tz_key}
 }
 
 /**

detect_timezone.min.js

-var ONE_HOUR_IN_MINUTES=6E4,HEMISPHERE_SOUTH="SOUTH",HEMISPHERE_NORTH="NORTH",HEMISPHERE_UNKNOWN="N/A",olsen={};
-olsen.timezones={"-720,0":new NonOlsenTimeZone("-12:00","International Datetime West",false),"-660,0":new TimeZone("-11:00","Pacific/Midway",false),"-660,1,s":new TimeZone("-11:00","Pacific/Apia",true),"-600,0":new TimeZone("-10:00","Pacific/Honolulu",false),"-540,1":new TimeZone("-09:00","America/Anchorage",true),"-480,1":new TimeZone("-08:00","America/Vancouver",true),"-420,0":new TimeZone("-07:00","America/Phoenix",false),"-420,1":new TimeZone("-07:00","America/Denver",true),"-360,0":new TimeZone("-06:00",
-"America/Regina",false),"-360,1":new TimeZone("-06:00","America/Chicago",true),"-300,0":new TimeZone("-05:00","America/Atikokan",false),"-300,1":new TimeZone("-05:00","America/Montreal",true),"-270,0":new TimeZone("-04:30","America/Caracas",false),"-240,1":new TimeZone("-04:00","America/Halifax",true),"-240,0":new TimeZone("-04:00","America/Manaus",false),"-240,1,s":new TimeZone("-04:00","America/Asuncion",true),"-210,1":new TimeZone("-03:30","America/St_Johns",true),"-180,1":new TimeZone("-03:00",
-"America/Godthab",true),"-180,0":new TimeZone("-03:00","America/Argentina/Buenos_Aires,",false),"-180,1,s":new TimeZone("-03:00","America/Montevideo",true),"-120,0":new TimeZone("-02:00","America/Noronha",true),"-120,1":new NonOlsenTimeZone("-02:00","Mid Atlantic",true),"-60,1":new TimeZone("-01:00","Atlantic/Azores",true),"-60,0":new TimeZone("-01:00","Atlantic/Cape_Verde",false),"0,0":new TimeZone("00:00","Atlantic/Reykjavik",false),"0,1":new TimeZone("00:00","Europe/Dublin",true),"60,1":new TimeZone("+01:00",
-"Europe/Amsterdam",true),"60,0":new TimeZone("+01:00","Africa/Porto-Novo",false),"60,1,s":new TimeZone("-01:00","Africa/Windhoek",true),"120,1":new TimeZone("+02:00","Asia/Beirut",true),"120,0":new TimeZone("+02:00","Africa/Harare",false),"180,1":new TimeZone("+03:00","Europe/Moscow",true),"180,0":new TimeZone("+03:00","Asia/Baghdad",false),"210,1":new TimeZone("+03:30","Asia/Tehran",true),"240,0":new TimeZone("+04:00","Asia/Dubai",false),"240,1":new TimeZone("+04:00","Asia/Yerevan",true),"270,0":new TimeZone("+04:30",
-"Asia/Kabul",false),"300,1":new TimeZone("+05:00","Asia/Yekaterinburg",true),"300,0":new TimeZone("+05:00","Asia/Karachi",false),"330,0":new TimeZone("+05:30","Asia/Kolkata",false),"345,0":new TimeZone("+05:45","Asia/Kathmandu",false),"360,0":new TimeZone("+06:00","Asia/Dhaka",false),"360,1":new TimeZone("+06:00","Asia/Novosibirsk",true),"390,0":new TimeZone("+06:30","Asia/Rangoon",false),"420,1":new TimeZone("+07:00","Asia/Krasnoyarsk",true),"420,0":new TimeZone("+07:00","Asia/Bangkok",false),"480,0":new TimeZone("+08:00",
-"Asia/Shanghai",false),"480,1":new TimeZone("+08:00","Asia/Irkutsk",true),"540,1":new TimeZone("+09:00","Asia/Yakutsk",true),"540,0":new TimeZone("+09:00","Asia/Seoul",false),"570,0":new TimeZone("+09:30","Australia/Darwin",false),"570,1,s":new TimeZone("+09:30","Australia/Adelaide",true),"600,0":new TimeZone("+10:00","Australia/Brisbane",false),"600,1":new TimeZone("+10:00","Asia/Vladivostok",true),"600,1,s":new TimeZone("+10:00","Australia/Melbourne",true),"660,1":new TimeZone("+11:00","Asia/Magadan Magadan, New Caledonia",
-true),"660,0":new TimeZone("+11:00","Pacific/Ponape",false),"720,1,s":new TimeZone("+12:00","Pacific/Auckland",true),"720,0":new TimeZone("+12:00","Pacific/Fiji",false),"780,0":new TimeZone("+13:00","Pacific/Tongatapu",false)};
-olsen.dst_start_dates={"America/Denver":new Date(2011,2,13,3,0,0,0),"America/Chihuahua":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(2011,9,2,3,0,0,0),"America/Santiago":new Date(2011,9,9,3,0,0,0),"America/Cuiaba":new Date(2011,9,16,5,0,0,0),"America/Montevideo":new Date(2011,9,2,2,0,0,0),"America/Sao_Paolo":new Date(2011,9,16,5,0,0,0),"Europe/Minsk":new Date(2011,2,27,5,0,0,0),"Europe/Helsinki":new Date(2011,
-2,27,7,0,0,0),"Asia/Beirut":new Date(2011,2,27,13,0,0,0),"Asia/Amman":new Date(2011,3,1,3,0,0,0),"Asia/Jerusalem":new Date(2011,3,1,23,0,0,0),"Africa/Cairo":new Date(2011,3,29,5,0,0,0),"Asia/Yerevan":new Date(2011,2,27,4,0,0,0),"Asia/Baku":new Date(2011,2,27,9,0,0,0),"Pacific/Auckland":new Date(2011,8,26,7,0,0,0),"Pacific/Fiji":new Date(2010,11,29,23,0,0,0)};
-olsen.ambiguity_list={"America/Denver":["America/Denver","America/Chihuahua"],"America/Chicago":["America/Chicago","America/Mexico_City"],"America/Asuncion":["America/Asuncion","America/Santiago","America/Cuiaba"],"America/Montevideo":["America/Montevideo","America/Sao_Paolo"],"Asia/Beirut":["Europe/Minsk","Europe/Helsinki","Asia/Beirut","Asia/Amman","Asia/Jerusalem","Africa/Cairo"],"Asia/Yerevan":["Asia/Yerevan","Asia/Baku"],"Pacific/Auckland":["Pacific/Auckland","Pacific/Fiji"]};
-function TimeZone(a,b,c){this.utc_offset=a;this.olsen_tz=b;this.uses_dst=c}TimeZone.prototype.display=function(){this.ambiguity_check();var a="<b>UTC-offset</b>: "+this.utc_offset+"<br/>";a+="<b>Olsen database name</b>: "+this.olsen_tz+"<br/>";a+="<b>Daylight Savings</b>: "+(this.uses_dst?"yes":"no")+"<br>";return a};
-TimeZone.prototype.ambiguity_check=function(){var a=olsen.ambiguity_list[this.olsen_tz];if(typeof a!="undefined")for(var b=a.length,c=0;c<b;c++){var d=a[c];if(date_is_dst(olsen.dst_start_dates[d])){this.olsen_tz=d;break}}};function NonOlsenTimeZone(a,b,c){this.utc_offset=a;this.tz_name=b;this.uses_dst=c}
-NonOlsenTimeZone.prototype.display=function(){var a='<b style="color: red;">This timezone is not mapped in the Olsen database</b><br/>';a+="<b>UTC-offset</b>: "+this.utc_offset+"<br/>";a+="<b>Time zone name</b>: "+this.tz_name+"<br/>";a+="<b>Daylight Savings</b>: "+(this.uses_dst?"yes":"no")+"<br/>";return a};function date_is_dst(a){var b=a.getMonth()>5?get_june_offset():get_january_offset();a=get_date_offset(a);return b-a!=0}
-function get_date_offset(a){var b=a.toGMTString();b=b.substring(0,b.lastIndexOf(" "));return(a-new Date(b))/ONE_HOUR_IN_MINUTES}function get_timezone_info(){var a=get_january_offset(),b=get_june_offset(),c=a-b;if(c<0)return{utc_offset:a,dst:1,hemisphere:HEMISPHERE_NORTH};else if(c>0)return{utc_offset:b,dst:1,hemisphere:HEMISPHERE_SOUTH};return{utc_offset:a,dst:0,hemisphere:HEMISPHERE_UNKNOWN}}function get_january_offset(){return get_date_offset(new Date(2011,0,1,0,0,0,0))}
-function get_june_offset(){return get_date_offset(new Date(2011,5,1,0,0,0,0))}function determine_timezone(){var a=get_timezone_info(),b="";if(a.hemisphere==HEMISPHERE_SOUTH)b=",s";a=a.utc_offset+","+a.dst+b;return{timezone:olsen.timezones[a],key:a}}
-function show_timezone_info(){var a=determine_timezone();response_text="No timezone found for "+a.key;response_text=typeof a.timezone=="undefined"?"No timezone found for "+a.key:a.timezone.display();document.getElementById("tz_info").innerHTML=response_text}onload=show_timezone_info;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.