Jon Nylander avatar Jon Nylander committed a9cf858

Simplified get_timezone_info() function into lookup_key() function.

Comments (0)

Files changed (1)

detect_timezone.js

 var jstz = (function () {
     'use strict';
     var HEMISPHERE_SOUTH = 'SOUTH',
-        HEMISPHERE_NORTH = 'NORTH',
-        HEMISPHERE_UNKNOWN = 'N/A',
         
         /** 
          * Gets the offset in minutes from UTC for a certain date.
          * This function does some basic calculations to create information about 
          * the user's timezone.
          * 
-         * Returns a primitive object on the format
-         * {'utc_offset' : -9, 'dst': 1, hemisphere' : 'north'}
-         * where dst is 1 if the region uses daylight savings.
+         * Returns a key that can be used to do lookups in jstz.olson.timezones.
          * 
-         * @returns {Object}  
+         * @returns {String}  
          */
-        get_timezone_info = function () {
+        
+        lookup_key = function () {
             var january_offset = get_january_offset(), 
                 june_offset = get_june_offset(), 
-                diff = get_january_offset() - get_june_offset(),
-                TzInfo = function (o, d, h) {
-                    this.utc_offset = o;
-                    this.dst = d;
-                    this.hemisphere = h;
-                };
-        
+                diff = get_january_offset() - get_june_offset();
+                
             if (diff < 0) {
-                return new TzInfo(january_offset, 1, HEMISPHERE_NORTH);
+                return january_offset + ",1";
             } else if (diff > 0) {
-                return new TzInfo(june_offset, 1, HEMISPHERE_SOUTH);
+                return june_offset + ",1," + HEMISPHERE_SOUTH;
             }
-    
-            return new TzInfo(january_offset, 0, HEMISPHERE_UNKNOWN);
+            
+            return january_offset + ",0";
         },
     
         /**
          * @returns Object 
          */
         determine_timezone = function () {
-            var timezone_key_info = get_timezone_info(),
-                hemisphere_suffix = timezone_key_info.hemisphere === HEMISPHERE_SOUTH ? ',s' : '',
-                tz_key = timezone_key_info.utc_offset + ',' + timezone_key_info.dst + hemisphere_suffix;
-                
-            return new jstz.TimeZone(jstz.olson.timezones[tz_key]);
+            var key = lookup_key();
+            return new jstz.TimeZone(jstz.olson.timezones[key]);
         };
     
     return {
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.