@@ -82,40 +82,40 @@ describe('Normalized time duration', () => {
82
82
} ) ;
83
83
} ) ;
84
84
85
- describe ( 'normalize ()' , ( ) => {
85
+ describe ( 'fromComponents ()' , ( ) => {
86
86
it ( 'basic' , ( ) => {
87
- check ( TimeDuration . normalize ( 1 , 1 , 1 , 1 , 1 , 1 ) , 3661 , 1001001 ) ;
88
- check ( TimeDuration . normalize ( - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ) , - 3661 , - 1001001 ) ;
87
+ check ( TimeDuration . fromComponents ( 1 , 1 , 1 , 1 , 1 , 1 ) , 3661 , 1001001 ) ;
88
+ check ( TimeDuration . fromComponents ( - 1 , - 1 , - 1 , - 1 , - 1 , - 1 ) , - 3661 , - 1001001 ) ;
89
89
} ) ;
90
90
91
91
it ( 'overflow from one unit to another' , ( ) => {
92
- check ( TimeDuration . normalize ( 1 , 61 , 61 , 998 , 1000 , 1000 ) , 7321 , 999001000 ) ;
93
- check ( TimeDuration . normalize ( - 1 , - 61 , - 61 , - 998 , - 1000 , - 1000 ) , - 7321 , - 999001000 ) ;
92
+ check ( TimeDuration . fromComponents ( 1 , 61 , 61 , 998 , 1000 , 1000 ) , 7321 , 999001000 ) ;
93
+ check ( TimeDuration . fromComponents ( - 1 , - 61 , - 61 , - 998 , - 1000 , - 1000 ) , - 7321 , - 999001000 ) ;
94
94
} ) ;
95
95
96
96
it ( 'overflow from subseconds to seconds' , ( ) => {
97
- check ( TimeDuration . normalize ( 0 , 0 , 1 , 1000 , 0 , 0 ) , 2 , 0 ) ;
98
- check ( TimeDuration . normalize ( 0 , 0 , - 1 , - 1000 , 0 , 0 ) , - 2 , 0 ) ;
97
+ check ( TimeDuration . fromComponents ( 0 , 0 , 1 , 1000 , 0 , 0 ) , 2 , 0 ) ;
98
+ check ( TimeDuration . fromComponents ( 0 , 0 , - 1 , - 1000 , 0 , 0 ) , - 2 , 0 ) ;
99
99
} ) ;
100
100
101
101
it ( 'multiple overflows from subseconds to seconds' , ( ) => {
102
- check ( TimeDuration . normalize ( 0 , 0 , 0 , 1234567890 , 1234567890 , 1234567890 ) , 1235803 , 692457890 ) ;
103
- check ( TimeDuration . normalize ( 0 , 0 , 0 , - 1234567890 , - 1234567890 , - 1234567890 ) , - 1235803 , - 692457890 ) ;
102
+ check ( TimeDuration . fromComponents ( 0 , 0 , 0 , 1234567890 , 1234567890 , 1234567890 ) , 1235803 , 692457890 ) ;
103
+ check ( TimeDuration . fromComponents ( 0 , 0 , 0 , - 1234567890 , - 1234567890 , - 1234567890 ) , - 1235803 , - 692457890 ) ;
104
104
} ) ;
105
105
106
106
it ( 'fails on overflow' , ( ) => {
107
- throws ( ( ) => TimeDuration . normalize ( 2501999792984 , 0 , 0 , 0 , 0 , 0 ) , RangeError ) ;
108
- throws ( ( ) => TimeDuration . normalize ( - 2501999792984 , 0 , 0 , 0 , 0 , 0 ) , RangeError ) ;
109
- throws ( ( ) => TimeDuration . normalize ( 0 , 150119987579017 , 0 , 0 , 0 , 0 ) , RangeError ) ;
110
- throws ( ( ) => TimeDuration . normalize ( 0 , - 150119987579017 , 0 , 0 , 0 , 0 ) , RangeError ) ;
111
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , 2 ** 53 , 0 , 0 , 0 ) , RangeError ) ;
112
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , - ( 2 ** 53 ) , 0 , 0 , 0 ) , RangeError ) ;
113
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , Number . MAX_SAFE_INTEGER , 1000 , 0 , 0 ) , RangeError ) ;
114
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , - Number . MAX_SAFE_INTEGER , - 1000 , 0 , 0 ) , RangeError ) ;
115
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , Number . MAX_SAFE_INTEGER , 0 , 1000000 , 0 ) , RangeError ) ;
116
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , - Number . MAX_SAFE_INTEGER , 0 , - 1000000 , 0 ) , RangeError ) ;
117
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , Number . MAX_SAFE_INTEGER , 0 , 0 , 1000000000 ) , RangeError ) ;
118
- throws ( ( ) => TimeDuration . normalize ( 0 , 0 , - Number . MAX_SAFE_INTEGER , 0 , 0 , - 1000000000 ) , RangeError ) ;
107
+ throws ( ( ) => TimeDuration . fromComponents ( 2501999792984 , 0 , 0 , 0 , 0 , 0 ) , RangeError ) ;
108
+ throws ( ( ) => TimeDuration . fromComponents ( - 2501999792984 , 0 , 0 , 0 , 0 , 0 ) , RangeError ) ;
109
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 150119987579017 , 0 , 0 , 0 , 0 ) , RangeError ) ;
110
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , - 150119987579017 , 0 , 0 , 0 , 0 ) , RangeError ) ;
111
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , 2 ** 53 , 0 , 0 , 0 ) , RangeError ) ;
112
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , - ( 2 ** 53 ) , 0 , 0 , 0 ) , RangeError ) ;
113
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , Number . MAX_SAFE_INTEGER , 1000 , 0 , 0 ) , RangeError ) ;
114
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , - Number . MAX_SAFE_INTEGER , - 1000 , 0 , 0 ) , RangeError ) ;
115
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , Number . MAX_SAFE_INTEGER , 0 , 1000000 , 0 ) , RangeError ) ;
116
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , - Number . MAX_SAFE_INTEGER , 0 , - 1000000 , 0 ) , RangeError ) ;
117
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , Number . MAX_SAFE_INTEGER , 0 , 0 , 1000000000 ) , RangeError ) ;
118
+ throws ( ( ) => TimeDuration . fromComponents ( 0 , 0 , - Number . MAX_SAFE_INTEGER , 0 , 0 , - 1000000000 ) , RangeError ) ;
119
119
} ) ;
120
120
} ) ;
121
121
@@ -343,7 +343,7 @@ describe('Normalized time duration', () => {
343
343
} ) ;
344
344
345
345
it ( 'quotient larger than seconds' , ( ) => {
346
- const d = TimeDuration . normalize ( 25 + 5 * 24 , 0 , 86401 , 333 , 666 , 999 ) ;
346
+ const d = TimeDuration . fromComponents ( 25 + 5 * 24 , 0 , 86401 , 333 , 666 , 999 ) ;
347
347
const { quotient, remainder } = d . divmod ( 86400e9 ) ;
348
348
equal ( quotient , 7 ) ;
349
349
check ( remainder , 3601 , 333666999 ) ;
@@ -401,7 +401,7 @@ describe('Normalized time duration', () => {
401
401
} ) ;
402
402
403
403
it ( 'quotient larger than seconds' , ( ) => {
404
- const d = TimeDuration . normalize ( 25 + 5 * 24 , 0 , 86401 , 333 , 666 , 999 ) ;
404
+ const d = TimeDuration . fromComponents ( 25 + 5 * 24 , 0 , 86401 , 333 , 666 , 999 ) ;
405
405
checkFloat ( d . fdiv ( 86400e9 ) , 7.041682102627303 ) ;
406
406
} ) ;
407
407
0 commit comments