Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d4ac254

Browse files
brettporterIgorMinar
authored andcommitted
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 #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 #5017 Closes #6730
1 parent e84da22 commit d4ac254

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
@@ -52,16 +52,19 @@ describe('ngMock', function() {
5252

5353

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

59-
//0 in +0h
60-
var t1 = new angular.mock.TzDate(0, 0);
62+
//0:00 in +0h
63+
var t1 = new angular.mock.TzDate(0, jan2);
6164
expect(t1.getHours()).toBe(0);
6265

63-
//0 in +3h
64-
var t2 = new angular.mock.TzDate(3, 0);
66+
//0:00 in +3h
67+
var t2 = new angular.mock.TzDate(3, jan2);
6568
expect(t2.getHours()).toMatch(21);
6669
});
6770

0 commit comments

Comments
 (0)