Skip to content
This repository has been archived by the owner on Jan 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #167 from Enlighten/master
Browse files Browse the repository at this point in the history
Load an unloaded zone file linked from the backward file
  • Loading branch information
JamieRuderman committed Dec 17, 2014
2 parents 630bb50 + d978403 commit d11a8d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
7 changes: 7 additions & 0 deletions spec/tz.default.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ describe('TimezoneJS', function () {
expect(sampleTz).toBeDefined();
expect(sampleTz.tzAbbr).toEqual('ICT');
});

it('should load an unloaded zone file linked from the backward file', function () {
sampleTz = timezoneJS.timezone.getTzInfo(new Date(), 'Antarctica/South_Pole');
expect(timezoneJS.timezone.loadedZones).toEqual({ asia: true, antarctica: true, backward: true, australasia: true });
expect(sampleTz.tzAbbr).toEqual('NZDT');
});

});
27 changes: 17 additions & 10 deletions src/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@
// legacy zone we need the backward file for.
_this.loadZoneFile('backward');
return getZone(dt, tz);
} else if (t && t !== tz) {
//Load the linked zone found in the backward file
_this.lazyLoadZoneFiles(t);
return getZone(dt, t);
}
invalidTZError(t);
}
Expand Down Expand Up @@ -1049,16 +1053,7 @@
//Expose transport mechanism and allow overwrite.
this.transport = _transport;
this.getTzInfo = function (dt, tz, isUTC) {
//Lazy-load any zones not yet loaded.
if (this.loadingScheme === this.loadingSchemes.LAZY_LOAD) {
//Get the correct region for the zone.
var zoneFile = getRegionForTimezone(tz);
if (!zoneFile) {
throw new Error('Not a valid timezone ID.');
}
//Get the file and parse it -- use synchronous XHR.
this.loadZoneFiles(zoneFile);
}
this.lazyLoadZoneFiles(tz);
var z = getZone(dt, tz);
var off = +z[0];
//See if the offset needs adjustment.
Expand All @@ -1069,5 +1064,17 @@
var abbr = getAbbreviation(z, rule);
return { tzOffset: off, tzAbbr: abbr };
};
//Lazy-load any zones not yet loaded.
this.lazyLoadZoneFiles = function(tz) {
if (this.loadingScheme === this.loadingSchemes.LAZY_LOAD) {
//Get the correct region for the zone.
var zoneFile = getRegionForTimezone(tz);
if (!zoneFile) {
throw new Error('Not a valid timezone ID.');
}
//Get the file and parse it -- use synchronous XHR.
this.loadZoneFiles(zoneFile);
}
};
}();
}).call(typeof window !== "undefined" ? window : this);

0 comments on commit d11a8d5

Please sign in to comment.