Skip to content

Commit

Permalink
Extend getTzInfo to allow calling it with UTC time (instead of local …
Browse files Browse the repository at this point in the history
…time)
  • Loading branch information
jannic committed Apr 3, 2010
1 parent 7b814a9 commit 11c416d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/date.js
Expand Up @@ -800,7 +800,7 @@ timezoneJS.timezone = new function() {
}
return true;
};
this.getTzInfo = function(dt, tz) {
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
Expand All @@ -818,7 +818,7 @@ timezoneJS.timezone = new function() {
var zone = getZone(dt, tz);
var off = getBasicOffset(zone);
// See if the offset needs adjustment
var rule = getRule(dt, zone);
var rule = getRule(dt, zone, isUTC);
if (rule) {
off = getAdjustedOffset(off, rule);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/test.html
Expand Up @@ -132,6 +132,29 @@
assertEquals('Test abbrev. for british summer time','BST', dt.tzAbbr);
}

var test_timezoneFromUTC = function() {
var dt;
dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-28T01:59:59'), 'Europe/Berlin'); // CET, from local time
assertEquals('CET, from local time','CET', dt.tzAbbr);
dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-28T03:00:00'), 'Europe/Berlin'); // CEST, from local time
assertEquals('CEST, from local time','CEST', dt.tzAbbr);

dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-28T00:59:59'), 'Europe/Berlin', true); // CET, from UTC
assertEquals('CET, from UTC','CET', dt.tzAbbr);
dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-28T01:00:00'), 'Europe/Berlin', true); // CEST, from UTC
assertEquals('CEST, from UTC','CEST', dt.tzAbbr);

dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-14T01:59:59'), 'America/Chicago'); // CST, from local time
assertEquals('CST, from local time','CST', dt.tzAbbr);
dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-14T03:00:00'), 'America/Chicago'); // CDT, from local time
assertEquals('CDT, from local time','CDT', dt.tzAbbr);

dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-14T07:59:59'), 'America/Chicago', true); // CST, from UTC
assertEquals('CST, from UTC','CST', dt.tzAbbr);
dt = timezoneJS.timezone.getTzInfo(parseISO('2010-03-14T08:00:00'), 'America/Chicago', true); // CDT, from UTC
assertEquals('CDT, from UTC','CDT', dt.tzAbbr);
}

</script>


Expand Down

0 comments on commit 11c416d

Please sign in to comment.