Comparing version 4.0.0 to 4.1.0
72
index.js
var cacheHelpers = require("cache-helpers"), | ||
fs = require("fs"), | ||
path = require("path"), | ||
time = require("time"), | ||
util = require("util"), | ||
@@ -86,21 +85,4 @@ cacheZones = cacheHelpers.once(function(callback) { | ||
if(pointInZone(lat, lon, bounds, polygons)) { | ||
try { | ||
now = new time.Date() | ||
now.setTimezone(tzid) | ||
} | ||
catch(e) { | ||
/* If an error occurs (presumably from the time module, like if the | ||
* given `tzid` doesn't exist in your system's database), just give | ||
* up and use an Etc time, below. */ | ||
break | ||
} | ||
return callback(null, { | ||
tzid: tzid, | ||
abbr: now.getTimezoneAbbr(), | ||
offset: now.getTimezoneOffset() / -60 | ||
}) | ||
} | ||
if(pointInZone(lat, lon, bounds, polygons)) | ||
return callback(null, tzid); | ||
} | ||
@@ -115,29 +97,29 @@ | ||
switch(Math.round((lon + 180) / 15)) { | ||
case 0: return callback(null, {tzid: "Etc/GMT+12", offset: -12}) | ||
case 1: return callback(null, {tzid: "Etc/GMT+11", offset: -11}) | ||
case 2: return callback(null, {tzid: "Etc/GMT+10", offset: -10}) | ||
case 3: return callback(null, {tzid: "Etc/GMT+9", offset: -9}) | ||
case 4: return callback(null, {tzid: "Etc/GMT+8", offset: -8}) | ||
case 5: return callback(null, {tzid: "Etc/GMT+7", offset: -7}) | ||
case 6: return callback(null, {tzid: "Etc/GMT+6", offset: -6}) | ||
case 7: return callback(null, {tzid: "Etc/GMT+5", offset: -5}) | ||
case 8: return callback(null, {tzid: "Etc/GMT+4", offset: -4}) | ||
case 9: return callback(null, {tzid: "Etc/GMT+3", offset: -3}) | ||
case 10: return callback(null, {tzid: "Etc/GMT+2", offset: -2}) | ||
case 11: return callback(null, {tzid: "Etc/GMT+1", offset: -1}) | ||
case 12: return callback(null, {tzid: "Etc/GMT", offset: 0}) | ||
case 13: return callback(null, {tzid: "Etc/GMT-1", offset: 1}) | ||
case 14: return callback(null, {tzid: "Etc/GMT-2", offset: 2}) | ||
case 15: return callback(null, {tzid: "Etc/GMT-3", offset: 3}) | ||
case 16: return callback(null, {tzid: "Etc/GMT-4", offset: 4}) | ||
case 17: return callback(null, {tzid: "Etc/GMT-5", offset: 5}) | ||
case 18: return callback(null, {tzid: "Etc/GMT-6", offset: 6}) | ||
case 19: return callback(null, {tzid: "Etc/GMT-7", offset: 7}) | ||
case 20: return callback(null, {tzid: "Etc/GMT-8", offset: 8}) | ||
case 21: return callback(null, {tzid: "Etc/GMT-9", offset: 9}) | ||
case 22: return callback(null, {tzid: "Etc/GMT-10", offset: 10}) | ||
case 23: return callback(null, {tzid: "Etc/GMT-11", offset: 11}) | ||
case 24: return callback(null, {tzid: "Etc/GMT-12", offset: 12}) | ||
case 0: return callback(null, "Etc/GMT+12") | ||
case 1: return callback(null, "Etc/GMT+11") | ||
case 2: return callback(null, "Etc/GMT+10") | ||
case 3: return callback(null, "Etc/GMT+9") | ||
case 4: return callback(null, "Etc/GMT+8") | ||
case 5: return callback(null, "Etc/GMT+7") | ||
case 6: return callback(null, "Etc/GMT+6") | ||
case 7: return callback(null, "Etc/GMT+5") | ||
case 8: return callback(null, "Etc/GMT+4") | ||
case 9: return callback(null, "Etc/GMT+3") | ||
case 10: return callback(null, "Etc/GMT+2") | ||
case 11: return callback(null, "Etc/GMT+1") | ||
case 12: return callback(null, "Etc/GMT") | ||
case 13: return callback(null, "Etc/GMT-1") | ||
case 14: return callback(null, "Etc/GMT-2") | ||
case 15: return callback(null, "Etc/GMT-3") | ||
case 16: return callback(null, "Etc/GMT-4") | ||
case 17: return callback(null, "Etc/GMT-5") | ||
case 18: return callback(null, "Etc/GMT-6") | ||
case 19: return callback(null, "Etc/GMT-7") | ||
case 20: return callback(null, "Etc/GMT-8") | ||
case 21: return callback(null, "Etc/GMT-9") | ||
case 22: return callback(null, "Etc/GMT-10") | ||
case 23: return callback(null, "Etc/GMT-11") | ||
case 24: return callback(null, "Etc/GMT-12") | ||
} | ||
}) | ||
} |
{ | ||
"name": "tz-lookup", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "time zone lookup", | ||
@@ -19,4 +19,3 @@ "keywords": [ | ||
"dependencies": { | ||
"cache-helpers": "1.3.x", | ||
"time": "0.8.x" | ||
"cache-helpers": "1.3.x" | ||
}, | ||
@@ -23,0 +22,0 @@ "devDependencies": { |
@@ -22,5 +22,5 @@ tz-lookup | ||
> }) | ||
{ tzid: "America/New_York", abbr: "EDT", offset: -4 } | ||
"America/New_York" | ||
The data file is only loaded on-demand, so the first call to `tzLookup()` | ||
will take a while, but subsequent calls will go quite quickly. |
62
test.js
@@ -5,3 +5,3 @@ var assert = require("assert"), | ||
function check(lat, lon, tzid, offset1, offset2) { | ||
function check(lat, lon, tzid) { | ||
it( | ||
@@ -14,21 +14,3 @@ util.format("should give the right tzid and offset for %d,%d", lat, lon), | ||
assert.ok(tz.hasOwnProperty("tzid"), "expected object to have property \"tzid\"") | ||
assert.ok(tz.hasOwnProperty("offset"), "expected object to have property \"offset\"") | ||
assert.equal(tzid, tz.tzid) | ||
if(offset2) | ||
assert( | ||
tz.offset === offset1 || tz.offset === offset2, | ||
util.format( | ||
"expected %d to equal either %d or %d", | ||
tz.offset, | ||
offset1, | ||
offset2 | ||
) | ||
) | ||
else | ||
assert.equal(tz.offset, offset1) | ||
assert.equal(tz, tzid) | ||
done() | ||
@@ -41,22 +23,22 @@ }) | ||
describe("tz", function() { | ||
check( 40.7092, -74.01506, "America/New_York", -5, -4) | ||
check( 42.3668, -71.05459, "America/New_York", -5, -4) | ||
check( 41.8976, -87.62052, "America/Chicago", -6, -5) | ||
check( 47.6897, -122.4023, "America/Los_Angeles", -8, -7) | ||
check( 42.7235, -73.6931, "America/New_York", -5, -4) | ||
check( 42.5807, -83.0223, "America/Detroit", -5, -4) | ||
check( 36.8381, -84.8500, "America/Kentucky/Monticello", -5, -4) | ||
check( 40.1674, -85.3583, "America/Indiana/Indianapolis", -5, -4) | ||
check( 37.9643, -86.7453, "America/Indiana/Tell_City", -6, -5) | ||
check( 38.6043, -90.2417, "America/Chicago", -6, -5) | ||
check( 41.1591, -104.8261, "America/Denver", -7, -6) | ||
check( 35.1991, -111.6348, "America/Phoenix", -7) | ||
check( 43.1432, -115.6750, "America/Boise", -7, -6) | ||
check( 47.5886, -122.3382, "America/Los_Angeles", -8, -7) | ||
check( 58.3168, -134.4397, "America/Juneau", -9, -8) | ||
check( 21.4381, -158.0493, "Pacific/Honolulu", -10) | ||
check( 42.7000, -80.0000, "Etc/GMT+5", -5) | ||
check( 51.0036, -114.0161, "America/Edmonton", -7, -6) | ||
check(-16.4965, -68.1702, "America/La_Paz", -4) | ||
check(-31.9369, 115.84534, "Australia/Perth", 8) | ||
check( 40.7092, -74.01506, "America/New_York") | ||
check( 42.3668, -71.05459, "America/New_York") | ||
check( 41.8976, -87.62052, "America/Chicago") | ||
check( 47.6897, -122.4023, "America/Los_Angeles") | ||
check( 42.7235, -73.6931, "America/New_York") | ||
check( 42.5807, -83.0223, "America/Detroit") | ||
check( 36.8381, -84.8500, "America/Kentucky/Monticello") | ||
check( 40.1674, -85.3583, "America/Indiana/Indianapolis") | ||
check( 37.9643, -86.7453, "America/Indiana/Tell_City") | ||
check( 38.6043, -90.2417, "America/Chicago") | ||
check( 41.1591, -104.8261, "America/Denver") | ||
check( 35.1991, -111.6348, "America/Phoenix") | ||
check( 43.1432, -115.6750, "America/Boise") | ||
check( 47.5886, -122.3382, "America/Los_Angeles") | ||
check( 58.3168, -134.4397, "America/Juneau") | ||
check( 21.4381, -158.0493, "Pacific/Honolulu") | ||
check( 42.7000, -80.0000, "Etc/GMT+5") | ||
check( 51.0036, -114.0161, "America/Edmonton") | ||
check(-16.4965, -68.1702, "America/La_Paz") | ||
check(-31.9369, 115.84534, "Australia/Perth") | ||
}) |
9857846
1
10
1260
2
- Removedtime@0.8.x
- Removedbindings@1.5.0(transitive)
- Removeddebug@4.3.7(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedms@2.1.3(transitive)
- Removedtime@0.8.4(transitive)