Skip to content

Commit

Permalink
turns out there was a bug :( add unit test and fix said bug
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed Jun 29, 2012
1 parent c509d30 commit 0ab9692
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 2 additions & 4 deletions spec/date.spec.js
Expand Up @@ -213,10 +213,8 @@ describe('timezoneJS.Date', function () {
console.log('Took ' + (Date.now() - start) + 'ms to convert 5000 dates');
});

it('should create a date quickly', function () {
var start = Date.now()
new timezoneJS.Date(1234, 'Asia/Bangkok');
console.log('Took ' + (Date.now() - start) + 'ms to create a date');
it('should output 1955-10-30T00:00:00 America/New_York as EDT', function () {
expect(new timezoneJS.Date(1955, 9, 30, 0, 'America/New_York').getTimezoneOffset()).toEqual(240);
});


Expand Down
7 changes: 3 additions & 4 deletions src/date.js
Expand Up @@ -461,7 +461,7 @@
var dat = 31;
if (z[4]) {
mon = SHORT_MONTHS[z[4].substr(0, 3)];
dat = parseInt(z[5], 10);
dat = parseInt(z[5], 10) || 1;
}
var string = z[6] ? z[6] : '23:59:59';
t = parseTimeString(string);
Expand Down Expand Up @@ -490,8 +490,7 @@
for (var i = 0; i < zoneList.length; i++) {
var z = zoneList[i];
if (!z[3]) { break; }
var d = Date.UTC(z[3]);
if (dt.getTime() < d) { break; }
if (dt.getTime() < z[3]) { break; }
}
if (i === zoneList.length) { throw new Error('No Zone found for "' + tz + '" on ' + dt); }
return zoneList[i];
Expand Down Expand Up @@ -829,7 +828,7 @@
}
if (arr.length < 3) break;
//Process zone right here and replace 3rd element with the processed array.
arr.splice(3, arr.length, processZone(arr));
arr.splice(3, arr.length, Date.UTC.apply(null, processZone(arr)));
arr[0] = [arr[0], parseTimeString(arr[0])];
_this.zones[zone].push(arr);
break;
Expand Down

0 comments on commit 0ab9692

Please sign in to comment.