Skip to content

Commit

Permalink
Version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Jul 21, 2014
1 parent f21ab0c commit 4923b19
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 57 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "moment-timezone",
"description" : "Parse and display moments in any timezone.",
"version": "0.1.0",
"version": "0.2.0",
"main": "builds/moment-timezone-with-data-2010-2020.js",
"dependencies" : {
"moment" : ">= 2.6.0"
Expand Down
102 changes: 79 additions & 23 deletions builds/moment-timezone-with-data-2010-2020.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! moment-timezone.js
//! version : 0.1.0
//! version : 0.2.0
//! author : Tim Wood
//! license : MIT
//! github.com/moment/moment-timezone
Expand All @@ -21,7 +21,7 @@
// Do not load moment-timezone a second time.
if (moment.tz !== undefined) { return moment; }

var VERSION = "0.1.0",
var VERSION = "0.2.0",
zones = {},
links = {};

Expand Down Expand Up @@ -119,14 +119,19 @@
************************************/

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) {
var target = +timestamp,
untils = this.untils,
Expand All @@ -143,13 +148,26 @@
var target = +timestamp,
offsets = this.offsets,
untils = this.untils,
i;
max = untils.length - 1,
offset, offsetNext, offsetPrev, i;

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;
}

for (i = 0; i < untils.length; i++) {
if (target < untils[i] - (offsets[i] * 60000)) {
if (target < untils[i] - (offset * 60000)) {
return offsets[i];
}
}

return offsets[max];
},

abbr : function (mom) {
Expand All @@ -170,27 +188,22 @@
}

function addZone (packed) {
var i, zone;
var i, zone, zoneName;

if (typeof packed === "string") {
packed = [packed];
}

for (i = 0; i < packed.length; i++) {
zone = new Zone(packed[i]);
zones[normalizeName(zone.name)] = zone;
zoneName = normalizeName(zone.name);
zones[zoneName] = zone;
upgradeLinksToZones(zoneName);
}
}

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;
}

function getNames () {
Expand All @@ -213,9 +226,42 @@
}

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);
}
}

Expand All @@ -239,6 +285,12 @@
return !!(m._a && (m._tzm === undefined));
}

function logError (message) {
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(message);
}
}

/************************************
moment.tz namespace
************************************/
Expand Down Expand Up @@ -272,6 +324,8 @@
tz.unpack = unpack;
tz.unpackBase60 = unpackBase60;
tz.needsOffset = needsOffset;
tz.moveInvalidForward = true;
tz.moveAmbiguousForward = false;

/************************************
Interface with Moment.js
Expand All @@ -297,6 +351,8 @@
this._z = getZone(name);
if (this._z) {
moment.updateOffset(this);
} else {
logError("Moment Timezone has no data for " + name + ". See http://momentjs.com/timezone/docs/#/data-loading/.");
}
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions builds/moment-timezone-with-data-2010-2020.min.js

Large diffs are not rendered by default.

102 changes: 79 additions & 23 deletions builds/moment-timezone-with-data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions builds/moment-timezone-with-data.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions builds/moment-timezone.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### `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_
* *Breaking:* Changed data format from Zones+Rules to just Zones. [#82](https://github.com/moment/moment-timezone/pull/82)
* *Breaking:* Removed `moment.tz.{addRule,addZone,zoneExists,zones}` as they are no longer relevant with the new data format.
Expand Down
2 changes: 1 addition & 1 deletion moment-timezone-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! moment-timezone-utils.js
//! version : 0.1.0
//! version : 0.2.0
//! author : Tim Wood
//! license : MIT
//! github.com/moment/moment-timezone
Expand Down
Loading

0 comments on commit 4923b19

Please sign in to comment.