@@ -140,12 +140,16 @@ export function ToPositiveInteger(valueParam: unknown, property?: string): numbe
140
140
return value ;
141
141
}
142
142
143
- function ToIntegerNoFraction ( valueParam : unknown ) : number {
143
+ export function ToIntegerWithoutRounding ( valueParam : unknown ) : number {
144
144
const value = ToNumber ( valueParam ) ;
145
+ if ( NumberIsNaN ( value ) ) return 0 ;
146
+ if ( ! NumberIsFinite ( value ) ) {
147
+ throw new RangeError ( 'infinity is out of range' ) ;
148
+ }
145
149
if ( ! IsInteger ( value ) ) {
146
150
throw new RangeError ( `unsupported fractional value ${ value } ` ) ;
147
151
}
148
- return value ;
152
+ return ToInteger ( value ) ; // ℝ(value) in spec text; converts -0 to 0
149
153
}
150
154
151
155
const BUILTIN_CASTS = new Map < PrimitivePropertyNames , ( v : unknown ) => string | number > ( [
@@ -159,16 +163,16 @@ const BUILTIN_CASTS = new Map<PrimitivePropertyNames, (v: unknown) => string | n
159
163
[ 'millisecond' , ToIntegerThrowOnInfinity ] ,
160
164
[ 'microsecond' , ToIntegerThrowOnInfinity ] ,
161
165
[ '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 ] ,
172
176
[ 'era' , ToString ] ,
173
177
[ 'eraYear' , ToInteger ] ,
174
178
[ 'offset' , ToString ]
0 commit comments