@formatjs/ecma402-abstract 3.0.7 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/262.d.ts +55 -55
- package/262.js +327 -327
- package/CanonicalizeLocaleList.d.ts +3 -3
- package/CanonicalizeLocaleList.js +5 -5
- package/CanonicalizeTimeZoneName.d.ts +13 -13
- package/CanonicalizeTimeZoneName.js +81 -82
- package/CoerceOptionsToObject.d.ts +4 -4
- package/CoerceOptionsToObject.js +9 -9
- package/DefaultNumberOption.d.ts +6 -6
- package/DefaultNumberOption.js +15 -15
- package/GetNumberOption.d.ts +5 -9
- package/GetNumberOption.js +10 -10
- package/GetOption.d.ts +12 -8
- package/GetOption.js +28 -28
- package/GetOptionsObject.d.ts +4 -4
- package/GetOptionsObject.js +11 -11
- package/GetStringOrBooleanOption.d.ts +4 -10
- package/GetStringOrBooleanOption.js +28 -28
- package/IsSanctionedSimpleUnitIdentifier.d.ts +6 -6
- package/IsSanctionedSimpleUnitIdentifier.js +53 -53
- package/IsValidTimeZoneName.d.ts +15 -15
- package/IsValidTimeZoneName.js +65 -66
- package/IsWellFormedCurrencyCode.d.ts +2 -2
- package/IsWellFormedCurrencyCode.js +15 -15
- package/IsWellFormedUnitIdentifier.d.ts +3 -3
- package/IsWellFormedUnitIdentifier.js +21 -22
- package/NumberFormat/ApplyUnsignedRoundingMode.d.ts +2 -2
- package/NumberFormat/ApplyUnsignedRoundingMode.js +34 -31
- package/NumberFormat/CollapseNumberRange.d.ts +6 -6
- package/NumberFormat/CollapseNumberRange.js +47 -47
- package/NumberFormat/ComputeExponent.d.ts +8 -8
- package/NumberFormat/ComputeExponent.js +48 -58
- package/NumberFormat/ComputeExponentForMagnitude.d.ts +6 -6
- package/NumberFormat/ComputeExponentForMagnitude.js +64 -72
- package/NumberFormat/CurrencyDigits.d.ts +3 -3
- package/NumberFormat/CurrencyDigits.js +5 -8
- package/NumberFormat/FormatApproximately.d.ts +3 -3
- package/NumberFormat/FormatApproximately.js +10 -6
- package/NumberFormat/FormatNumeric.d.ts +2 -2
- package/NumberFormat/FormatNumeric.js +4 -3
- package/NumberFormat/FormatNumericRange.d.ts +6 -6
- package/NumberFormat/FormatNumericRange.js +7 -9
- package/NumberFormat/FormatNumericRangeToParts.d.ts +6 -6
- package/NumberFormat/FormatNumericRangeToParts.js +12 -14
- package/NumberFormat/FormatNumericToParts.d.ts +3 -3
- package/NumberFormat/FormatNumericToParts.js +12 -12
- package/NumberFormat/FormatNumericToString.d.ts +7 -7
- package/NumberFormat/FormatNumericToString.js +79 -81
- package/NumberFormat/GetUnsignedRoundingMode.d.ts +1 -1
- package/NumberFormat/GetUnsignedRoundingMode.js +25 -24
- package/NumberFormat/InitializeNumberFormat.d.ts +10 -10
- package/NumberFormat/InitializeNumberFormat.js +83 -64
- package/NumberFormat/PartitionNumberPattern.d.ts +4 -4
- package/NumberFormat/PartitionNumberPattern.js +112 -123
- package/NumberFormat/PartitionNumberRangePattern.d.ts +6 -6
- package/NumberFormat/PartitionNumberRangePattern.js +41 -38
- package/NumberFormat/SetNumberFormatDigitOptions.d.ts +3 -3
- package/NumberFormat/SetNumberFormatDigitOptions.js +185 -174
- package/NumberFormat/SetNumberFormatUnitOptions.d.ts +3 -3
- package/NumberFormat/SetNumberFormatUnitOptions.js +62 -48
- package/NumberFormat/ToRawFixed.d.ts +7 -7
- package/NumberFormat/ToRawFixed.js +103 -107
- package/NumberFormat/ToRawPrecision.d.ts +7 -7
- package/NumberFormat/ToRawPrecision.js +199 -202
- package/NumberFormat/decimal-cache.d.ts +10 -10
- package/NumberFormat/decimal-cache.js +13 -13
- package/NumberFormat/digit-mapping.generated.js +781 -66
- package/NumberFormat/format_to_parts.d.ts +19 -20
- package/NumberFormat/format_to_parts.js +446 -438
- package/PartitionPattern.d.ts +6 -6
- package/PartitionPattern.js +33 -33
- package/SupportedLocales.d.ts +6 -6
- package/SupportedLocales.js +17 -17
- package/ToIntlMathematicalValue.d.ts +5 -1
- package/ToIntlMathematicalValue.js +31 -25
- package/constants.d.ts +1 -1
- package/constants.js +4 -4
- package/data.d.ts +1 -1
- package/data.js +4 -11
- package/index.d.ts +47 -47
- package/index.js +45 -45
- package/package.json +5 -5
- package/regex.generated.js +1 -1
- package/types/core.d.ts +5 -5
- package/types/date-time.d.ts +123 -128
- package/types/date-time.js +6 -6
- package/types/displaynames.d.ts +55 -55
- package/types/displaynames.js +1 -1
- package/types/list.d.ts +11 -11
- package/types/list.js +1 -1
- package/types/number.d.ts +137 -137
- package/types/number.js +2 -1
- package/types/plural-rules.d.ts +19 -11
- package/types/plural-rules.js +2 -1
- package/types/relative-time.d.ts +26 -32
- package/types/relative-time.js +2 -1
- package/utils.d.ts +30 -15
- package/utils.js +62 -116
package/262.js
CHANGED
|
@@ -1,400 +1,400 @@
|
|
|
1
|
-
import { Decimal } from
|
|
2
|
-
import { ZERO } from
|
|
3
|
-
import { invariant } from
|
|
1
|
+
import { Decimal } from "decimal.js";
|
|
2
|
+
import { ZERO } from "./constants.js";
|
|
3
|
+
import { invariant } from "./utils.js";
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
* https://tc39.es/ecma262/#sec-tostring
|
|
6
|
+
*/
|
|
7
7
|
export function ToString(o) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
// Only symbol is irregular...
|
|
9
|
+
if (typeof o === "symbol") {
|
|
10
|
+
throw TypeError("Cannot convert a Symbol value to a string");
|
|
11
|
+
}
|
|
12
|
+
return String(o);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
* https://tc39.es/ecma262/#sec-tonumber
|
|
16
|
+
* @param val
|
|
17
|
+
*/
|
|
18
18
|
export function ToNumber(arg) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
if (typeof arg === "number") {
|
|
20
|
+
return new Decimal(arg);
|
|
21
|
+
}
|
|
22
|
+
// Support bigint values by converting to string first
|
|
23
|
+
// https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.select
|
|
24
|
+
if (typeof arg === "bigint") {
|
|
25
|
+
return new Decimal(arg.toString());
|
|
26
|
+
}
|
|
27
|
+
invariant(typeof arg !== "symbol", "Symbol is not supported", TypeError);
|
|
28
|
+
if (arg === undefined) {
|
|
29
|
+
return new Decimal(NaN);
|
|
30
|
+
}
|
|
31
|
+
if (arg === null || arg === 0) {
|
|
32
|
+
return ZERO;
|
|
33
|
+
}
|
|
34
|
+
if (arg === true) {
|
|
35
|
+
return new Decimal(1);
|
|
36
|
+
}
|
|
37
|
+
if (typeof arg === "string") {
|
|
38
|
+
try {
|
|
39
|
+
return new Decimal(arg);
|
|
40
|
+
} catch {
|
|
41
|
+
return new Decimal(NaN);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
invariant(typeof arg === "object", "object expected", TypeError);
|
|
45
|
+
let primValue = ToPrimitive(arg, "number");
|
|
46
|
+
invariant(typeof primValue !== "object", "object expected", TypeError);
|
|
47
|
+
return ToNumber(primValue);
|
|
44
48
|
}
|
|
45
49
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
* https://tc39.es/ecma262/#sec-tointeger
|
|
51
|
+
* @param n
|
|
52
|
+
*/
|
|
49
53
|
function ToInteger(n) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
const number = ToNumber(n);
|
|
55
|
+
if (number.isNaN() || number.isZero()) {
|
|
56
|
+
return ZERO;
|
|
57
|
+
}
|
|
58
|
+
if (number.isFinite()) {
|
|
59
|
+
return number;
|
|
60
|
+
}
|
|
61
|
+
let integer = number.abs().floor();
|
|
62
|
+
if (number.isNegative()) {
|
|
63
|
+
integer = integer.negated();
|
|
64
|
+
}
|
|
65
|
+
return integer;
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
* https://tc39.es/ecma262/#sec-timeclip
|
|
69
|
+
* @param time
|
|
70
|
+
*/
|
|
67
71
|
export function TimeClip(time) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
if (!time.isFinite()) {
|
|
73
|
+
return new Decimal(NaN);
|
|
74
|
+
}
|
|
75
|
+
if (time.abs().greaterThan(8.64 * 0x38d7ea4c68000)) {
|
|
76
|
+
return new Decimal(NaN);
|
|
77
|
+
}
|
|
78
|
+
return ToInteger(time);
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
* https://tc39.es/ecma262/#sec-toobject
|
|
82
|
+
* @param arg
|
|
83
|
+
*/
|
|
80
84
|
export function ToObject(arg) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
if (arg == null) {
|
|
86
|
+
throw new TypeError("undefined/null cannot be converted to object");
|
|
87
|
+
}
|
|
88
|
+
return Object(arg);
|
|
85
89
|
}
|
|
86
90
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-samevalue
|
|
92
|
+
* @param x
|
|
93
|
+
* @param y
|
|
94
|
+
*/
|
|
91
95
|
export function SameValue(x, y) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
if (Object.is) {
|
|
97
|
+
return Object.is(x, y);
|
|
98
|
+
}
|
|
99
|
+
// SameValue algorithm
|
|
100
|
+
if (x === y) {
|
|
101
|
+
// Steps 1-5, 7-10
|
|
102
|
+
// Steps 6.b-6.e: +0 != -0
|
|
103
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
104
|
+
}
|
|
105
|
+
// Step 6.a: NaN == NaN
|
|
106
|
+
return x !== x && y !== y;
|
|
103
107
|
}
|
|
104
108
|
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-arraycreate
|
|
110
|
+
* @param len
|
|
111
|
+
*/
|
|
108
112
|
export function ArrayCreate(len) {
|
|
109
|
-
|
|
113
|
+
return Array.from({ length: len });
|
|
110
114
|
}
|
|
111
115
|
/**
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-hasownproperty
|
|
117
|
+
* @param o
|
|
118
|
+
* @param prop
|
|
119
|
+
*/
|
|
116
120
|
export function HasOwnProperty(o, prop) {
|
|
117
|
-
|
|
121
|
+
return Object.prototype.hasOwnProperty.call(o, prop);
|
|
118
122
|
}
|
|
119
123
|
/**
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
* https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
|
|
125
|
+
* @param x
|
|
126
|
+
*/
|
|
123
127
|
export function Type(x) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
128
|
+
if (x === null) {
|
|
129
|
+
return "Null";
|
|
130
|
+
}
|
|
131
|
+
if (typeof x === "undefined") {
|
|
132
|
+
return "Undefined";
|
|
133
|
+
}
|
|
134
|
+
if (typeof x === "function" || typeof x === "object") {
|
|
135
|
+
return "Object";
|
|
136
|
+
}
|
|
137
|
+
if (typeof x === "number") {
|
|
138
|
+
return "Number";
|
|
139
|
+
}
|
|
140
|
+
if (typeof x === "boolean") {
|
|
141
|
+
return "Boolean";
|
|
142
|
+
}
|
|
143
|
+
if (typeof x === "string") {
|
|
144
|
+
return "String";
|
|
145
|
+
}
|
|
146
|
+
if (typeof x === "symbol") {
|
|
147
|
+
return "Symbol";
|
|
148
|
+
}
|
|
149
|
+
if (typeof x === "bigint") {
|
|
150
|
+
return "BigInt";
|
|
151
|
+
}
|
|
148
152
|
}
|
|
149
|
-
|
|
153
|
+
const MS_PER_DAY = 864e5;
|
|
150
154
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
* https://www.ecma-international.org/ecma-262/11.0/index.html#eqn-modulo
|
|
156
|
+
* @param x
|
|
157
|
+
* @param y
|
|
158
|
+
* @return k of the same sign as y
|
|
159
|
+
*/
|
|
156
160
|
function mod(x, y) {
|
|
157
|
-
|
|
161
|
+
return x - Math.floor(x / y) * y;
|
|
158
162
|
}
|
|
159
163
|
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
* https://tc39.es/ecma262/#eqn-Day
|
|
165
|
+
* @param t
|
|
166
|
+
*/
|
|
163
167
|
export function Day(t) {
|
|
164
|
-
|
|
168
|
+
return Math.floor(t / MS_PER_DAY);
|
|
165
169
|
}
|
|
166
170
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
171
|
+
* https://tc39.es/ecma262/#sec-week-day
|
|
172
|
+
* @param t
|
|
173
|
+
*/
|
|
170
174
|
export function WeekDay(t) {
|
|
171
|
-
|
|
175
|
+
return mod(Day(t) + 4, 7);
|
|
172
176
|
}
|
|
173
177
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
* https://tc39.es/ecma262/#sec-year-number
|
|
179
|
+
* @param y
|
|
180
|
+
*/
|
|
177
181
|
export function DayFromYear(y) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
182
|
+
if (y < 100) {
|
|
183
|
+
// Date.UTC parses 0 - 99 as 1900 - 1999
|
|
184
|
+
const date = new Date(0);
|
|
185
|
+
date.setUTCFullYear(y, 0, 1);
|
|
186
|
+
date.setUTCHours(0, 0, 0, 0);
|
|
187
|
+
return date.getTime() / MS_PER_DAY;
|
|
188
|
+
}
|
|
189
|
+
return Date.UTC(y, 0) / MS_PER_DAY;
|
|
186
190
|
}
|
|
187
191
|
/**
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
192
|
+
* https://tc39.es/ecma262/#sec-year-number
|
|
193
|
+
* @param y
|
|
194
|
+
*/
|
|
191
195
|
export function TimeFromYear(y) {
|
|
192
|
-
|
|
196
|
+
return Date.UTC(y, 0);
|
|
193
197
|
}
|
|
194
198
|
/**
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
199
|
+
* https://tc39.es/ecma262/#sec-year-number
|
|
200
|
+
* @param t
|
|
201
|
+
*/
|
|
198
202
|
export function YearFromTime(t) {
|
|
199
|
-
|
|
203
|
+
return new Date(t).getUTCFullYear();
|
|
200
204
|
}
|
|
201
205
|
export function DaysInYear(y) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
if (y % 4 !== 0) {
|
|
207
|
+
return 365;
|
|
208
|
+
}
|
|
209
|
+
if (y % 100 !== 0) {
|
|
210
|
+
return 366;
|
|
211
|
+
}
|
|
212
|
+
if (y % 400 !== 0) {
|
|
213
|
+
return 365;
|
|
214
|
+
}
|
|
215
|
+
return 366;
|
|
212
216
|
}
|
|
213
217
|
export function DayWithinYear(t) {
|
|
214
|
-
|
|
218
|
+
return Day(t) - DayFromYear(YearFromTime(t));
|
|
215
219
|
}
|
|
216
220
|
export function InLeapYear(t) {
|
|
217
|
-
|
|
221
|
+
return DaysInYear(YearFromTime(t)) === 365 ? 0 : 1;
|
|
218
222
|
}
|
|
219
223
|
/**
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
* https://tc39.es/ecma262/#sec-month-number
|
|
225
|
+
* @param t
|
|
226
|
+
*/
|
|
223
227
|
export function MonthFromTime(t) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
228
|
+
const dwy = DayWithinYear(t);
|
|
229
|
+
const leap = InLeapYear(t);
|
|
230
|
+
if (dwy >= 0 && dwy < 31) {
|
|
231
|
+
return 0;
|
|
232
|
+
}
|
|
233
|
+
if (dwy < 59 + leap) {
|
|
234
|
+
return 1;
|
|
235
|
+
}
|
|
236
|
+
if (dwy < 90 + leap) {
|
|
237
|
+
return 2;
|
|
238
|
+
}
|
|
239
|
+
if (dwy < 120 + leap) {
|
|
240
|
+
return 3;
|
|
241
|
+
}
|
|
242
|
+
if (dwy < 151 + leap) {
|
|
243
|
+
return 4;
|
|
244
|
+
}
|
|
245
|
+
if (dwy < 181 + leap) {
|
|
246
|
+
return 5;
|
|
247
|
+
}
|
|
248
|
+
if (dwy < 212 + leap) {
|
|
249
|
+
return 6;
|
|
250
|
+
}
|
|
251
|
+
if (dwy < 243 + leap) {
|
|
252
|
+
return 7;
|
|
253
|
+
}
|
|
254
|
+
if (dwy < 273 + leap) {
|
|
255
|
+
return 8;
|
|
256
|
+
}
|
|
257
|
+
if (dwy < 304 + leap) {
|
|
258
|
+
return 9;
|
|
259
|
+
}
|
|
260
|
+
if (dwy < 334 + leap) {
|
|
261
|
+
return 10;
|
|
262
|
+
}
|
|
263
|
+
if (dwy < 365 + leap) {
|
|
264
|
+
return 11;
|
|
265
|
+
}
|
|
266
|
+
throw new Error("Invalid time");
|
|
263
267
|
}
|
|
264
268
|
export function DateFromTime(t) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
269
|
+
const dwy = DayWithinYear(t);
|
|
270
|
+
const mft = MonthFromTime(t);
|
|
271
|
+
const leap = InLeapYear(t);
|
|
272
|
+
if (mft === 0) {
|
|
273
|
+
return dwy + 1;
|
|
274
|
+
}
|
|
275
|
+
if (mft === 1) {
|
|
276
|
+
return dwy - 30;
|
|
277
|
+
}
|
|
278
|
+
if (mft === 2) {
|
|
279
|
+
return dwy - 58 - leap;
|
|
280
|
+
}
|
|
281
|
+
if (mft === 3) {
|
|
282
|
+
return dwy - 89 - leap;
|
|
283
|
+
}
|
|
284
|
+
if (mft === 4) {
|
|
285
|
+
return dwy - 119 - leap;
|
|
286
|
+
}
|
|
287
|
+
if (mft === 5) {
|
|
288
|
+
return dwy - 150 - leap;
|
|
289
|
+
}
|
|
290
|
+
if (mft === 6) {
|
|
291
|
+
return dwy - 180 - leap;
|
|
292
|
+
}
|
|
293
|
+
if (mft === 7) {
|
|
294
|
+
return dwy - 211 - leap;
|
|
295
|
+
}
|
|
296
|
+
if (mft === 8) {
|
|
297
|
+
return dwy - 242 - leap;
|
|
298
|
+
}
|
|
299
|
+
if (mft === 9) {
|
|
300
|
+
return dwy - 272 - leap;
|
|
301
|
+
}
|
|
302
|
+
if (mft === 10) {
|
|
303
|
+
return dwy - 303 - leap;
|
|
304
|
+
}
|
|
305
|
+
if (mft === 11) {
|
|
306
|
+
return dwy - 333 - leap;
|
|
307
|
+
}
|
|
308
|
+
throw new Error("Invalid time");
|
|
305
309
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
const HOURS_PER_DAY = 24;
|
|
311
|
+
const MINUTES_PER_HOUR = 60;
|
|
312
|
+
const SECONDS_PER_MINUTE = 60;
|
|
313
|
+
const MS_PER_SECOND = 1e3;
|
|
314
|
+
const MS_PER_MINUTE = MS_PER_SECOND * SECONDS_PER_MINUTE;
|
|
315
|
+
const MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
|
|
312
316
|
export function HourFromTime(t) {
|
|
313
|
-
|
|
317
|
+
return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
|
|
314
318
|
}
|
|
315
319
|
export function MinFromTime(t) {
|
|
316
|
-
|
|
320
|
+
return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
|
|
317
321
|
}
|
|
318
322
|
export function SecFromTime(t) {
|
|
319
|
-
|
|
323
|
+
return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
|
|
320
324
|
}
|
|
321
325
|
function IsCallable(fn) {
|
|
322
|
-
|
|
326
|
+
return typeof fn === "function";
|
|
323
327
|
}
|
|
324
328
|
/**
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
329
|
+
* The abstract operation OrdinaryHasInstance implements
|
|
330
|
+
* the default algorithm for determining if an object O
|
|
331
|
+
* inherits from the instance object inheritance path
|
|
332
|
+
* provided by constructor C.
|
|
333
|
+
* @param C class
|
|
334
|
+
* @param O object
|
|
335
|
+
* @param internalSlots internalSlots
|
|
336
|
+
*/
|
|
333
337
|
export function OrdinaryHasInstance(C, O, internalSlots) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
338
|
+
if (!IsCallable(C)) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
if (internalSlots?.boundTargetFunction) {
|
|
342
|
+
let BC = internalSlots?.boundTargetFunction;
|
|
343
|
+
return O instanceof BC;
|
|
344
|
+
}
|
|
345
|
+
if (typeof O !== "object") {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
let P = C.prototype;
|
|
349
|
+
if (typeof P !== "object") {
|
|
350
|
+
throw new TypeError("OrdinaryHasInstance called on an object with an invalid prototype property.");
|
|
351
|
+
}
|
|
352
|
+
return Object.prototype.isPrototypeOf.call(P, O);
|
|
349
353
|
}
|
|
350
354
|
export function msFromTime(t) {
|
|
351
|
-
|
|
355
|
+
return mod(t, MS_PER_SECOND);
|
|
352
356
|
}
|
|
353
357
|
function OrdinaryToPrimitive(O, hint) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
throw new TypeError('Cannot convert object to primitive value');
|
|
358
|
+
let methodNames;
|
|
359
|
+
if (hint === "string") {
|
|
360
|
+
methodNames = ["toString", "valueOf"];
|
|
361
|
+
} else {
|
|
362
|
+
methodNames = ["valueOf", "toString"];
|
|
363
|
+
}
|
|
364
|
+
for (const name of methodNames) {
|
|
365
|
+
const method = O[name];
|
|
366
|
+
if (IsCallable(method)) {
|
|
367
|
+
let result = method.call(O);
|
|
368
|
+
if (typeof result !== "object") {
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
throw new TypeError("Cannot convert object to primitive value");
|
|
372
374
|
}
|
|
373
375
|
export function ToPrimitive(input, preferredType) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
return input;
|
|
376
|
+
if (typeof input === "object" && input != null) {
|
|
377
|
+
const exoticToPrim = Symbol.toPrimitive in input ? input[Symbol.toPrimitive] : undefined;
|
|
378
|
+
let hint;
|
|
379
|
+
if (exoticToPrim !== undefined) {
|
|
380
|
+
if (preferredType === undefined) {
|
|
381
|
+
hint = "default";
|
|
382
|
+
} else if (preferredType === "string") {
|
|
383
|
+
hint = "string";
|
|
384
|
+
} else {
|
|
385
|
+
invariant(preferredType === "number", "preferredType must be \"string\" or \"number\"");
|
|
386
|
+
hint = "number";
|
|
387
|
+
}
|
|
388
|
+
let result = exoticToPrim.call(input, hint);
|
|
389
|
+
if (typeof result !== "object") {
|
|
390
|
+
return result;
|
|
391
|
+
}
|
|
392
|
+
throw new TypeError("Cannot convert exotic object to primitive.");
|
|
393
|
+
}
|
|
394
|
+
if (preferredType === undefined) {
|
|
395
|
+
preferredType = "number";
|
|
396
|
+
}
|
|
397
|
+
return OrdinaryToPrimitive(input, preferredType);
|
|
398
|
+
}
|
|
399
|
+
return input;
|
|
400
400
|
}
|