Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ function tzset (tz) {
debug('set the current timezone to:', usedTz);
if (!rtn.tzname[1] && rtn.timezone === 0) {
debug('got bad zoneinfo object:', rtn);
if (tz !== exports.currentTimezone) {
// restore original timezone in case of error
tzset(exports.currentTimezone);
}
var err = new Error("Unknown Timezone: '" + usedTz + "'");
for (var i in rtn) {
err[i] = rtn[i];
Expand Down
7 changes: 7 additions & 0 deletions test/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ describe('Date', function () {
initial.should.equal(process.env.TZ)
})

it('should clean up after an error', function () {
var initial = process.env.TZ
, d = new time.Date
d.setTimezone.bind(d, 'Any/Wrong/TZ').should.throw(/^Unknown Timezone/)
initial.should.equal(process.env.TZ)
})

it('should change the "timezone offset"', function () {
var d = new time.Date
, offset = d.getTimezoneOffset()
Expand Down