Skip to content

Commit 493df56

Browse files
committed
test(ngMock): workaround issue with negative timestamps
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
1 parent 751f058 commit 493df56

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/ngMock/angular-mocksSpec.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,19 @@ describe('ngMock', function() {
5555

5656

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

62-
//0 in +0h
63-
var t1 = new angular.mock.TzDate(0, 0);
65+
//0:00 in +0h
66+
var t1 = new angular.mock.TzDate(0, jan2);
6467
expect(t1.getHours()).toBe(0);
6568

66-
//0 in +3h
67-
var t2 = new angular.mock.TzDate(3, 0);
69+
//0:00 in +3h
70+
var t2 = new angular.mock.TzDate(3, jan2);
6871
expect(t2.getHours()).toMatch(21);
6972
});
7073

0 commit comments

Comments
 (0)