moment-timezone
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -0,1 +1,7 @@ | ||
### `0.2.0` _2014-07-21_ | ||
* Added the ability to configure whether ambiguous or invalid input is rolled forward or backward. [#101](https://github.com/moment/moment-timezone/pull/101) | ||
* Added `moment>=2.6.0` as a dependency in `bower.json`. [#107](https://github.com/moment/moment-timezone/issues/107) | ||
* Fixed getting the name of a zone that was added as a linked zone. [#104](https://github.com/moment/moment-timezone/pull/104) | ||
* Added an error message when a zone was not loaded. [#106](https://github.com/moment/moment-timezone/issues/106) | ||
### `0.1.0` _2014-06-23_ | ||
@@ -2,0 +8,0 @@ * *Breaking:* Changed data format from Zones+Rules to just Zones. [#82](https://github.com/moment/moment-timezone/pull/82) |
//! moment-timezone-utils.js | ||
//! version : 0.1.0 | ||
//! version : 0.2.0 | ||
//! author : Tim Wood | ||
@@ -4,0 +4,0 @@ //! license : MIT |
//! moment-timezone.js | ||
//! version : 0.1.0 | ||
//! version : 0.2.0 | ||
//! author : Tim Wood | ||
@@ -24,3 +24,3 @@ //! license : MIT | ||
var VERSION = "0.1.0", | ||
var VERSION = "0.2.0", | ||
zones = {}, | ||
@@ -123,10 +123,15 @@ links = {}; | ||
function Zone (packedString) { | ||
var unpacked = unpack(packedString); | ||
this.name = unpacked.name; | ||
this.abbrs = unpacked.abbrs; | ||
this.untils = unpacked.untils; | ||
this.offsets = unpacked.offsets; | ||
if (packedString) { | ||
this._set(unpack(packedString)); | ||
} | ||
} | ||
Zone.prototype = { | ||
_set : function (unpacked) { | ||
this.name = unpacked.name; | ||
this.abbrs = unpacked.abbrs; | ||
this.untils = unpacked.untils; | ||
this.offsets = unpacked.offsets; | ||
}, | ||
_index : function (timestamp) { | ||
@@ -148,9 +153,22 @@ var target = +timestamp, | ||
untils = this.untils, | ||
i; | ||
max = untils.length - 1, | ||
offset, offsetNext, offsetPrev, i; | ||
for (i = 0; i < untils.length; i++) { | ||
if (target < untils[i] - (offsets[i] * 60000)) { | ||
for (i = 0; i < max; i++) { | ||
offset = offsets[i]; | ||
offsetNext = offsets[i + 1]; | ||
offsetPrev = offsets[i ? i - 1 : i]; | ||
if (offset < offsetNext && tz.moveAmbiguousForward) { | ||
offset = offsetNext; | ||
} else if (offset > offsetPrev && tz.moveInvalidForward) { | ||
offset = offsetPrev; | ||
} | ||
if (target < untils[i] - (offset * 60000)) { | ||
return offsets[i]; | ||
} | ||
} | ||
return offsets[max]; | ||
}, | ||
@@ -176,3 +194,3 @@ | ||
function addZone (packed) { | ||
var i, zone; | ||
var i, zone, zoneName; | ||
@@ -185,3 +203,5 @@ if (typeof packed === "string") { | ||
zone = new Zone(packed[i]); | ||
zones[normalizeName(zone.name)] = zone; | ||
zoneName = normalizeName(zone.name); | ||
zones[zoneName] = zone; | ||
upgradeLinksToZones(zoneName); | ||
} | ||
@@ -191,10 +211,3 @@ } | ||
function getZone (name) { | ||
name = normalizeName(name); | ||
var linkName = links[name]; | ||
if (linkName && zones[linkName]) { | ||
name = linkName; | ||
} | ||
return zones[name] || null; | ||
return zones[normalizeName(name)] || null; | ||
} | ||
@@ -222,8 +235,41 @@ | ||
for (i = 0; i < aliases.length; i++) { | ||
alias = normalizeName(aliases[i]).split('|'); | ||
links[alias[0]] = alias[1]; | ||
links[alias[1]] = alias[0]; | ||
alias = aliases[i].split('|'); | ||
pushLink(alias[0], alias[1]); | ||
pushLink(alias[1], alias[0]); | ||
} | ||
} | ||
function upgradeLinksToZones (zoneName) { | ||
if (!links[zoneName]) { | ||
return; | ||
} | ||
var i, | ||
zone = zones[zoneName], | ||
linkNames = links[zoneName]; | ||
for (i = 0; i < linkNames.length; i++) { | ||
copyZoneWithName(zone, linkNames[i]); | ||
} | ||
links[zoneName] = null; | ||
} | ||
function copyZoneWithName (zone, name) { | ||
var linkZone = zones[normalizeName(name)] = new Zone(); | ||
linkZone._set(zone); | ||
linkZone.name = name; | ||
} | ||
function pushLink (zoneName, linkName) { | ||
zoneName = normalizeName(zoneName); | ||
if (zones[zoneName]) { | ||
copyZoneWithName(zones[zoneName], linkName); | ||
} else { | ||
links[zoneName] = links[zoneName] || []; | ||
links[zoneName].push(linkName); | ||
} | ||
} | ||
function loadData (data) { | ||
@@ -249,2 +295,8 @@ addZone(data.zones); | ||
function logError (message) { | ||
if (typeof console !== 'undefined' && typeof console.error === 'function') { | ||
console.error(message); | ||
} | ||
} | ||
/************************************ | ||
@@ -283,2 +335,4 @@ moment.tz namespace | ||
tz.needsOffset = needsOffset; | ||
tz.moveInvalidForward = true; | ||
tz.moveAmbiguousForward = false; | ||
@@ -309,2 +363,4 @@ /************************************ | ||
moment.updateOffset(this); | ||
} else { | ||
logError("Moment Timezone has no data for " + name + ". See http://momentjs.com/timezone/docs/#/data-loading/."); | ||
} | ||
@@ -311,0 +367,0 @@ return this; |
{ | ||
"name": "moment-timezone", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Parse and display moments in any timezone.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://momentjs.com/timezone/", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2336372
127689
0