Skip to content

Commit

Permalink
test(ngMock): workaround issue with negative timestamps
Browse files Browse the repository at this point in the history
In some specific timezones and operating systems, it seems that
getTimezoneOffset() can return an incorrect value for negative timestamps, as
described in angular#5017. While this isn't something easily fixed in the mock code,
the tests can avoid that particular timeframe by using a positive timestamp.

Closes angular#5017
  • Loading branch information
brettporter committed Mar 18, 2014
1 parent f8f97f8 commit 7441649
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ describe('ngMock', function() {


it('should fake getHours method', function() {
//0 in -3h
var t0 = new angular.mock.TzDate(-3, 0);
// avoid going negative due to #5017, so use Jan 2, 1970 00:00 UTC
var jan2 = 24 * 60 * 60 * 1000;

//0:00 in -3h
var t0 = new angular.mock.TzDate(-3, jan2);
expect(t0.getHours()).toBe(3);

//0 in +0h
var t1 = new angular.mock.TzDate(0, 0);
//0:00 in +0h
var t1 = new angular.mock.TzDate(0, jan2);
expect(t1.getHours()).toBe(0);

//0 in +3h
var t2 = new angular.mock.TzDate(3, 0);
//0:00 in +3h
var t2 = new angular.mock.TzDate(3, jan2);
expect(t2.getHours()).toMatch(21);
});

Expand Down

0 comments on commit 7441649

Please # to comment.