@@ -140,12 +140,16 @@ export function ToPositiveInteger(valueParam: unknown, property?: string): numbe
140140 return value ;
141141}
142142
143- function ToIntegerNoFraction ( valueParam : unknown ) : number {
143+ export function ToIntegerWithoutRounding ( valueParam : unknown ) : number {
144144 const value = ToNumber ( valueParam ) ;
145+ if ( NumberIsNaN ( value ) ) return 0 ;
146+ if ( ! NumberIsFinite ( value ) ) {
147+ throw new RangeError ( 'infinity is out of range' ) ;
148+ }
145149 if ( ! IsInteger ( value ) ) {
146150 throw new RangeError ( `unsupported fractional value ${ value } ` ) ;
147151 }
148- return value ;
152+ return ToInteger ( value ) ; // ℝ(value) in spec text; converts -0 to 0
149153}
150154
151155const BUILTIN_CASTS = new Map < PrimitivePropertyNames , ( v : unknown ) => string | number > ( [
@@ -159,16 +163,16 @@ const BUILTIN_CASTS = new Map<PrimitivePropertyNames, (v: unknown) => string | n
159163 [ 'millisecond' , ToIntegerThrowOnInfinity ] ,
160164 [ 'microsecond' , ToIntegerThrowOnInfinity ] ,
161165 [ 'nanosecond' , ToIntegerThrowOnInfinity ] ,
162- [ 'years' , ToIntegerNoFraction ] ,
163- [ 'months' , ToIntegerNoFraction ] ,
164- [ 'weeks' , ToIntegerNoFraction ] ,
165- [ 'days' , ToIntegerNoFraction ] ,
166- [ 'hours' , ToIntegerNoFraction ] ,
167- [ 'minutes' , ToIntegerNoFraction ] ,
168- [ 'seconds' , ToIntegerNoFraction ] ,
169- [ 'milliseconds' , ToIntegerNoFraction ] ,
170- [ 'microseconds' , ToIntegerNoFraction ] ,
171- [ 'nanoseconds' , ToIntegerNoFraction ] ,
166+ [ 'years' , ToIntegerWithoutRounding ] ,
167+ [ 'months' , ToIntegerWithoutRounding ] ,
168+ [ 'weeks' , ToIntegerWithoutRounding ] ,
169+ [ 'days' , ToIntegerWithoutRounding ] ,
170+ [ 'hours' , ToIntegerWithoutRounding ] ,
171+ [ 'minutes' , ToIntegerWithoutRounding ] ,
172+ [ 'seconds' , ToIntegerWithoutRounding ] ,
173+ [ 'milliseconds' , ToIntegerWithoutRounding ] ,
174+ [ 'microseconds' , ToIntegerWithoutRounding ] ,
175+ [ 'nanoseconds' , ToIntegerWithoutRounding ] ,
172176 [ 'era' , ToString ] ,
173177 [ 'eraYear' , ToInteger ] ,
174178 [ 'offset' , ToString ]
0 commit comments