Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(core): migrate numfmt (#7268)
白熱95c504607597
diff --git a/packages/core/package.json b/packages/core/package.jsonindex 56f894770a..65bd14166f 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -85,7 +85,6 @@"fast-diff": "1.3.0","kdbush": "^4.1.0","lodash-es": "^4.18.1",- "numfmt": "3.2.6","ot-json1": "^1.0.2","rbush": "^4.0.1"},diff --git a/packages/core/src/shared/__tests__/numfmt.spec.ts b/packages/core/src/shared/__tests__/numfmt.spec.tsindex 084370ca53..f9a3b9317f 100644--- a/packages/core/src/shared/__tests__/numfmt.spec.ts+++ b/packages/core/src/shared/__tests__/numfmt.spec.ts@@ -78,6 +78,92 @@ describe('numfmt compatibility regression tests', () => {});});+ describe('Excel-compatible decimal rounding', () => {+ it.each([+ [10.155, '0.00', '10.16'],+ [1.005, '0.00', '1.01'],+ [2.155, '0.00', '2.16'],+ [-10.155, '0.00', '-10.16'],+ [-1.005, '0.00', '-1.01'],+ [-2.155, '0.00', '-2.16'],+ [1.00499999999999, '0.00', '1.00'],+ [1.00500000000001, '0.00', '1.01'],+ [9.995, '0.00', '10.00'],+ [0.10155, '0.00%', '10.16%'],+ [10155, '0.00,', '10.16'],+ [-0.004, '0.00', '0.00'],+ [0.1 + 0.2, '0.000000000000000', '0.300000000000000'],+ [999999999999999, '0.00', '999999999999999.00'],+ [450000000000000.44, '0.00', '450000000000000.00'],+ ])('formats %s with %s as %s', (value, pattern, expected) => {+ expect(numfmt.format(pattern, value)).toBe(expected);+ });++ it.each([+ [2.155, '0.00E+00', '2.16E+00'],+ [-2.155, '0.00E+00', '-2.16E+00'],+ [9.995, '0.00E+00', '1.00E+01'],+ [-9.995, '0.00E+00', '-1.00E+01'],+ [1.0155e20, '0.00E+00', '1.02E+20'],+ [1.0155e-20, '0.00E+00', '1.02E-20'],+ [1e308, '0.00E+00', '1.00E+308'],+ [1e-308, '0.00E+00', '1.00E-308'],+ ])('formats scientific value %s', (value, pattern, expected) => {+ expect(numfmt.format(pattern, value)).toBe(expected);+ });++ it('rounds through the public decimal API', () => {+ expect(numfmt.round(10.155, 2)).toBe(10.16);+ expect(numfmt.round(1.005, 2)).toBe(1.01);+ expect(numfmt.round(-1.005, 2)).toBe(-1.01);+ expect(Object.is(numfmt.round(-0.004, 2), -0)).toBe(false);+ });++ it.each([+ [Number.MAX_SAFE_INTEGER, undefined, Number.MAX_SAFE_INTEGER],+ [Number.MIN_SAFE_INTEGER, undefined, Number.MIN_SAFE_INTEGER],+ [Number.MAX_VALUE, undefined, Number.MAX_VALUE],+ [1.5, Number.NaN, 2],+ [1.5, Number.POSITIVE_INFINITY, Number.NaN],+ [1.5, Number.NEGATIVE_INFINITY, 2],+ [1.15, 1.9, 1.2],+ [1.23456789, 1_000_000, 1.23456789],+ [Number.MAX_VALUE, -308, Number.MAX_VALUE],+ [1.23, -1_000_000, 0],+ ])('rounds public boundary %s at %s places', (value, places, expected) => {+ expect(numfmt.round(value, places)).toBe(expected);+ });++ it('preserves public round passthrough values', () => {+ expect(numfmt.round('text')).toBe('text');+ expect(numfmt.round(Number.NaN, 2)).toBeNaN();+ expect(numfmt.round(Number.POSITIVE_INFINITY, 2)).toBe(Number.POSITIVE_INFINITY);+ expect(numfmt.round(Number.NEGATIVE_INFINITY, 2)).toBe(Number.NEGATIVE_INFINITY);+ expect(Object.is(numfmt.round(-0), -0)).toBe(false);+ });++ it.each([+ [1.234565e11, '1.23457E+11'],+ [-1.234565e11, '-1.23457E+11'],+ [9.999995e11, '1E+12'],+ [-9.999995e11, '-1E+12'],+ ])('formats General decimal tie %s', (value, expected) => {+ expect(numfmt.format('General', value)).toBe(expected);+ });++ it('preserves legacy rounding for vulgar fractions', () => {+ expect(numfmt.format('# ?/11', 0.6818181818181818)).toBe(' 7/11');+ });++ it('preserves legacy rounding for BigInt scientific fallback', () => {+ expect(numfmt.format('0.00E+00', 1005000n)).toBe('1.00E+06');+ });++ it('preserves legacy rounding for BigInt General fallback', () => {+ expect(numfmt.format('General', 999999500000000n)).toBe('10E+14');+ });+ });+describe('numfmt.formatColor', () => {it('should return color for colored patterns', () => {expect(numfmt.formatColor('[red]0', 42)).toBe('red');diff --git a/packages/core/src/shared/numfmt/LICENSE b/packages/core/src/shared/numfmt/LICENSEnew file mode 100644index 0000000000..464216f936--- /dev/null+++ b/packages/core/src/shared/numfmt/LICENSE@@ -0,0 +1,22 @@+numfmt 3.2.6+Source: https://github.com/borgar/numfmt/tree/c2cfdfa01bb1f24df51e985825671eb480daed4c++Copyright (c) 2020, Borgar Þorsteinsson <[email protected]>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.diff --git a/packages/core/src/shared/numfmt/__tests__/api-compatibility.spec.ts b/packages/core/src/shared/numfmt/__tests__/api-compatibility.spec.tsnew file mode 100644index 0000000000..d7c7d147ee--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/api-compatibility.spec.ts@@ -0,0 +1,59 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { expect, expectTypeOf, it } from 'vitest';+import * as numfmt from '../api';++it('preserves the numfmt 3.2.6 type exports', () => {+ expectTypeOf<numfmt.FormatDateInfo['clockType']>().toEqualTypeOf<12 | 24>();+ expectTypeOf<numfmt.FormatInfo['type']>().toMatchTypeOf<string>();+ expectTypeOf<numfmt.FormatToken['raw']>().toEqualTypeOf<string>();+ expectTypeOf<numfmt.LocaleData['decimal']>().toEqualTypeOf<string>();+ expectTypeOf<numfmt.LocaleToken['lang']>().toEqualTypeOf<string>();+ expectTypeOf<numfmt.ParseData['v']>().toEqualTypeOf<number | boolean>();+});++it('preserves the numfmt 3.2.6 runtime exports', () => {+ expect(Object.keys(numfmt).sort()).toEqual([+ 'addLocale',+ 'dateFromSerial',+ 'dateToSerial',+ 'dec2frac',+ 'format',+ 'formatColor',+ 'getFormatDateInfo',+ 'getFormatInfo',+ 'getLocale',+ 'isDateFormat',+ 'isPercentFormat',+ 'isTextFormat',+ 'isValidFormat',+ 'parseBool',+ 'parseDate',+ 'parseLocale',+ 'parseNumber',+ 'parseTime',+ 'parseValue',+ 'round',+ 'tokenTypes',+ 'tokenize',+ ]);+});diff --git a/packages/core/src/shared/numfmt/__tests__/bigint.spec.ts b/packages/core/src/shared/numfmt/__tests__/bigint.spec.tsnew file mode 100644index 0000000000..2f76aea2b3--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/bigint.spec.ts@@ -0,0 +1,49 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++numfmtTest('bigint', (t) => {+ t.format('0', Number.MAX_SAFE_INTEGER, String(Number.MAX_SAFE_INTEGER));+ t.format('0', 10n, '10');++ t.format('General', 10n, '10');+ t.format('General', 9007199254740991n, '9.0072E+15');++ t.format('0.0', 9007199254740991n, '9007199254740990.0');++ t.format('#,##0.0', 9007199254740991n, '9,007,199,254,740,990.0');+ t.format('#,##0.0', 9007199254750000n, '######');+ t.format('#,##0.0', -9007199254750000n, '######');++ t.format('#0-000-00', 9007199254750000n, '######');+ t.format('0%', 9007199254750000n, '######');++ t.format('#0-000-00', 9007199254750000n, '9007199254750000', { bigintErrorNumber: true });+ t.format('0%', 9007199254750000n, '9007199254750000', { bigintErrorNumber: true });++ // preferably we should support bigint throughout:+ // t.format('#0-000-00', 9007199254750000n, '90071992547-500-00');+ // t.format('0%', 9007199254750000n, '900719925475000000%');++ t.format('0.000E+00', 999990000, '1.000E+09');+ t.format('0.000E+00', 999990000n, '1.000E+09');+});diff --git a/packages/core/src/shared/numfmt/__tests__/color.spec.ts b/packages/core/src/shared/numfmt/__tests__/color.spec.tsnew file mode 100644index 0000000000..ab74ba5040--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/color.spec.ts@@ -0,0 +1,64 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++numfmtTest('formatColor', (t) => {+ // color works the same across number sections, but not text+ t.formatColor('0', 123, null);+ t.formatColor('0', 0, null);+ t.formatColor('0', -123, null);+ t.formatColor('0', 'foo', null);+ t.formatColor('[blue]0', 123, 'blue');+ t.formatColor('[blue]0', 0, 'blue');+ t.formatColor('[blue]0', -123, 'blue');+ t.formatColor('[blue]0', 'foo', null);+ // can define separate colors per section+ t.formatColor('[blue]0;[green]-0;[magenta]0;[cyan]@', 1, 'blue');+ t.formatColor('[blue]0;[green]-0;[magenta]0;[cyan]@', -1, 'green');+ t.formatColor('[blue]0;[green]-0;[magenta]0;[cyan]@', 0, 'magenta');+ t.formatColor('[blue]0;[green]-0;[magenta]0;[cyan]@', 'foo', 'cyan');+ // color is case insensitive+ t.formatColor('[red]0', 0, 'red');+ t.formatColor('[Red]0', 0, 'red');+ t.formatColor('[RED]0', 0, 'red');+ // all known primaries work+ t.formatColor('[black]0', 0, 'black');+ t.formatColor('[blue]0', 0, 'blue');+ t.formatColor('[cyan]0', 0, 'cyan');+ t.formatColor('[green]0', 0, 'green');+ t.formatColor('[magenta]0', 0, 'magenta');+ t.formatColor('[red]0', 0, 'red');+ t.formatColor('[white]0', 0, 'white');+ t.formatColor('[yellow]0', 0, 'yellow');+ // 1-based index color resolutions+ t.formatColor('[color 0]0', 0, null);+ t.formatColor('[color 1]0', 0, '#000000');+ t.formatColor('[color 2]0', 0, '#FFFFFF');+ t.formatColor('[color3]0', 0, '#FF0000');+ // numbers are returned when indexColors is off+ t.formatColor('[color 0]0', 0, null, { indexColors: false });+ t.formatColor('[color 1]0', 0, 1, { indexColors: false });+ t.formatColor('[color 2]0', 0, 2, { indexColors: false });+ t.formatColor('[color3]0', 0, 3, { indexColors: false });+ // keywords are still returned when indexColors is off+ t.formatColor('[yellow]0', 0, 'yellow', { indexColors: false });+});diff --git a/packages/core/src/shared/numfmt/__tests__/comma.spec.ts b/packages/core/src/shared/numfmt/__tests__/comma.spec.tsnew file mode 100644index 0000000000..3e5a3f041a--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/comma.spec.ts@@ -0,0 +1,69 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++numfmtTest('Excel-compatible decimal rounding after comma scaling', (t) => {+ t.format('0.00,', 10155, '10.16');+});++numfmtTest('Correct handling of the comma operator', (t) => {+ t.format('0,', 1234567.89, '1235');+ t.format('0,,', 1234567.89, '1');+ t.format('0,,,', 1234567.89, '0');+ t.format('0,0', 1234567.89, '1,234,568');+ t.format('0,00', 1234567.89, '1,234,568');+ t.format('0,000', 1234567.89, '1,234,568');+ t.format('0,0,0', 1234567.89, '1,234,568');+ t.format('0,,0', 1234567.89, '1,234,568');+ t.format('0,,,0', 1234567.89, '1,234,568');+ t.format('0,x', 1234567.89, '1235x');+ t.format('0,x,', 1234567.89, '1235x,');+ t.format('0x,', 1234567.89, '1234568x,');+ t.format('0,,x', 1234567.89, '1x');+ t.format('0,x0', 1234567.89, '123456x8');+ t.format('0 , 0', 1234567.89, '123456 , 8');+ t.format('0, ,0', 1234567.89, '123456 ,8');+ t.format('0.,', 1234567.89, '1235.');+ t.format('0.0,', 1234567.89, '1234.6');+ t.format('0.0,0', 1234567.89, '1234567.89');+ t.format('0,0 0/0', 1234567.89, '1,234,567 8/9');+ t.format('0,0,,0', 1234567.89, '1,234,568');+ t.format('0.0,0,', 1234567.89, '1234.57');+ t.format('0.0 , 0 ,', 1234567.89, '1234567.8 , 9 ,');+ t.format('0 ,', 1234567.89, '1234568 ,');+ t.format('0x,', 1234567.89, '1234568x,');+ t.format('0 ,', 1234567.89, '1234568 ,');+ t.format('0 ,,', 1234567.89, '1234568 ,');+ t.format('0x,', 1234567.89, '1234568x,');+ t.format('x,0', 1234567.89, 'x,1234568');++ // Still unsolved by the formatter: digit interplay with 0#?+ t.format('01,', 1234567.89, '12351');+ t.format('09,', 1234567.89, '12359');+ // t.format('01,0', 1234567.89, '1,234,5618');+ // t.format('09,0', 1234567.89, '1,234,5698');+ // t.format('0, 9', 1234567.89, '1234568 9');++ t.formatInvalid('0,0/0');+ t.formatInvalid('0/0,0');+ // t.formatInvalid('0 0/0,'); "1234 4/7" gets emitted, same as Sheets+});diff --git a/packages/core/src/shared/numfmt/__tests__/conditionals.spec.ts b/packages/core/src/shared/numfmt/__tests__/conditionals.spec.tsnew file mode 100644index 0000000000..e7fa901810--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/conditionals.spec.ts@@ -0,0 +1,597 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++numfmtTest('conditional parts', (t) => {+ t.format('[>=100]"A"0;[<=-100]"B"0;"C"0', 6.3, 'C6');+ t.format('[>=100]"A"0;[<=-100]"B"0;"C"0', -6.3, '-C6');+ t.format('[>=100]"A"0;[<=0]"B"0;"C"0', 6.3, 'C6');+ t.format('[>=100]"A"0;[<=0]"B"0;"C"0', -6.3, '-B6');+ t.format('[>=0]"A"0;[<=-100]"B"0;"C"0', 6.3, 'A6');+ t.format('[>=0]"A"0;[<=-100]"B"0;"C"0', -6.3, '-C6');+ t.format('[>=0]"A"0;[<=0]"B"0;"C"0', 6.3, 'A6');+ t.format('[>=0]"A"0;[<=0]"B"0;"C"0', -6.3, '-B6');+ t.format('[>=0]"A"0;[<=-100]"B"0', 6.3, 'A6');+ t.format('[>=100]"A"0;[<=0]"B"0', -6.3, '-B6');+ t.format('[<=-100]"B"0;"C"0', 6.3, 'C6');+ t.format('[<=-100]"B"0;"C"0', -6.3, 'C6');+ t.format('[<=0]"B"0', 6.3, '6.3');+ t.format('[<=0]"B"0', -6.3, '-B6');+ t.format('[=6.3]"B"0', 6.3, 'B6');+ t.format('[=6.3]"B"0', -6.3, '-6.3');+ t.format('[<>6]"B"0', 6.3, 'B6');+ t.format('[<>6]"B"0', -6.3, '-B6');+ t.format('[=6.3]"B"0', 6.3, 'B6');+ t.format('[=6.3]"B"0', -6.3, '-6.3');+ t.format('[>6]"A"0;[<-6]"B"0', 6.3, 'A6');+ t.format('[>6]"A"0;[<-6]"B"0', -6.3, 'B6');+ t.format('[>=100]"A"0;[<=-100]"B"0;"C"0;"D"@', 6.3, 'C6');+ t.format('[>=100]"A"0;[<=-100]"B"0;"C"0;"D"@', -6.3, '-C6');+ t.format('[>=100]"A"-0;[<=-100]"B"-0;"C"-0', 6.3, 'C-6');+ t.format('[>=100]"A"-0;[<=-100]"B"-0;"C"-0', -6.3, '-C-6');+ t.format('[>=100]"A"-#,##0;[<=0]"B"-#,##0;"C"-#,##0', 6.3, 'C-6');+ t.format('[>=100]"A"-#,##0;[<=0]"B"-#,##0;"C"-#,##0', -6.3, '-B-6');+ t.format('[>=0]"A"-0;[<=-100]"B"-0;"C"-0', 6.3, 'A-6');+ t.format('[>=0]"A"-0;[<=-100]"B"-0;"C"-0', -6.3, '-C-6');+ t.format('[>=0]"A"-0;[<=0]"B"-0;"C"-0', 6.3, 'A-6');+ t.format('[>=0]"A"-0;[<=0]"B"-0;"C"-0', -6.3, '-B-6');++ t.format('[>=100]"A"0;[<=-100]"B"0', 6.3, '######');+ t.format('[>=100]"A"0;[<=-100]"B"0', -6.3, '######');+ t.format('[>=0]"A"0;[<=-100]"B"0', -6.3, '######');+ t.format('[>=100]"A"0;[<=0]"B"0', 6.3, '######');+ t.formatInvalid('[>=100]"A"0;[<=-100]"B"0;"C"0;"D"0');+ t.formatInvalid('[>=100]"A"0;[<=-100]"B"0;"C"0;"D"0');+ t.formatInvalid('[<-25]0;[>25]0;0;"foo".#');+});++numfmtTest('conditional parts vs negative numbers', (t) => {+ t.format('[<>-6]\\A0', -5, '-A5');+ t.format('[<-4]\\A0', -5, 'A5');+ t.format('[<=-4]\\A0', -5, 'A5');+ t.format('[=-5]\\A0', -5, 'A5');+ t.format('[>-6]\\A0', -5, '-A5');+ t.format('[>=-6]\\A0', -5, '-A5');+ t.format('[<>-5]\\A0', -5, '5');+ t.format('[<-6]\\A0', -5, '5');+ t.format('[<=-6]\\A0', -5, '5');+ t.format('[=-6]\\A0', -5, '-5');+ t.format('[>2]\\A0', -5, '-5');+ t.format('[>=2]\\A0', -5, '-5');++ t.format('[<>-6]\\A0;\\B0', -5, '-A5');+ t.format('[<-4]\\A0;\\B0', -5, 'A5');+ t.format('[<=-4]\\A0;\\B0', -5, 'A5');+ t.format('[=-5]\\A0;\\B0', -5, 'A5');+ t.format('[>-6]\\A0;\\B0', -5, '-A5');+ t.format('[>=-6]\\A0;\\B0', -5, '-A5');+ t.format('[<>-5]\\A0;\\B0', -5, 'B5');+ t.format('[<-6]\\A0;\\B0', -5, 'B5');+ t.format('[<=-6]\\A0;\\B0', -5, 'B5');+ t.format('[=-6]\\A0;\\B0', -5, '-B5');+ t.format('[>2]\\A0;\\B0', -5, '-B5');+ t.format('[>=2]\\A0;\\B0', -5, '-B5');++ t.format('[<>-6]\\A0;[<>-6]\\B0;\\C0', -5, '-A5');+ t.format('[<>-6]\\A0;[<-4]\\B0;\\C0', -5, '-A5');+ t.format('[<>-6]\\A0;[<=-4]\\B0;\\C0', -5, '-A5');+ t.format('[<>-6]\\A0;[=-5]\\B0;\\C0', -5, '-A5');+ t.format('[<>-6]\\A0;[>-6]\\B0;\\C0', -5, '-A5');+ t.format('[<>-6]\\A0;[>=-6]\\B0;\\C0', -5, '-A5');+ t.format('[<-4]\\A0;[<>-6]\\B0;\\C0', -5, 'A5');+ t.format('[<-4]\\A0;[<-4]\\B0;\\C0', -5, 'A5');+ t.format('[<-4]\\A0;[<=-4]\\B0;\\C0', -5, 'A5');+ t.format('[<-4]\\A0;[=-5]\\B0;\\C0', -5, 'A5');+ t.format('[<-4]\\A0;[>-6]\\B0;\\C0', -5, 'A5');+ t.format('[<-4]\\A0;[>=-6]\\B0;\\C0', -5, 'A5');+ t.format('[<=-4]\\A0;[<>-6]\\B0;\\C0', -5, 'A5');+ t.format('[<=-4]\\A0;[<-4]\\B0;\\C0', -5, 'A5');+ t.format('[<=-4]\\A0;[<=-4]\\B0;\\C0', -5, 'A5');+ t.format('[<=-4]\\A0;[=-5]\\B0;\\C0', -5, 'A5');+ t.format('[<=-4]\\A0;[>-6]\\B0;\\C0', -5, 'A5');+ t.format('[<=-4]\\A0;[>=-6]\\B0;\\C0', -5, 'A5');+ t.format('[=-5]\\A0;[<>-6]\\B0;\\C0', -5, 'A5');+ t.format('[=-5]\\A0;[<-4]\\B0;\\C0', -5, 'A5');+ t.format('[=-5]\\A0;[<=-4]\\B0;\\C0', -5, 'A5');+ t.format('[=-5]\\A0;[=-5]\\B0;\\C0', -5, 'A5');+ t.format('[=-5]\\A0;[>-6]\\B0;\\C0', -5, 'A5');+ t.format('[=-5]\\A0;[>=-6]\\B0;\\C0', -5, 'A5');+ t.format('[>-6]\\A0;[<>-6]\\B0;\\C0', -5, '-A5');+ t.format('[>-6]\\A0;[<-4]\\B0;\\C0', -5, '-A5');+ t.format('[>-6]\\A0;[<=-4]\\B0;\\C0', -5, '-A5');+ t.format('[>-6]\\A0;[=-5]\\B0;\\C0', -5, '-A5');+ t.format('[>-6]\\A0;[>-6]\\B0;\\C0', -5, '-A5');+ t.format('[>-6]\\A0;[>=-6]\\B0;\\C0', -5, '-A5');+ t.format('[>=-6]\\A0;[<>-6]\\B0;\\C0', -5, '-A5');+ t.format('[>=-6]\\A0;[<-4]\\B0;\\C0', -5, '-A5');+ t.format('[>=-6]\\A0;[<=-4]\\B0;\\C0', -5, '-A5');+ t.format('[>=-6]\\A0;[=-5]\\B0;\\C0', -5, '-A5');+ t.format('[>=-6]\\A0;[>-6]\\B0;\\C0', -5, '-A5');+ t.format('[>=-6]\\A0;[>=-6]\\B0;\\C0', -5, '-A5');++ t.format('[<>-5]\\A0;[<>-6]\\B0;\\C0', -5, '-B5');+ t.format('[<>-5]\\A0;[<-4]\\B0;\\C0', -5, 'B5');+ t.format('[<>-5]\\A0;[<=-4]\\B0;\\C0', -5, 'B5');+ t.format('[<>-5]\\A0;[=-5]\\B0;\\C0', -5, 'B5');+ t.format('[<>-5]\\A0;[>-6]\\B0;\\C0', -5, '-B5');+ t.format('[<>-5]\\A0;[>=-6]\\B0;\\C0', -5, '-B5');+ t.format('[<-6]\\A0;[<>-6]\\B0;\\C0', -5, '-B5');+ t.format('[<-6]\\A0;[<-4]\\B0;\\C0', -5, 'B5');+ t.format('[<-6]\\A0;[<=-4]\\B0;\\C0', -5, 'B5');+ t.format('[<-6]\\A0;[=-5]\\B0;\\C0', -5, 'B5');+ t.format('[<-6]\\A0;[>-6]\\B0;\\C0', -5, '-B5');+ t.format('[<-6]\\A0;[>=-6]\\B0;\\C0', -5, '-B5');+ t.format('[<=-6]\\A0;[<>-6]\\B0;\\C0', -5, '-B5');+ t.format('[<=-6]\\A0;[<-4]\\B0;\\C0', -5, 'B5');+ t.format('[<=-6]\\A0;[<=-4]\\B0;\\C0', -5, 'B5');+ t.format('[<=-6]\\A0;[=-5]\\B0;\\C0', -5, 'B5');+ t.format('[<=-6]\\A0;[>-6]\\B0;\\C0', -5, '-B5');+ t.format('[<=-6]\\A0;[>=-6]\\B0;\\C0', -5, '-B5');+ t.format('[=-6]\\A0;[<>-6]\\B0;\\C0', -5, '-B5');+ t.format('[=-6]\\A0;[<-4]\\B0;\\C0', -5, 'B5');+ t.format('[=-6]\\A0;[<=-4]\\B0;\\C0', -5, 'B5');+ t.format('[=-6]\\A0;[=-5]\\B0;\\C0', -5, 'B5');+ t.format('[=-6]\\A0;[>-6]\\B0;\\C0', -5, '-B5');+ t.format('[=-6]\\A0;[>=-6]\\B0;\\C0', -5, '-B5');+ t.format('[>2]\\A0;[<>-6]\\B0;\\C0', -5, '-B5');+ t.format('[>2]\\A0;[<-4]\\B0;\\C0', -5, 'B5');+ t.format('[>2]\\A0;[<=-4]\\B0;\\C0', -5, 'B5');+ t.format('[>2]\\A0;[=-5]\\B0;\\C0', -5, 'B5');+ t.format('[>2]\\A0;[>-6]\\B0;\\C0', -5, '-B5');+ t.format('[>2]\\A0;[>=-6]\\B0;\\C0', -5, '-B5');+ t.format('[>=2]\\A0;[<>-6]\\B0;\\C0', -5, '-B5');+ t.format('[>=2]\\A0;[<-4]\\B0;\\C0', -5, 'B5');+ t.format('[>=2]\\A0;[<=-4]\\B0;\\C0', -5, 'B5');+ t.format('[>=2]\\A0;[=-5]\\B0;\\C0', -5, 'B5');+ t.format('[>=2]\\A0;[>-6]\\B0;\\C0', -5, '-B5');+ t.format('[>=2]\\A0;[>=-6]\\B0;\\C0', -5, '-B5');++ t.format('[<>-5]\\A0;[<>-5]\\B0;\\C0', -5, '-C5');+ t.format('[<>-5]\\A0;[<-6]\\B0;\\C0', -5, '-C5');+ t.format('[<>-5]\\A0;[<=-6]\\B0;\\C0', -5, '-C5');+ t.format('[<>-5]\\A0;[=-6]\\B0;\\C0', -5, '-C5');+ t.format('[<>-5]\\A0;[>2]\\B0;\\C0', -5, '-C5');+ t.format('[<>-5]\\A0;[>=2]\\B0;\\C0', -5, '-C5');+ t.format('[<-6]\\A0;[<>-5]\\B0;\\C0', -5, '-C5');+ t.format('[<-6]\\A0;[<-6]\\B0;\\C0', -5, '-C5');+ t.format('[<-6]\\A0;[<=-6]\\B0;\\C0', -5, '-C5');+ t.format('[<-6]\\A0;[=-6]\\B0;\\C0', -5, '-C5');+ t.format('[<-6]\\A0;[>2]\\B0;\\C0', -5, '-C5');+ t.format('[<-6]\\A0;[>=2]\\B0;\\C0', -5, '-C5');+ t.format('[<=-6]\\A0;[<>-5]\\B0;\\C0', -5, '-C5');+ t.format('[<=-6]\\A0;[<-6]\\B0;\\C0', -5, '-C5');+ t.format('[<=-6]\\A0;[<=-6]\\B0;\\C0', -5, '-C5');+ t.format('[<=-6]\\A0;[=-6]\\B0;\\C0', -5, '-C5');+ t.format('[<=-6]\\A0;[>2]\\B0;\\C0', -5, '-C5');+ t.format('[<=-6]\\A0;[>=2]\\B0;\\C0', -5, '-C5');+ t.format('[=-6]\\A0;[<>-5]\\B0;\\C0', -5, '-C5');+ t.format('[=-6]\\A0;[<-6]\\B0;\\C0', -5, '-C5');+ t.format('[=-6]\\A0;[<=-6]\\B0;\\C0', -5, '-C5');+ t.format('[=-6]\\A0;[=-6]\\B0;\\C0', -5, '-C5');+ t.format('[=-6]\\A0;[>2]\\B0;\\C0', -5, '-C5');+ t.format('[=-6]\\A0;[>=2]\\B0;\\C0', -5, '-C5');+ t.format('[>2]\\A0;[<>-5]\\B0;\\C0', -5, '-C5');+ t.format('[>2]\\A0;[<-6]\\B0;\\C0', -5, '-C5');+ t.format('[>2]\\A0;[<=-6]\\B0;\\C0', -5, '-C5');+ t.format('[>2]\\A0;[=-6]\\B0;\\C0', -5, '-C5');+ t.format('[>2]\\A0;[>2]\\B0;\\C0', -5, '-C5');+ t.format('[>2]\\A0;[>=2]\\B0;\\C0', -5, '-C5');+ t.format('[>=2]\\A0;[<>-5]\\B0;\\C0', -5, '-C5');+ t.format('[>=2]\\A0;[<-6]\\B0;\\C0', -5, '-C5');+ t.format('[>=2]\\A0;[<=-6]\\B0;\\C0', -5, '-C5');+ t.format('[>=2]\\A0;[=-6]\\B0;\\C0', -5, '-C5');+ t.format('[>=2]\\A0;[>2]\\B0;\\C0', -5, '-C5');+ t.format('[>=2]\\A0;[>=2]\\B0;\\C0', -5, '-C5');+});++numfmtTest('secondary only conditional', (t) => {+ t.format('"A-"0;[=-11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=-11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=-11]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=-11]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=-11]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=-10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=-10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=-10]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[=-10]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=-10]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=-5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=-5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=-5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=-5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=-5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=-2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=-2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=-2]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=-2]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=-2]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=-1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=-1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=-1]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=-1]"B-"0;"C-"0', -1, 'B-1');+ t.format('"A-"0;[=-1]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=-0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=-0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=-0.5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=-0.5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=-0.5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=0]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=0]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=0]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=0]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=0]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[=0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=0.5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=0.5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=0.5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=1]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=1]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=1]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=2]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=2]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=2]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=10]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=10]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=10]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[=11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[=11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[=11]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[=11]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[=11]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<-11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<-11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<-11]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[<-11]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<-11]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<-10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<-10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<-10]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[<-10]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<-10]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<-5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<-5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<-5]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<-5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<-5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<-2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<-2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<-2]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<-2]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<-2]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<-1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<-1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<-1]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<-1]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<-1]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<-0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<-0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<-0.5]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<-0.5]"B-"0;"C-"0', -1, 'B-1');+ t.format('"A-"0;[<-0.5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<0]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<0]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<0]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<0]"B-"0;"C-"0', -1, 'B-1');+ t.format('"A-"0;[<0]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<0.5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<0.5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<0.5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<1]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<1]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<1]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<2]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<2]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<2]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<10]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<10]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<10]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<11]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<11]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<11]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>-11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>-11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>-11]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[>-11]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>-11]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>-10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>-10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>-10]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>-10]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>-10]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>-5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>-5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>-5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>-5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>-5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>-2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>-2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>-2]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>-2]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>-2]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>-1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>-1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>-1]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>-1]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>-1]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>-0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>-0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>-0.5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>-0.5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>-0.5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>0]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>0]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>0]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>0]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>0]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>0.5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>0.5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>0.5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>1]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>1]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>1]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>2]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>2]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>2]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>10]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>10]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>10]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>11]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>11]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>11]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<=-11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=-11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=-11]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[<=-11]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<=-11]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<=-10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=-10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=-10]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<=-10]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<=-10]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<=-5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=-5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=-5]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<=-5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<=-5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<=-2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=-2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=-2]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<=-2]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<=-2]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<=-1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=-1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=-1]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<=-1]"B-"0;"C-"0', -1, 'B-1');+ t.format('"A-"0;[<=-1]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<=-0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=-0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=-0.5]"B-"0;"C-"0', -10, 'B-10');+ t.format('"A-"0;[<=-0.5]"B-"0;"C-"0', -1, 'B-1');+ t.format('"A-"0;[<=-0.5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<=0]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=0]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=0]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<=0]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<=0]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<=0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=0.5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<=0.5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<=0.5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<=1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=1]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<=1]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<=1]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<=2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=2]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<=2]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<=2]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<=5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<=5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<=5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<=10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=10]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<=10]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<=10]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<=11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<=11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<=11]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<=11]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<=11]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=-11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=-11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=-11]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[>=-11]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>=-11]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=-10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=-10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=-10]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[>=-10]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>=-10]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=-5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=-5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=-5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=-5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>=-5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=-2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=-2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=-2]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=-2]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>=-2]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=-1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=-1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=-1]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=-1]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[>=-1]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=-0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=-0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=-0.5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=-0.5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=-0.5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=0]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=0]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=0]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=0]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=0]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[>=0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=0.5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=0.5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=0.5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>=1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=1]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=1]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=1]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>=2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=2]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=2]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=2]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>=5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=5]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=5]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=5]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>=10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=10]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=10]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=10]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[>=11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[>=11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[>=11]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[>=11]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[>=11]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<>-11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>-11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>-11]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>-11]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>-11]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>-10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>-10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>-10]"B-"0;"C-"0', -10, '-C-10');+ t.format('"A-"0;[<>-10]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>-10]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>-5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>-5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>-5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>-5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>-5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>-2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>-2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>-2]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>-2]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>-2]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>-1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>-1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>-1]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>-1]"B-"0;"C-"0', -1, '-C-1');+ t.format('"A-"0;[<>-1]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>-0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>-0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>-0.5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>-0.5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>-0.5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>0]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>0]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>0]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>0]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>0]"B-"0;"C-"0', 0, 'C-0');+ t.format('"A-"0;[<>0.5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>0.5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>0.5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>0.5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>0.5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>1]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>1]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>1]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>1]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>1]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>2]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>2]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>2]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>2]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>2]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>5]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>5]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>5]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>5]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>5]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>10]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>10]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>10]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>10]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>10]"B-"0;"C-"0', 0, 'B-0');+ t.format('"A-"0;[<>11]"B-"0;"C-"0', 10, 'A-10');+ t.format('"A-"0;[<>11]"B-"0;"C-"0', 1, 'A-1');+ t.format('"A-"0;[<>11]"B-"0;"C-"0', -10, '-B-10');+ t.format('"A-"0;[<>11]"B-"0;"C-"0', -1, '-B-1');+ t.format('"A-"0;[<>11]"B-"0;"C-"0', 0, 'B-0');+});diff --git a/packages/core/src/shared/numfmt/__tests__/date-and-parse.spec.ts b/packages/core/src/shared/numfmt/__tests__/date-and-parse.spec.tsnew file mode 100644index 0000000000..530b38f20a--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/date-and-parse.spec.ts@@ -0,0 +1,53 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { describe, expect, it } from 'vitest';+import {+ isValidDate,+ parseBool,+ parseDate,+ parseNumber,+ parseTime,+ parseValue,+} from '../parse-value';+import { dateFromSerial, dateToSerial } from '../serial-date';++describe('numfmt dates and value parsing', () => {+ it('converts the spreadsheet serial epoch', () => {+ expect(dateFromSerial(28627)).toEqual([1978, 5, 17, 0, 0, 0]);+ expect(dateToSerial([1978, 5, 17])).toBe(28627);+ });++ it('keeps the Excel 1900 leap-day contract', () => {+ expect(dateFromSerial(60)).toEqual([1900, 2, 29, 0, 0, 0]);+ expect(dateFromSerial(60, { leap1900: false })).toEqual([1900, 2, 28, 0, 0, 0]);+ });++ it('parses representative values', () => {+ expect(parseNumber('1,234.50')).toEqual({ v: 1234.5, z: '#,##0.00' });+ expect(parseDate('3/13/1989')).toEqual({ v: 32580, z: 'm/d/yyyy' });+ expect(parseTime('5:30 PM')).toEqual({ v: 0.7291666666666666, z: 'h:mm AM/PM' });+ expect(parseBool('TRUE')).toEqual({ v: true });+ expect(parseValue('$1,000')).toEqual({ v: 1000, z: '$#,##0' });+ expect(isValidDate(2024, 2, 29)).toBe(true);+ expect(isValidDate(2023, 2, 29)).toBe(false);+ });+});diff --git a/packages/core/src/shared/numfmt/__tests__/date-bounds.spec.ts b/packages/core/src/shared/numfmt/__tests__/date-bounds.spec.tsnew file mode 100644index 0000000000..2ed795b69e--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/date-bounds.spec.ts@@ -0,0 +1,258 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { format } from '../api';+import { numfmtTest } from './test-utils';++const ISODATE = 'yyyy-mm-dd';+const ISODATETIME = 'yyyy-mm-dd\\Thh:mm:ss';++numfmtTest('dateSpanLarge: OFF', (t) => {+ const opts = { leap1900: false, dateSpanLarge: false, dateErrorThrows: true };++ t.throws(() => format(ISODATE, -0.1, opts), '-0.1');+ t.throws(() => format(ISODATE, -0.01, opts), '-0.01');+ t.throws(() => format(ISODATE, -0.001, opts), '-0.001');+ t.throws(() => format(ISODATE, -0.0001, opts), '-0.0001');+ t.throws(() => format(ISODATE, -0.00001, opts), '-0.00001');+ t.throws(() => format(ISODATE, -0.000001, opts), '-0.000001');+ t.equal(format(ISODATE, 0, opts), '1899-12-30', '0');++ t.throws(() => format(ISODATE, 2958465.99999422, opts), '2958465.99999422');+ t.equal(format(ISODATE, 2958465.99999421, opts), '9999-12-31', '2958465.99999421');++ const dt = 'yyyy-mm-dd/hh:mm:ss';+ t.throws(() => format(dt, 2958465.99999422, opts), '2958465.99999422');+ t.equal(format(dt, 2958465.99999421, opts), '9999-12-31/23:59:59', '2958465.99999421');++ const dt0 = 'yyyy-mm-dd/hh:mm:ss.0';+ t.throws(() => format(dt0, 2958465.99999943, opts), '2958465.99999943');+ t.equal(format(dt0, 2958465.99999942, opts), '9999-12-31/23:59:59.9', '2958465.99999942');++ const dt00 = `${ISODATE}/hh:mm:ss.00`;+ t.throws(() => format(dt00, 2958465.99999995, opts), '2958465.99999995');+ t.equal(format(dt00, 2958465.99999994, opts), '9999-12-31/23:59:59.99', '2958465.99999994');++ const dt000 = `${ISODATE}/hh:mm:ss.000`;+ // Excel can't really represent 2958465.999999995 so this never happens, but:+ t.throws(() => format(dt000, 2958465.999999995, opts), '2958465.99999999');+ t.equal(format(dt000, 2958465.99999999, opts), '9999-12-31/23:59:59.999', '2958465.99999999');+});++numfmtTest('dateSpanLarge: ON', (t) => {+ t.format(ISODATETIME, 0.1, '1899-12-30T02:24:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.00001157407, '1899-12-29T23:59:59', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, 0, '1899-12-30T00:00:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.1, '1899-12-29T21:36:00', { leap1900: false, dateSpanLarge: true });++ t.format('[s]', -0.1, '-8640', { leap1900: false, dateSpanLarge: true });+ t.format('[m]', -0.1, '-144', { leap1900: false, dateSpanLarge: true });+ t.format('[h]', -0.1, '-2', { leap1900: false, dateSpanLarge: true });+ t.format('[s]', -2, '-172800', { leap1900: false, dateSpanLarge: true });+ t.format('[m]', -2, '-2880', { leap1900: false, dateSpanLarge: true });+ t.format('[h]', -2, '-48', { leap1900: false, dateSpanLarge: true });++ t.format(ISODATETIME, -0.2, '1899-12-29T19:12:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.3, '1899-12-29T16:48:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.4, '1899-12-29T14:24:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.5, '1899-12-29T12:00:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.6, '1899-12-29T09:36:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.7, '1899-12-29T07:12:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.8, '1899-12-29T04:48:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -0.9, '1899-12-29T02:24:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1, '1899-12-29T00:00:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.1, '1899-12-28T21:36:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.2, '1899-12-28T19:12:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.3, '1899-12-28T16:48:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.4, '1899-12-28T14:24:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.5, '1899-12-28T12:00:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.6, '1899-12-28T09:36:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.7, '1899-12-28T07:12:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.8, '1899-12-28T04:48:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -1.9, '1899-12-28T02:24:00', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, -2, '1899-12-28T00:00:00', { leap1900: false, dateSpanLarge: true });++ // negative dates should not be affected by the leap year bug+ t.format(ISODATETIME, -0.2, '1899-12-29T19:12:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -0.3, '1899-12-29T16:48:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -0.4, '1899-12-29T14:24:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -0.5, '1899-12-29T12:00:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -0.6, '1899-12-29T09:36:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -0.7, '1899-12-29T07:12:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -0.8, '1899-12-29T04:48:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -0.9, '1899-12-29T02:24:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1, '1899-12-29T00:00:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.1, '1899-12-28T21:36:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.2, '1899-12-28T19:12:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.3, '1899-12-28T16:48:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.4, '1899-12-28T14:24:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.5, '1899-12-28T12:00:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.6, '1899-12-28T09:36:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.7, '1899-12-28T07:12:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.8, '1899-12-28T04:48:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -1.9, '1899-12-28T02:24:00', { dateSpanLarge: true });+ t.format(ISODATETIME, -2, '1899-12-28T00:00:00', { dateSpanLarge: true });++ t.format(ISODATE, -45000, '1776-10-15', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATE, 35830289, '99999-12-30', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATE, 35830290, '99999-12-31', { leap1900: false, dateSpanLarge: true });+ t.format(ISODATETIME, 35830290.9, '99999-12-31T21:36:00', { leap1900: false, dateSpanLarge: true });+ // out of bounds+ t.format(ISODATETIME, 35830291, '######', { leap1900: false, dateSpanLarge: true, dateErrorNumber: false });+ t.format(ISODATETIME, 35830291, '35830291', { leap1900: false, dateSpanLarge: true, dateErrorNumber: true });++ // Google Sheets emits "00-1-01-02" for TEXT(-694324, ISODATE)+ // this is does not seem all that useful to anyone+ t.format(ISODATE, -694323, '-0001-01-02', { leap1900: false, dateSpanLarge: true, dateErrorNumber: false });+ t.format(ISODATE, -694324, '-0001-01-01', { leap1900: false, dateSpanLarge: true, dateErrorNumber: false });+ t.format(ISODATETIME, -694324.1, '######', { leap1900: false, dateSpanLarge: true, dateErrorNumber: false });+ t.format(ISODATETIME, -694324.1, '-694324.1', { leap1900: false, dateSpanLarge: true, dateErrorNumber: true });+});++numfmtTest('Excel leap 1900 bug: ON', (t) => {+ t.format(ISODATE, 61, '1900-03-01', { leap1900: true });+ t.format(ISODATE, 60, '1900-02-29', { leap1900: true });+ t.format(ISODATE, 59, '1900-02-28', { leap1900: true });+ t.format(ISODATE, 58, '1900-02-27', { leap1900: true });+ t.format(ISODATE, 57, '1900-02-26', { leap1900: true });+ t.format(ISODATE, 56, '1900-02-25', { leap1900: true });+ t.format(ISODATE, 55, '1900-02-24', { leap1900: true });+ t.format(ISODATE, 54, '1900-02-23', { leap1900: true });+ t.format(ISODATE, 53, '1900-02-22', { leap1900: true });+ t.format(ISODATE, 52, '1900-02-21', { leap1900: true });+ t.format(ISODATE, 51, '1900-02-20', { leap1900: true });+ t.format(ISODATE, 50, '1900-02-19', { leap1900: true });+ t.format(ISODATE, 49, '1900-02-18', { leap1900: true });+ t.format(ISODATE, 48, '1900-02-17', { leap1900: true });+ t.format(ISODATE, 47, '1900-02-16', { leap1900: true });+ t.format(ISODATE, 46, '1900-02-15', { leap1900: true });+ t.format(ISODATE, 45, '1900-02-14', { leap1900: true });+ t.format(ISODATE, 44, '1900-02-13', { leap1900: true });+ t.format(ISODATE, 43, '1900-02-12', { leap1900: true });+ t.format(ISODATE, 42, '1900-02-11', { leap1900: true });+ t.format(ISODATE, 41, '1900-02-10', { leap1900: true });+ t.format(ISODATE, 40, '1900-02-09', { leap1900: true });+ t.format(ISODATE, 39, '1900-02-08', { leap1900: true });+ t.format(ISODATE, 38, '1900-02-07', { leap1900: true });+ t.format(ISODATE, 37, '1900-02-06', { leap1900: true });+ t.format(ISODATE, 36, '1900-02-05', { leap1900: true });+ t.format(ISODATE, 35, '1900-02-04', { leap1900: true });+ t.format(ISODATE, 34, '1900-02-03', { leap1900: true });+ t.format(ISODATE, 33, '1900-02-02', { leap1900: true });+ t.format(ISODATE, 32, '1900-02-01', { leap1900: true });+ t.format(ISODATE, 31, '1900-01-31', { leap1900: true });+ t.format(ISODATE, 30, '1900-01-30', { leap1900: true });+ t.format(ISODATE, 29, '1900-01-29', { leap1900: true });+ t.format(ISODATE, 28, '1900-01-28', { leap1900: true });+ t.format(ISODATE, 27, '1900-01-27', { leap1900: true });+ t.format(ISODATE, 26, '1900-01-26', { leap1900: true });+ t.format(ISODATE, 25, '1900-01-25', { leap1900: true });+ t.format(ISODATE, 24, '1900-01-24', { leap1900: true });+ t.format(ISODATE, 23, '1900-01-23', { leap1900: true });+ t.format(ISODATE, 22, '1900-01-22', { leap1900: true });+ t.format(ISODATE, 21, '1900-01-21', { leap1900: true });+ t.format(ISODATE, 20, '1900-01-20', { leap1900: true });+ t.format(ISODATE, 19, '1900-01-19', { leap1900: true });+ t.format(ISODATE, 18, '1900-01-18', { leap1900: true });+ t.format(ISODATE, 17, '1900-01-17', { leap1900: true });+ t.format(ISODATE, 16, '1900-01-16', { leap1900: true });+ t.format(ISODATE, 15, '1900-01-15', { leap1900: true });+ t.format(ISODATE, 14, '1900-01-14', { leap1900: true });+ t.format(ISODATE, 13, '1900-01-13', { leap1900: true });+ t.format(ISODATE, 12, '1900-01-12', { leap1900: true });+ t.format(ISODATE, 11, '1900-01-11', { leap1900: true });+ t.format(ISODATE, 10, '1900-01-10', { leap1900: true });+ t.format(ISODATE, 9, '1900-01-09', { leap1900: true });+ t.format(ISODATE, 8, '1900-01-08', { leap1900: true });+ t.format(ISODATE, 7, '1900-01-07', { leap1900: true });+ t.format(ISODATE, 6, '1900-01-06', { leap1900: true });+ t.format(ISODATE, 5, '1900-01-05', { leap1900: true });+ t.format(ISODATE, 4, '1900-01-04', { leap1900: true });+ t.format(ISODATE, 3, '1900-01-03', { leap1900: true });+ t.format(ISODATE, 2, '1900-01-02', { leap1900: true });+ t.format(ISODATE, 1, '1900-01-01', { leap1900: true });+ t.format(ISODATE, 0, '1900-01-00', { leap1900: true });+});++numfmtTest('Excel 1900 bug: OFF', (t) => {+ t.format(ISODATE, 61, '1900-03-01', { leap1900: false });+ t.format(ISODATE, 60, '1900-02-28', { leap1900: false });+ t.format(ISODATE, 59, '1900-02-27', { leap1900: false });+ t.format(ISODATE, 58, '1900-02-26', { leap1900: false });+ t.format(ISODATE, 57, '1900-02-25', { leap1900: false });+ t.format(ISODATE, 56, '1900-02-24', { leap1900: false });+ t.format(ISODATE, 55, '1900-02-23', { leap1900: false });+ t.format(ISODATE, 54, '1900-02-22', { leap1900: false });+ t.format(ISODATE, 53, '1900-02-21', { leap1900: false });+ t.format(ISODATE, 52, '1900-02-20', { leap1900: false });+ t.format(ISODATE, 51, '1900-02-19', { leap1900: false });+ t.format(ISODATE, 50, '1900-02-18', { leap1900: false });+ t.format(ISODATE, 49, '1900-02-17', { leap1900: false });+ t.format(ISODATE, 48, '1900-02-16', { leap1900: false });+ t.format(ISODATE, 47, '1900-02-15', { leap1900: false });+ t.format(ISODATE, 46, '1900-02-14', { leap1900: false });+ t.format(ISODATE, 45, '1900-02-13', { leap1900: false });+ t.format(ISODATE, 44, '1900-02-12', { leap1900: false });+ t.format(ISODATE, 43, '1900-02-11', { leap1900: false });+ t.format(ISODATE, 42, '1900-02-10', { leap1900: false });+ t.format(ISODATE, 41, '1900-02-09', { leap1900: false });+ t.format(ISODATE, 40, '1900-02-08', { leap1900: false });+ t.format(ISODATE, 39, '1900-02-07', { leap1900: false });+ t.format(ISODATE, 38, '1900-02-06', { leap1900: false });+ t.format(ISODATE, 37, '1900-02-05', { leap1900: false });+ t.format(ISODATE, 36, '1900-02-04', { leap1900: false });+ t.format(ISODATE, 35, '1900-02-03', { leap1900: false });+ t.format(ISODATE, 34, '1900-02-02', { leap1900: false });+ t.format(ISODATE, 33, '1900-02-01', { leap1900: false });+ t.format(ISODATE, 32, '1900-01-31', { leap1900: false });+ t.format(ISODATE, 31, '1900-01-30', { leap1900: false });+ t.format(ISODATE, 30, '1900-01-29', { leap1900: false });+ t.format(ISODATE, 29, '1900-01-28', { leap1900: false });+ t.format(ISODATE, 28, '1900-01-27', { leap1900: false });+ t.format(ISODATE, 27, '1900-01-26', { leap1900: false });+ t.format(ISODATE, 26, '1900-01-25', { leap1900: false });+ t.format(ISODATE, 25, '1900-01-24', { leap1900: false });+ t.format(ISODATE, 24, '1900-01-23', { leap1900: false });+ t.format(ISODATE, 23, '1900-01-22', { leap1900: false });+ t.format(ISODATE, 22, '1900-01-21', { leap1900: false });+ t.format(ISODATE, 21, '1900-01-20', { leap1900: false });+ t.format(ISODATE, 20, '1900-01-19', { leap1900: false });+ t.format(ISODATE, 19, '1900-01-18', { leap1900: false });+ t.format(ISODATE, 18, '1900-01-17', { leap1900: false });+ t.format(ISODATE, 17, '1900-01-16', { leap1900: false });+ t.format(ISODATE, 16, '1900-01-15', { leap1900: false });+ t.format(ISODATE, 15, '1900-01-14', { leap1900: false });+ t.format(ISODATE, 14, '1900-01-13', { leap1900: false });+ t.format(ISODATE, 13, '1900-01-12', { leap1900: false });+ t.format(ISODATE, 12, '1900-01-11', { leap1900: false });+ t.format(ISODATE, 11, '1900-01-10', { leap1900: false });+ t.format(ISODATE, 10, '1900-01-09', { leap1900: false });+ t.format(ISODATE, 9, '1900-01-08', { leap1900: false });+ t.format(ISODATE, 8, '1900-01-07', { leap1900: false });+ t.format(ISODATE, 7, '1900-01-06', { leap1900: false });+ t.format(ISODATE, 6, '1900-01-05', { leap1900: false });+ t.format(ISODATE, 5, '1900-01-04', { leap1900: false });+ t.format(ISODATE, 4, '1900-01-03', { leap1900: false });+ t.format(ISODATE, 3, '1900-01-02', { leap1900: false });+ t.format(ISODATE, 2, '1900-01-01', { leap1900: false });+ t.format(ISODATE, 1, '1899-12-31', { leap1900: false });+ t.format(ISODATE, 0, '1899-12-30', { leap1900: false });+});diff --git a/packages/core/src/shared/numfmt/__tests__/date-parsing.spec.ts b/packages/core/src/shared/numfmt/__tests__/date-parsing.spec.tsnew file mode 100644index 0000000000..714cdb6e5a--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/date-parsing.spec.ts@@ -0,0 +1,184 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++const date = 3290.1278435; // 1909-01-02 03:04:05.678++numfmtTest('Date specifiers:', (t) => {+ t.format('s', date, '6');+ t.format('ss', date, '06');+ t.format('sss', date, '06');+ t.format('ssss', date, '06');+ t.format('sssss', date, '06');+ t.format('ssssss', date, '06');+ t.format('S', date, '6');+ t.format('SS', date, '06');+ t.format('SSS', date, '06');+ t.format('SSSS', date, '06');+ t.format('SSSSS', date, '06');+ t.format('SSSSSS', date, '06');+ t.format('m', date, '1');+ t.format('mm', date, '01');+ t.format('mmm', date, 'Jan');+ t.format('mmmm', date, 'January');+ t.format('mmmmm', date, 'J');+ t.format('mmmmmm', date, 'January');+ t.format('M', date, '1');+ t.format('MM', date, '01');+ t.format('MMM', date, 'Jan');+ t.format('MMMM', date, 'January');+ t.format('MMMMM', date, 'J');+ t.format('MMMMMM', date, 'January');+ t.format('h', date, '3');+ t.format('hh', date, '03');+ t.format('hhh', date, '03');+ t.format('hhhh', date, '03');+ t.format('hhhhh', date, '03');+ t.format('hhhhhh', date, '03');+ t.format('H', date, '3');+ t.format('HH', date, '03');+ t.format('HHH', date, '03');+ t.format('HHHH', date, '03');+ t.format('HHHHH', date, '03');+ t.format('HHHHHH', date, '03');+ t.format('a', date, 'a');+ t.format('aa', date, 'aa');+ t.format('aaa', date, 'Sat');+ t.format('aaaa', date, 'Saturday');+ t.format('aaaaa', date, 'Saturday');+ t.format('aaaaaa', date, 'Saturday');+ t.format('d', date, '2');+ t.format('dd', date, '02');+ t.format('ddd', date, 'Sat');+ t.format('dddd', date, 'Saturday');+ t.format('ddddd', date, 'Saturday');+ t.format('dddddd', date, 'Saturday');+ t.format('D', date, '2');+ t.format('DD', date, '02');+ t.format('DDD', date, 'Sat');+ t.format('DDDD', date, 'Saturday');+ t.format('DDDDD', date, 'Saturday');+ t.format('DDDDDD', date, 'Saturday');+ t.format('y', date, '09');+ t.format('yy', date, '09');+ t.format('yyy', date, '1909');+ t.format('yyyy', date, '1909');+ t.format('yyyyy', date, '1909');+ t.format('yyyyyy', date, '1909');+ t.format('Y', date, '09');+ t.format('YY', date, '09');+ t.format('YYY', date, '1909');+ t.format('YYYY', date, '1909');+ t.format('YYYYY', date, '1909');+ t.format('YYYYYY', date, '1909');+ // elapsed+ t.format('[h]', date, '78963');+ t.format('[hh]', date, '78963');+ t.format('[hhh]', date, '78963');+ t.format('[hhhh]', date, '78963');+ t.format('[hhhhh]', date, '78963');+ t.format('[m]', date, '4737784');+ t.format('[mm]', date, '4737784');+ t.format('[mmm]', date, '4737784');+ t.format('[mmmm]', date, '4737784');+ t.format('[s]', date, '284267046');+ t.format('[ss]', date, '284267046');+ t.format('[sss]', date, '284267046');+ t.format('[ssss]', date, '284267046');+ // fractional seconds+ t.format('[s].0', date, '284267045.7');+ t.format('[s].00', date, '284267045.68');+ t.format('[s].000', date, '284267045.678');+ t.format('s.0', date, '5.7');+ t.format('s.00', date, '5.68');+ t.format('s.000', date, '5.678');+});++numfmtTest('Date specifiers: month vs. minute', (t) => {+ t.format('h', date, '3');+ t.format('m', date, '1');+ t.format('s', date, '6');++ t.format('h-h', date, '3-3');+ t.format('h-m', date, '3-4');+ t.format('h-s', date, '3-6');+ t.format('m-h', date, '1-3');+ t.format('m-m', date, '1-1');+ t.format('m-s', date, '4-6');+ t.format('s-h', date, '6-3');+ t.format('s-m', date, '6-4');+ t.format('s-s', date, '6-6');++ t.format('h-h-m', date, '3-3-4');+ t.format('h-h-s', date, '3-3-6');+ t.format('h-m-h', date, '3-4-3');+ t.format('h-m-m', date, '3-4-1');+ t.format('h-m-s', date, '3-4-6');+ t.format('h-s-h', date, '3-6-3');+ t.format('h-s-m', date, '3-6-4');+ t.format('h-s-s', date, '3-6-6');+ t.format('m-h-h', date, '1-3-3');+ t.format('m-h-m', date, '1-3-4');+ t.format('m-h-s', date, '1-3-6');+ t.format('m-m-h', date, '1-1-3');+ t.format('m-m-m', date, '1-1-1');+ t.format('m-m-s', date, '1-4-6');+ t.format('m-s-h', date, '4-6-3');+ t.format('m-s-m', date, '4-6-1');+ t.format('m-s-s', date, '4-6-6');+ t.format('s-h-h', date, '6-3-3');+ t.format('s-h-m', date, '6-3-4');+ t.format('s-h-s', date, '6-3-6');+ t.format('s-m-h', date, '6-4-3');+ t.format('s-m-m', date, '6-4-1');+ t.format('s-m-s', date, '6-4-6');+ t.format('s-s-h', date, '6-6-3');+ t.format('s-s-m', date, '6-6-4');++ t.format('h-m-m-s', date, '3-4-4-6');+ t.format('h-m-s-m', date, '3-4-6-1');+ t.format('h-s-m-m', date, '3-6-4-1');+ t.format('m-h-m-s', date, '1-3-4-6');+ t.format('m-h-s-m', date, '1-3-6-4');+ t.format('m-m-h-s', date, '1-1-3-6');+ t.format('m-m-s-h', date, '1-4-6-3');+ t.format('m-s-h-m', date, '4-6-3-4');+ t.format('m-s-m-h', date, '4-6-1-3');+ t.format('s-h-m-m', date, '6-3-4-1');+ t.format('s-m-h-m', date, '6-4-3-4');+ t.format('s-m-m-h', date, '6-4-1-3');++ t.format('y-m-d', date, '09-1-2');+ t.format('d-m-y', date, '2-1-09');+ t.format('yy-mm-dd', date, '09-01-02');++ t.format('yyyy', date, '1909');+ t.format('yyyy-mm', date, '1909-01');+ t.format('yyyy-mm-dd', date, '1909-01-02');+ t.format('yyyy-mm-dd\\Thh', date, '1909-01-02T03');+ t.format('yyyy-mm-dd\\Thh-mm', date, '1909-01-02T03-04');+ t.format('yyyy-mm-dd\\Thh-mm-ss', date, '1909-01-02T03-04-06');+ t.format('yyyy-mm-dd\\Thh-mm-ss.000', date, '1909-01-02T03-04-05.678');++ t.format('yyyy-mm-dd\\Thh-mm-ss.000', 60, '1900-02-29T00-00-00.000');+ t.format('yyyy-mm-dd\\Thh-mm-ss.000', 61, '1900-03-01T00-00-00.000');+});diff --git a/packages/core/src/shared/numfmt/__tests__/decimal.spec.ts b/packages/core/src/shared/numfmt/__tests__/decimal.spec.tsnew file mode 100644index 0000000000..65df32d722--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/decimal.spec.ts@@ -0,0 +1,168 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// @vitest-environment node++import { describe, expect, it } from 'vitest';+import {+ decimalFromNumber,+ decimalPartsToNumber,+ decimalPartsToPlainString,+ roundDecimal,+ roundScientificDecimal,+ shiftDecimal,+} from '../decimal';++describe('spreadsheet decimal rounding', () => {+ it('rejects non-finite numbers', () => {+ expect(() => decimalFromNumber(Number.NaN)).toThrow(RangeError);+ expect(() => decimalFromNumber(Number.POSITIVE_INFINITY)).toThrow(RangeError);+ expect(() => decimalFromNumber(Number.NEGATIVE_INFINITY)).toThrow(RangeError);+ });++ it('canonicalizes to 15 significant digits', () => {+ expect(decimalFromNumber(10.155)).toEqual({+ negative: false,+ digits: '10155',+ exponent: 1,+ });+ expect(decimalFromNumber(450000000000000.44)).toEqual({+ negative: false,+ digits: '45',+ exponent: 14,+ });+ expect(decimalFromNumber(1.234567890123456)).toEqual({+ negative: false,+ digits: '123456789012346',+ exponent: 0,+ });+ });++ it('preserves signed zero while canonicalizing and shifting', () => {+ expect(decimalFromNumber(0)).toEqual({+ negative: false,+ digits: '0',+ exponent: 0,+ });+ expect(shiftDecimal(decimalFromNumber(-0), 12)).toEqual({+ negative: true,+ digits: '0',+ exponent: 0,+ });+ });++ it('rounds magnitude half-up for either sign', () => {+ expect(roundDecimal(decimalFromNumber(1.005), 2)).toEqual({+ negative: false,+ integer: '1',+ fraction: '01',+ zero: false,+ });+ expect(roundDecimal(decimalFromNumber(-1.005), 2)).toEqual({+ negative: true,+ integer: '1',+ fraction: '01',+ zero: false,+ });+ });++ it('distinguishes values immediately below and above a half tie', () => {+ expect(decimalPartsToNumber(roundDecimal(decimalFromNumber(1.00499999999999), 2))).toBe(1);+ expect(decimalPartsToNumber(roundDecimal(decimalFromNumber(1.00500000000001), 2))).toBe(1.01);+ });++ it('rounds negative places and carries across the integer boundary', () => {+ expect(decimalPartsToNumber(roundDecimal(decimalFromNumber(50), -2))).toBe(100);+ expect(decimalPartsToNumber(roundDecimal(decimalFromNumber(9.995), 2))).toBe(10);+ expect(decimalPartsToNumber(roundDecimal(decimalFromNumber(999.5), 0))).toBe(1000);+ });++ it('scales by shifting the decimal exponent', () => {+ const percent = shiftDecimal(decimalFromNumber(0.10155), 2.9);++ expect(percent).toEqual({+ negative: false,+ digits: '10155',+ exponent: 1,+ });+ expect(roundDecimal(percent, 2)).toMatchObject({+ integer: '10',+ fraction: '16',+ });+ });++ it('normalizes rounded zero to positive number and plain string output', () => {+ const rounded = roundDecimal(decimalFromNumber(-0.004), 2);++ expect(rounded).toEqual({+ negative: true,+ integer: '0',+ fraction: '',+ zero: true,+ });+ expect(Object.is(decimalPartsToNumber(rounded), -0)).toBe(false);+ expect(decimalPartsToPlainString(rounded)).toBe('0');+ expect(decimalPartsToPlainString(roundDecimal(decimalFromNumber(-1.005), 2))).toBe('-1.01');+ });++ it('normalizes scientific carry', () => {+ expect(roundScientificDecimal(decimalFromNumber(9.995), 1, true, 2)).toEqual({+ exponent: 1,+ rounded: {+ negative: false,+ integer: '1',+ fraction: '',+ zero: false,+ },+ });+ });++ it('keeps scientific zero at exponent zero', () => {+ expect(roundScientificDecimal(decimalFromNumber(-0), 3, false, 4)).toEqual({+ exponent: 0,+ rounded: {+ negative: true,+ integer: '0',+ fraction: '',+ zero: true,+ },+ });+ });++ it('groups engineering notation by the requested integer digits', () => {+ expect(roundScientificDecimal(decimalFromNumber(12345), 3, true, 2)).toEqual({+ exponent: 3,+ rounded: {+ negative: false,+ integer: '12',+ fraction: '35',+ zero: false,+ },+ });+ });++ it('shifts scientific notation without an integer pattern', () => {+ expect(roundScientificDecimal(decimalFromNumber(12.34), 1, false, 2)).toEqual({+ exponent: 2,+ rounded: {+ negative: false,+ integer: '0',+ fraction: '12',+ zero: false,+ },+ });+ });+});diff --git a/packages/core/src/shared/numfmt/__tests__/error.spec.ts b/packages/core/src/shared/numfmt/__tests__/error.spec.tsnew file mode 100644index 0000000000..379f679a09--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/error.spec.ts@@ -0,0 +1,305 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { isDateFormat, isPercentFormat, isTextFormat } from '../api';+import { numfmtTest } from './test-utils';++const excelOpts = { dateSpanLarge: false, dateErrorNumber: false };++numfmtTest('Various format restrictions', (t) => {+ // no more than 4 sections+ t.formatInvalid('a;b;c;d;');+ t.formatInvalid('#;#;#;#;#');++ // no more than 2 conditional sections+ t.formatInvalid('[<-2]a;[<-1]b;[>2]c;d;');++ // can't mix dates and numbers (within a segment)+ t.formatInvalid('y 0');+ t.formatInvalid('yyyy 0');+ t.formatInvalid('m 0');+ t.formatInvalid('mmmm 0');+ t.formatInvalid('d 0');+ t.formatInvalid('dddd 0');+ t.formatInvalid('s 0');+ t.formatInvalid('h 0');+ t.formatInvalid('AM/PM 0');+ t.formatInvalid('[h] 0');+ t.formatInvalid('[m] 0');+ t.formatInvalid('[s] 0');+ t.formatInvalid('y #');+ t.formatInvalid('yyyy #');+ t.formatInvalid('m #');+ t.formatInvalid('mmmm #');+ t.formatInvalid('d #');+ t.formatInvalid('dddd #');+ t.formatInvalid('s #');+ t.formatInvalid('h #');+ t.formatInvalid('AM/PM #');+ t.formatInvalid('[h] #');+ t.formatInvalid('[m] #');+ t.formatInvalid('[s] #');+ t.formatInvalid('y ?');+ t.formatInvalid('yyyy ?');+ t.formatInvalid('m ?');+ t.formatInvalid('mmmm ?');+ t.formatInvalid('d ?');+ t.formatInvalid('dddd ?');+ t.formatInvalid('s ?');+ t.formatInvalid('h ?');+ t.formatInvalid('AM/PM ?');+ t.formatInvalid('[h] ?');+ t.formatInvalid('[m] ?');+ t.formatInvalid('[s] ?');++ t.formatInvalid('d .#');+ t.formatInvalid('mm%');+ t.formatInvalid('mm@');++ // no out of bounds dates+ t.format('dddd, dd. mmmm yyy', -1, '######', excelOpts);+ t.format('dddd, dd. mmmm yyy', 2958470, '######', excelOpts);++ // isDate should not throw on malformed input+ t.equal(isDateFormat('dddd, dd. mmmm yyy'), true, "isDateFormat('dddd, dd. mmmm yyy')");+ t.equal(isDateFormat('0.0M'), false, "isDateFormat('0.0M')");++ // utility functions exist and work on error formatters+ t.equal(isDateFormat('y 0'), false, "isDateFormat('y 0')");+ t.equal(isPercentFormat('y 0'), false, "isPercentFormat('y 0')");+ t.equal(isTextFormat('y 0'), false, "isTextFormat('y 0')");+});++numfmtTest('Single characters', (t) => {+ t.format(' ', 1, ' ');+ t.format('!', 1, '!');+ t.formatInvalid('"');+ t.format('#', 1, '1');+ t.format('$', 1, '$');+ t.format('%', 1, '%');+ t.format('&', 1, '&');+ t.format('\'', 1, '\'');+ t.format('(', 1, '(');+ t.format(')', 1, ')');+ t.formatInvalid('*');+ t.format('+', 1, '+');+ t.format(',', 1, ',');+ t.format('-', 1, '-');+ t.format('.', 1, '.');+ // slash is allowed in date formats+ t.format('d/', 1, '1/');+ // slash otherwise means vulgar fractions+ t.format('0/0', 0, '0/1');+ t.format('0/0', 1, '1/1');+ t.formatInvalid('0/');+ t.formatInvalid('/0');+ t.formatInvalid('/');+ t.format('0', 1, '1');+ t.format('1', 1, '1');+ t.format('2', 1, '2');+ t.format('3', 1, '3');+ t.format('4', 1, '4');+ t.format('5', 1, '5');+ t.format('6', 1, '6');+ t.format('7', 1, '7');+ t.format('8', 1, '8');+ t.format('9', 1, '9');+ t.format(':', 1, ':');+ t.format(';', 1, '');+ t.format('<', 1, '<');+ t.format('=', 1, '=');+ t.format('>', 1, '>');+ t.format('?', 1, '1');+ t.format('@', 1, '1');+ t.format('A', 1, 'A');+ // B is not allowed at the end of the pattern+ t.formatInvalid('B');+ t.format('B ', 1, '43 ');+ t.format('B;', 1, '43');+ t.format('C', 1, 'C');+ t.format('D', 1, '1');+ // E is stricter than e, for whatever reason (see E tests below)+ t.formatInvalid('E');+ t.format('F', 1, 'F');+ t.format('G', 1, '');+ t.format('H', 1, '0');+ t.format('I', 1, 'I');+ t.format('J', 1, 'J');+ t.format('K', 1, 'K');+ t.format('L', 1, 'L');+ t.format('M', 1, '1');+ t.formatInvalid('N');+ t.format('O', 1, 'O');+ t.format('P', 1, 'P');+ t.format('Q', 1, 'Q');+ t.format('R', 1, 'R');+ t.format('S', 1, '0');+ t.format('T', 1, 'T');+ t.format('U', 1, 'U');+ t.format('V', 1, 'V');+ t.format('W', 1, 'W');+ t.format('X', 1, 'X');+ t.format('Y', 1, '00');+ t.format('Z', 1, 'Z');+ t.formatInvalid('[');+ t.formatInvalid('\\');+ t.format(']', 1, ']');+ t.format('^', 1, '^');+ t.formatInvalid('_');+ t.format('`', 1, '`');+ t.format('a', 1, 'a');+ t.format('b', 1, '43');+ t.format('c', 1, 'c');+ t.format('d', 1, '1');+ t.format('e', 1, '1900');+ t.format('f', 1, 'f');+ t.format('g', 1, '');+ t.format('h', 1, '0');+ t.format('i', 1, 'i');+ t.format('j', 1, 'j');+ t.format('k', 1, 'k');+ t.format('l', 1, 'l');+ t.format('m', 1, '1');+ t.formatInvalid('n');+ t.format('o', 1, 'o');+ t.format('p', 1, 'p');+ t.format('q', 1, 'q');+ t.format('r', 1, 'r');+ t.format('s', 1, '0');+ t.format('t', 1, 't');+ t.format('u', 1, 'u');+ t.format('v', 1, 'v');+ t.format('w', 1, 'w');+ t.format('x', 1, 'x');+ t.format('y', 1, '00');+ t.format('z', 1, 'z');+ t.format('{', 1, '{');+ t.format('|', 1, '|');+ t.format('}', 1, '}');+ t.format('~', 1, '~');+ t.format('', 1, '');+ t.format('Ä', 1, 'Ä');+ t.format('Å', 1, 'Å');+ t.format('Ç', 1, 'Ç');+ t.formatInvalid('É');+ t.formatInvalid('Ñ');+ t.format('Ö', 1, 'Ö');+ t.format('Ü', 1, 'Ü');+ t.format('á', 1, 'á');+ t.format('à', 1, 'à');+ t.format('â', 1, 'â');+ t.format('ä', 1, 'ä');+ t.format('ã', 1, 'ã');+ t.format('å', 1, 'å');+ t.format('ç', 1, 'ç');+ t.formatInvalid('é');+ t.formatInvalid('è');+ t.formatInvalid('ê');+ t.formatInvalid('ë');+ t.format('í', 1, 'í');+ t.format('ì', 1, 'ì');+ t.format('î', 1, 'î');+ t.format('ï', 1, 'ï');+ t.formatInvalid('ñ');+ t.format('ó', 1, 'ó');+ t.format('ò', 1, 'ò');+ t.format('ô', 1, 'ô');+ t.format('ö', 1, 'ö');+ t.format('õ', 1, 'õ');+ t.format('ú', 1, 'ú');+ t.format('ù', 1, 'ù');+ t.format('û', 1, 'û');+ t.format('ü', 1, 'ü');+ t.format('†', 1, '†');+ t.format('°', 1, '°');+ t.format('¢', 1, '¢');+ t.format('£', 1, '£');+ t.format('§', 1, '§');+ t.format('•', 1, '•');+ t.format('¶', 1, '¶');+ t.format('ß', 1, 'ß');+ t.format('®', 1, '®');+ t.format('©', 1, '©');+ t.format('™', 1, '™');+ t.format('´', 1, '´');+ t.format('¨', 1, '¨');+ t.format('≠', 1, '≠');+ t.format('Æ', 1, 'Æ');+ t.format('Ø', 1, 'Ø');+ t.format('∞', 1, '∞');+ t.format('±', 1, '±');+ t.format('≤', 1, '≤');+ t.format('≥', 1, '≥');+ t.format('¥', 1, '¥');+ t.format('µ', 1, 'µ');+ t.format('∂', 1, '∂');+ t.format('∑', 1, '∑');+ t.format('∏', 1, '∏');+ t.format('π', 1, 'π');+ t.format('∫', 1, '∫');+ t.format('ª', 1, 'ª');+ t.format('º', 1, 'º');+ t.format('Ω', 1, 'Ω');+ t.format('æ', 1, 'æ');+ t.format('ø', 1, 'ø');+ t.format('¿', 1, '¿');+ t.format('¡', 1, '¡');+ t.format('¬', 1, '¬');+});++numfmtTest('The "E" and "e" operators', (t) => {+ t.format('e', 1, '1900');+ t.formatInvalid('0e');+ t.formatInvalid('e0');+ t.formatInvalid('0e0');+ t.format('e+', 1, '1900+'); // Sheets does not allow this+ t.formatInvalid('0e+');+ t.formatInvalid('e+0');+ t.formatInvalid('0e+0'); // Sheets emits "1e+0"+ t.format('e-', 1, '1900-'); // Sheets emits "1e+0"+ t.formatInvalid('0e-');+ t.formatInvalid('e-0');+ t.formatInvalid('0e-0'); // Sheets emits "1e0"+ t.formatInvalid('E');+ t.formatInvalid('0E');+ t.formatInvalid('E0');+ t.formatInvalid('0E0');+ t.formatInvalid('E+');+ t.formatInvalid('0E+');+ t.formatInvalid('E+0');+ t.format('0E+0', 1, '1E+0');+ t.formatInvalid('E-');+ t.formatInvalid('0E-');+ t.formatInvalid('E-0');+ t.format('0E-0', 1, '1E0');++ t.formatInvalid('0 e 0');+ t.formatInvalid('0 e + 0');+ t.formatInvalid('0 e +0');+ t.formatInvalid('0 e+ 0'); // Sheets emits "1 e +4"++ t.formatInvalid('0 E 0');+ t.formatInvalid('0 E + 0');+ t.formatInvalid('0 E +0');+ t.format('0 E+ 0', 1, '1 E +0');++ t.format('e-m', 1, '1900-1');+});diff --git a/packages/core/src/shared/numfmt/__tests__/exp-format.spec.ts b/packages/core/src/shared/numfmt/__tests__/exp-format.spec.tsnew file mode 100644index 0000000000..6543354f6b--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/exp-format.spec.ts@@ -0,0 +1,432 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++numfmtTest('Excel-compatible scientific decimal rounding', (t) => {+ t.format('0.00E+00', 2.155, '2.16E+00');+ t.format('0.00E+00', -2.155, '-2.16E+00');+ t.format('0.00E+00', 9.995, '1.00E+01');+ t.format('0.00E+00', -9.995, '-1.00E+01');+ t.format('0.00E+00', 1.0155e20, '1.02E+20');+ t.format('0.00E+00', 1.0155e-20, '1.02E-20');+ t.format('0.00E+00', 1e308, '1.00E+308');+ t.format('0.00E+00', 1e-308, '1.00E-308');+});++numfmtTest('Shortest exponential compatibility below exponent -308', (t) => {+ t.format('0.000E+000', 2.33e-321, '2.330E-321');+ t.format('0.000E+000', 1e-308, '1.000E-308');+});++numfmtTest('Exponent detection', (t) => {+ t.format('0E+00', 95000000, '1E+08');+ t.format('0E+00', 96000000, '1E+08');+ t.format('0E+00', 97000000, '1E+08');+ t.format('0E+00', 98000000, '1E+08');+ t.format('0E+00', 99000000, '1E+08');+ t.format('0E+00', 100000000, '1E+08');+ t.format('0E+00', 110000000, '1E+08');+ t.format('0E+00', 120000000, '1E+08');+ t.format('0E+00', 130000000, '1E+08');+ t.format('0E+00', 140000000, '1E+08');+ t.format('0E+00', 199999999, '2E+08');+ t.format('0E+00', 899999999, '9E+08');+ t.format('0E+00', 990000000, '1E+09');+ t.format('0E+00', 999000000, '1E+09');+ t.format('0E+00', 999900000, '1E+09');+ t.format('0E+00', 999990000, '1E+09');+ t.format('0.0E+00', 95000000, '9.5E+07');+ t.format('0.0E+00', 96000000, '9.6E+07');+ t.format('0.0E+00', 97000000, '9.7E+07');+ t.format('0.0E+00', 98000000, '9.8E+07');+ t.format('0.0E+00', 99000000, '9.9E+07');+ t.format('0.0E+00', 100000000, '1.0E+08');+ t.format('0.0E+00', 110000000, '1.1E+08');+ t.format('0.0E+00', 120000000, '1.2E+08');+ t.format('0.0E+00', 130000000, '1.3E+08');+ t.format('0.0E+00', 140000000, '1.4E+08');+ t.format('0.0E+00', 199999999, '2.0E+08');+ t.format('0.0E+00', 899999999, '9.0E+08');+ t.format('0.0E+00', 990000000, '9.9E+08');+ t.format('0.0E+00', 999000000, '1.0E+09');+ t.format('0.0E+00', 999900000, '1.0E+09');+ t.format('0.0E+00', 999990000, '1.0E+09');+ t.format('0.00E+00', 95000000, '9.50E+07');+ t.format('0.00E+00', 96000000, '9.60E+07');+ t.format('0.00E+00', 97000000, '9.70E+07');+ t.format('0.00E+00', 98000000, '9.80E+07');+ t.format('0.00E+00', 99000000, '9.90E+07');+ t.format('0.00E+00', 100000000, '1.00E+08');+ t.format('0.00E+00', 110000000, '1.10E+08');+ t.format('0.00E+00', 120000000, '1.20E+08');+ t.format('0.00E+00', 130000000, '1.30E+08');+ t.format('0.00E+00', 140000000, '1.40E+08');+ t.format('0.00E+00', 199999999, '2.00E+08');+ t.format('0.00E+00', 899999999, '9.00E+08');+ t.format('0.00E+00', 990000000, '9.90E+08');+ t.format('0.00E+00', 999000000, '9.99E+08');+ t.format('0.00E+00', 999900000, '1.00E+09');+ t.format('0.00E+00', 999990000, '1.00E+09');+ t.format('0.000E+00', 95000000, '9.500E+07');+ t.format('0.000E+00', 96000000, '9.600E+07');+ t.format('0.000E+00', 97000000, '9.700E+07');+ t.format('0.000E+00', 98000000, '9.800E+07');+ t.format('0.000E+00', 99000000, '9.900E+07');+ t.format('0.000E+00', 100000000, '1.000E+08');+ t.format('0.000E+00', 110000000, '1.100E+08');+ t.format('0.000E+00', 120000000, '1.200E+08');+ t.format('0.000E+00', 130000000, '1.300E+08');+ t.format('0.000E+00', 140000000, '1.400E+08');+ t.format('0.000E+00', 199999999, '2.000E+08');+ t.format('0.000E+00', 899999999, '9.000E+08');+ t.format('0.000E+00', 990000000, '9.900E+08');+ t.format('0.000E+00', 999000000, '9.990E+08');+ t.format('0.000E+00', 999900000, '9.999E+08');+ t.format('0.000E+00', 999990000, '1.000E+09');+});++numfmtTest('Exponent detection', (t) => {+ t.format('0.E+00', 9, '9.E+00');+ t.format('0.E+00', 9.49999, '9.E+00');+ t.format('0.E+00', 9.59999, '1.E+01');+ t.format('0.E+00', 9.69999, '1.E+01');+ t.format('0.E+00', 10, '1.E+01');+ t.format('0.E+00', 90, '9.E+01');+ t.format('0.E+00', 94.9999, '9.E+01');+ t.format('0.E+00', 95.9999, '1.E+02');+ t.format('0.E+00', 96.9999, '1.E+02');+ t.format('0.E+00', 100, '1.E+02');+ t.format('0.E+00', 900, '9.E+02');+ t.format('0.E+00', 949.999, '9.E+02');+ t.format('0.E+00', 959.999, '1.E+03');+ t.format('0.E+00', 969.999, '1.E+03');+ t.format('0.E+00', 1000, '1.E+03');+ t.format('0.E+00', 9000, '9.E+03');+ t.format('0.E+00', 9499.99, '9.E+03');+ t.format('0.E+00', 9599.99, '1.E+04');+ t.format('0.E+00', 9699.99, '1.E+04');+ t.format('0.E+00', 10000, '1.E+04');+ t.format('0.E+00', 90000, '9.E+04');+ t.format('0.E+00', 94999.9, '9.E+04');+ t.format('0.E+00', 95999.9, '1.E+05');+ t.format('0.E+00', 96999.9, '1.E+05');+ t.format('0.E+00', 100000, '1.E+05');+ t.format('0.0E+00', 9, '9.0E+00');+ t.format('0.0E+00', 9.49999, '9.5E+00');+ t.format('0.0E+00', 9.59999, '9.6E+00');+ t.format('0.0E+00', 9.69999, '9.7E+00');+ t.format('0.0E+00', 10, '1.0E+01');+ t.format('0.0E+00', 90, '9.0E+01');+ t.format('0.0E+00', 94.9999, '9.5E+01');+ t.format('0.0E+00', 95.9999, '9.6E+01');+ t.format('0.0E+00', 96.9999, '9.7E+01');+ t.format('0.0E+00', 100, '1.0E+02');+ t.format('0.0E+00', 900, '9.0E+02');+ t.format('0.0E+00', 949.999, '9.5E+02');+ t.format('0.0E+00', 959.999, '9.6E+02');+ t.format('0.0E+00', 969.999, '9.7E+02');+ t.format('0.0E+00', 1000, '1.0E+03');+ t.format('0.0E+00', 9000, '9.0E+03');+ t.format('0.0E+00', 9499.99, '9.5E+03');+ t.format('0.0E+00', 9599.99, '9.6E+03');+ t.format('0.0E+00', 9699.99, '9.7E+03');+ t.format('0.0E+00', 10000, '1.0E+04');+ t.format('0.0E+00', 90000, '9.0E+04');+ t.format('0.0E+00', 94999.9, '9.5E+04');+ t.format('0.0E+00', 95999.9, '9.6E+04');+ t.format('0.0E+00', 96999.9, '9.7E+04');+ t.format('0.0E+00', 100000, '1.0E+05');+ t.format('0.00E+00', 9, '9.00E+00');+ t.format('0.00E+00', 9.49999, '9.50E+00');+ t.format('0.00E+00', 9.59999, '9.60E+00');+ t.format('0.00E+00', 9.69999, '9.70E+00');+ t.format('0.00E+00', 10, '1.00E+01');+ t.format('0.00E+00', 90, '9.00E+01');+ t.format('0.00E+00', 94.9999, '9.50E+01');+ t.format('0.00E+00', 95.9999, '9.60E+01');+ t.format('0.00E+00', 96.9999, '9.70E+01');+ t.format('0.00E+00', 100, '1.00E+02');+ t.format('0.00E+00', 900, '9.00E+02');+ t.format('0.00E+00', 949.999, '9.50E+02');+ t.format('0.00E+00', 959.999, '9.60E+02');+ t.format('0.00E+00', 969.999, '9.70E+02');+ t.format('0.00E+00', 1000, '1.00E+03');+ t.format('0.00E+00', 9000, '9.00E+03');+ t.format('0.00E+00', 9499.99, '9.50E+03');+ t.format('0.00E+00', 9599.99, '9.60E+03');+ t.format('0.00E+00', 9699.99, '9.70E+03');+ t.format('0.00E+00', 10000, '1.00E+04');+ t.format('0.00E+00', 90000, '9.00E+04');+ t.format('0.00E+00', 94999.9, '9.50E+04');+ t.format('0.00E+00', 95999.9, '9.60E+04');+ t.format('0.00E+00', 96999.9, '9.70E+04');+ t.format('0.00E+00', 100000, '1.00E+05');+ t.format('00.E+00', 9, '09.E+00');+ t.format('00.E+00', 9.49999, '09.E+00');+ t.format('00.E+00', 9.59999, '10.E+00');+ t.format('00.E+00', 9.69999, '10.E+00');+ t.format('00.E+00', 10, '10.E+00');+ t.format('00.E+00', 90, '90.E+00');+ t.format('00.E+00', 94.9999, '95.E+00');+ t.format('00.E+00', 95.9999, '96.E+00');+ t.format('00.E+00', 96.9999, '97.E+00');+ t.format('00.E+00', 100, '01.E+02');+ t.format('00.E+00', 900, '09.E+02');+ t.format('00.E+00', 949.999, '09.E+02');+ t.format('00.E+00', 959.999, '10.E+02');+ t.format('00.E+00', 969.999, '10.E+02');+ t.format('00.E+00', 1000, '10.E+02');+ t.format('00.E+00', 9000, '90.E+02');+ t.format('00.E+00', 9499.99, '95.E+02');+ t.format('00.E+00', 9599.99, '96.E+02');+ t.format('00.E+00', 9699.99, '97.E+02');+ t.format('00.E+00', 10000, '01.E+04');+ t.format('00.E+00', 90000, '09.E+04');+ t.format('00.E+00', 94999.9, '09.E+04');+ t.format('00.E+00', 95999.9, '10.E+04');+ t.format('00.E+00', 96999.9, '10.E+04');+ t.format('00.E+00', 100000, '10.E+04');+ t.format('00.0E+00', 9, '09.0E+00');+ t.format('00.0E+00', 9.49999, '09.5E+00');+ t.format('00.0E+00', 9.59999, '09.6E+00');+ t.format('00.0E+00', 9.69999, '09.7E+00');+ t.format('00.0E+00', 10, '10.0E+00');+ t.format('00.0E+00', 90, '90.0E+00');+ t.format('00.0E+00', 94.9999, '95.0E+00');+ t.format('00.0E+00', 95.9999, '96.0E+00');+ t.format('00.0E+00', 96.9999, '97.0E+00');+ t.format('00.0E+00', 100, '01.0E+02');+ t.format('00.0E+00', 900, '09.0E+02');+ t.format('00.0E+00', 949.999, '09.5E+02');+ t.format('00.0E+00', 959.999, '09.6E+02');+ t.format('00.0E+00', 969.999, '09.7E+02');+ t.format('00.0E+00', 1000, '10.0E+02');+ t.format('00.0E+00', 9000, '90.0E+02');+ t.format('00.0E+00', 9499.99, '95.0E+02');+ t.format('00.0E+00', 9599.99, '96.0E+02');+ t.format('00.0E+00', 9699.99, '97.0E+02');+ t.format('00.0E+00', 10000, '01.0E+04');+ t.format('00.0E+00', 90000, '09.0E+04');+ t.format('00.0E+00', 94999.9, '09.5E+04');+ t.format('00.0E+00', 95999.9, '09.6E+04');+ t.format('00.0E+00', 96999.9, '09.7E+04');+ t.format('00.0E+00', 100000, '10.0E+04');+ t.format('00.00E+00', 9, '09.00E+00');+ t.format('00.00E+00', 9.49999, '09.50E+00');+ t.format('00.00E+00', 9.59999, '09.60E+00');+ t.format('00.00E+00', 9.69999, '09.70E+00');+ t.format('00.00E+00', 10, '10.00E+00');+ t.format('00.00E+00', 90, '90.00E+00');+ t.format('00.00E+00', 94.9999, '95.00E+00');+ t.format('00.00E+00', 95.9999, '96.00E+00');+ t.format('00.00E+00', 96.9999, '97.00E+00');+ t.format('00.00E+00', 100, '01.00E+02');+ t.format('00.00E+00', 900, '09.00E+02');+ t.format('00.00E+00', 949.999, '09.50E+02');+ t.format('00.00E+00', 959.999, '09.60E+02');+ t.format('00.00E+00', 969.999, '09.70E+02');+ t.format('00.00E+00', 1000, '10.00E+02');+ t.format('00.00E+00', 9000, '90.00E+02');+ t.format('00.00E+00', 9499.99, '95.00E+02');+ t.format('00.00E+00', 9599.99, '96.00E+02');+ t.format('00.00E+00', 9699.99, '97.00E+02');+ t.format('00.00E+00', 10000, '01.00E+04');+ t.format('00.00E+00', 90000, '09.00E+04');+ t.format('00.00E+00', 94999.9, '09.50E+04');+ t.format('00.00E+00', 95999.9, '09.60E+04');+ t.format('00.00E+00', 96999.9, '09.70E+04');+ t.format('00.00E+00', 100000, '10.00E+04');+ t.format('000.E+00', 9, '009.E+00');+ t.format('000.E+00', 9.49999, '009.E+00');+ t.format('000.E+00', 9.59999, '010.E+00');+ t.format('000.E+00', 9.69999, '010.E+00');+ t.format('000.E+00', 10, '010.E+00');+ t.format('000.E+00', 90, '090.E+00');+ t.format('000.E+00', 94.9999, '095.E+00');+ t.format('000.E+00', 95.9999, '096.E+00');+ t.format('000.E+00', 96.9999, '097.E+00');+ t.format('000.E+00', 100, '100.E+00');+ t.format('000.E+00', 900, '900.E+00');+ t.format('000.E+00', 949.999, '950.E+00');+ t.format('000.E+00', 959.999, '960.E+00');+ t.format('000.E+00', 969.999, '970.E+00');+ t.format('000.E+00', 1000, '001.E+03');+ t.format('000.E+00', 9000, '009.E+03');+ t.format('000.E+00', 9499.99, '009.E+03');+ t.format('000.E+00', 9599.99, '010.E+03');+ t.format('000.E+00', 9699.99, '010.E+03');+ t.format('000.E+00', 10000, '010.E+03');+ t.format('000.E+00', 90000, '090.E+03');+ t.format('000.E+00', 94999.9, '095.E+03');+ t.format('000.E+00', 95999.9, '096.E+03');+ t.format('000.E+00', 96999.9, '097.E+03');+ t.format('000.E+00', 100000, '100.E+03');+ t.format('000.0E+00', 9, '009.0E+00');+ t.format('000.0E+00', 9.49999, '009.5E+00');+ t.format('000.0E+00', 9.59999, '009.6E+00');+ t.format('000.0E+00', 9.69999, '009.7E+00');+ t.format('000.0E+00', 10, '010.0E+00');+ t.format('000.0E+00', 90, '090.0E+00');+ t.format('000.0E+00', 94.9999, '095.0E+00');+ t.format('000.0E+00', 95.9999, '096.0E+00');+ t.format('000.0E+00', 96.9999, '097.0E+00');+ t.format('000.0E+00', 100, '100.0E+00');+ t.format('000.0E+00', 900, '900.0E+00');+ t.format('000.0E+00', 949.999, '950.0E+00');+ t.format('000.0E+00', 959.999, '960.0E+00');+ t.format('000.0E+00', 969.999, '970.0E+00');+ t.format('000.0E+00', 1000, '001.0E+03');+ t.format('000.0E+00', 9000, '009.0E+03');+ t.format('000.0E+00', 9499.99, '009.5E+03');+ t.format('000.0E+00', 9599.99, '009.6E+03');+ t.format('000.0E+00', 9699.99, '009.7E+03');+ t.format('000.0E+00', 10000, '010.0E+03');+ t.format('000.0E+00', 90000, '090.0E+03');+ t.format('000.0E+00', 94999.9, '095.0E+03');+ t.format('000.0E+00', 95999.9, '096.0E+03');+ t.format('000.0E+00', 96999.9, '097.0E+03');+ t.format('000.0E+00', 100000, '100.0E+03');+ t.format('000.00E+00', 9, '009.00E+00');+ t.format('000.00E+00', 9.49999, '009.50E+00');+ t.format('000.00E+00', 9.59999, '009.60E+00');+ t.format('000.00E+00', 9.69999, '009.70E+00');+ t.format('000.00E+00', 10, '010.00E+00');+ t.format('000.00E+00', 90, '090.00E+00');+ t.format('000.00E+00', 94.9999, '095.00E+00');+ t.format('000.00E+00', 95.9999, '096.00E+00');+ t.format('000.00E+00', 96.9999, '097.00E+00');+ t.format('000.00E+00', 100, '100.00E+00');+ t.format('000.00E+00', 900, '900.00E+00');+ t.format('000.00E+00', 949.999, '950.00E+00');+ t.format('000.00E+00', 959.999, '960.00E+00');+ t.format('000.00E+00', 969.999, '970.00E+00');+ t.format('000.00E+00', 1000, '001.00E+03');+ t.format('000.00E+00', 9000, '009.00E+03');+ t.format('000.00E+00', 9499.99, '009.50E+03');+ t.format('000.00E+00', 9599.99, '009.60E+03');+ t.format('000.00E+00', 9699.99, '009.70E+03');+ t.format('000.00E+00', 10000, '010.00E+03');+ t.format('000.00E+00', 90000, '090.00E+03');+ t.format('000.00E+00', 94999.9, '095.00E+03');+ t.format('000.00E+00', 95999.9, '096.00E+03');+ t.format('000.00E+00', 96999.9, '097.00E+03');+ t.format('000.00E+00', 100000, '100.00E+03');+});++numfmtTest('Exponential 0E+00', (t) => {+ t.format('0E+00', 1000000000000, '1E+12');+ t.format('0E+00', 999999999999, '1E+12');+ t.format('0E+00', 950000000000, '1E+12');+ t.format('0E+00', 100000000000, '1E+11');+ t.format('0E+00', 95000000000, '1E+11');+ t.format('0E+00', 10000000000, '1E+10');+ t.format('0E+00', 9500000000, '1E+10');+ t.format('0E+00', 1000000000, '1E+09');+ t.format('0E+00', 950000000, '1E+09');+ t.format('0E+00', 100000000, '1E+08');+ t.format('0E+00', 95000000, '1E+08');+ t.format('0E+00', 10000000, '1E+07');+ t.format('0E+00', 9500000, '1E+07');+ t.format('0E+00', 1000000, '1E+06');+ t.format('0E+00', 950000, '1E+06');+ t.format('0E+00', 100000, '1E+05');+ t.format('0E+00', 95000, '1E+05');+ t.format('0E+00', 10000, '1E+04');+ t.format('0E+00', 9500, '1E+04');+ t.format('0E+00', 1000, '1E+03');+ t.format('0E+00', 950, '1E+03');+ t.format('0E+00', 100, '1E+02');+ t.format('0E+00', 95, '1E+02');+ t.format('0E+00', 10, '1E+01');+ t.format('0E+00', 9.5, '1E+01');+ t.format('0E+00', 1.4999999, '1E+00');+ t.format('0E+00', 1, '1E+00');+ t.format('0E+00', 0.95, '1E+00');+ t.format('0E+00', 0.14999999, '1E-01');+ t.format('0E+00', 0.1, '1E-01');+ t.format('0E+00', 0.014999999, '1E-02');+ t.format('0E+00', 0.01, '1E-02');+ t.format('0E+00', 0.0014999999, '1E-03');+ t.format('0E+00', 0.001, '1E-03');+ t.format('0E+00', 0.00014999999, '1E-04');+ t.format('0E+00', 0.0001, '1E-04');+ t.format('0E+00', 0.000014999999, '1E-05');+ t.format('0E+00', 0.00001, '1E-05');+ t.format('0E+00', 0.00000149999999, '1E-06');+ t.format('0E+00', 0.000001, '1E-06');+ t.format('0E+00', 0.00000014999999, '1E-07');+ t.format('0E+00', 0.0000001, '1E-07');+ t.format('0E+00', 0.000000014999999, '1E-08');+ t.format('0E+00', 0.00000001, '1E-08');+ t.format('0E+00', 0.0000000014999999, '1E-09');+ t.format('0E+00', 0.000000001, '1E-09');+ t.format('0E+00', 0.00000000014999999, '1E-10');+ t.format('0E+00', 0.0000000001, '1E-10');+ t.format('0E+00', 0.000000000014999999, '1E-11');+ t.format('0E+00', 0.00000000001, '1E-11');+ t.format('0E+00', 0.0000000000014999999, '1E-12');+ t.format('0E+00', 0.000000000001, '1E-12');+});++numfmtTest('Exponential 0.00E+00', (t) => {+ t.format('0.00E+00', 10000000, '1.00E+07');+ t.format('0.00E+00', 20000000, '2.00E+07');+ t.format('0.00E+00', 30000000, '3.00E+07');+ t.format('0.00E+00', 30010000, '3.00E+07');+ t.format('0.00E+00', 30100000, '3.01E+07');+ t.format('0.00E+00', 31000000, '3.10E+07');+ t.format('0.00E+00', 31680000, '3.17E+07');+ t.format('0.00E+00', 31700000, '3.17E+07');+ t.format('0.00E+00', 32500000, '3.25E+07');+ t.format('0.00E+00', 35000000, '3.50E+07');+ t.format('0.00E+00', 40000000, '4.00E+07');+ t.format('0.00E+00', 50000000, '5.00E+07');+ t.format('0.00E+00', 60000000, '6.00E+07');+ t.format('0.00E+00', 70000000, '7.00E+07');+ t.format('0.00E+00', 80000000, '8.00E+07');+ t.format('0.00E+00', 90000000, '9.00E+07');+});++numfmtTest('Sign is grouped with digit in output', (t) => {+ t.format('0 E+ 0', 10000000, '1 E +7');+ t.format('0 E+ 00', 10000000, '1 E +07');+ t.format('0 E- 0', 10000000, '1 E 7');+ t.format('0 E- 0', 0.0000001, '1 E -7');+ t.format('0 E- 00', 0.0000001, '1 E -07');+});++numfmtTest('Exponent is shifted when integer part is omitted:', (t) => {+ t.format('.0E+0', 0, '.0E+0');+ t.format('.0E+0', 1, '.1E+1');+ t.format('.0E+0', 10, '.1E+2');+ t.format('.0E+0', 100, '.1E+3');+ t.format('.0E+0', 1000, '.1E+4');+ t.format('.0E+0', 10000, '.1E+5');+ t.format('.0E+0', 100000, '.1E+6');+ t.format('.0E+0', 123456789, '.1E+9');+ t.format('.0E+0', 0.1, '.1E+0');+ t.format('.0E+0', 0.01, '.1E-1');+ t.format('.0E+0', 0.001, '.1E-2');+ t.format('.0E+0', 0.0001, '.1E-3');+ t.format('.0E+0', 0.12345, '.1E+0');+ t.format('.0E+0', 0.012345, '.1E-1');+});diff --git a/packages/core/src/shared/numfmt/__tests__/fixtures/cal-updated.tsv.gz b/packages/core/src/shared/numfmt/__tests__/fixtures/cal-updated.tsv.gznew file mode 100644index 0000000000..e14eeef106Binary files /dev/null and b/packages/core/src/shared/numfmt/__tests__/fixtures/cal-updated.tsv.gz differdiff --git a/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-dates.tsv.gz b/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-dates.tsv.gznew file mode 100644index 0000000000..1601019963Binary files /dev/null and b/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-dates.tsv.gz differdiff --git a/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-times-full.tsv.gz b/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-times-full.tsv.gznew file mode 100644index 0000000000..b2e0e231feBinary files /dev/null and b/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-times-full.tsv.gz differdiff --git a/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-times.tsv.gz b/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-times.tsv.gznew file mode 100644index 0000000000..775e6300d3Binary files /dev/null and b/packages/core/src/shared/numfmt/__tests__/fixtures/ssf-times.tsv.gz differdiff --git a/packages/core/src/shared/numfmt/__tests__/format-api.spec.ts b/packages/core/src/shared/numfmt/__tests__/format-api.spec.tsnew file mode 100644index 0000000000..7cc8fe5623--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/format-api.spec.ts@@ -0,0 +1,71 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { describe, expect, it } from 'vitest';+import * as numfmt from '../api';++describe('local numfmt API', () => {+ it('exposes only the planned runtime surface', () => {+ expect(Object.keys(numfmt).sort()).toEqual([+ 'addLocale',+ 'dateFromSerial',+ 'dateToSerial',+ 'dec2frac',+ 'format',+ 'formatColor',+ 'getFormatDateInfo',+ 'getFormatInfo',+ 'getLocale',+ 'isDateFormat',+ 'isPercentFormat',+ 'isTextFormat',+ 'isValidFormat',+ 'parseBool',+ 'parseDate',+ 'parseLocale',+ 'parseNumber',+ 'parseTime',+ 'parseValue',+ 'round',+ 'tokenTypes',+ 'tokenize',+ ]);+ });++ it.each([+ ['#,##0.00', 1234.567, '1,234.57'],+ ['0.0%', 0.0294, '2.9%'],+ ['0.00E+00', 12.34, '1.23E+01'],+ ['yyyy-mm-dd', 3290, '1909-01-02'],+ ['# ?/?', 1.25, '1 1/4'],+ ['@', 'hello', 'hello'],+ ])('formats %s', (pattern, value, expected) => {+ expect(numfmt.format(pattern, value)).toBe(expected);+ });++ it('exposes color and metadata helpers', () => {+ expect(numfmt.formatColor('[Green]0;[Red]-0', -1)).toBe('red');+ expect(numfmt.isDateFormat('yyyy-mm-dd')).toBe(true);+ expect(numfmt.isPercentFormat('0%')).toBe(true);+ expect(numfmt.isTextFormat('@')).toBe(true);+ expect(numfmt.isValidFormat('0.00')).toBe(true);+ });+});diff --git a/packages/core/src/shared/numfmt/__tests__/foundations.spec.ts b/packages/core/src/shared/numfmt/__tests__/foundations.spec.tsnew file mode 100644index 0000000000..b1d5c1dc12--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/foundations.spec.ts@@ -0,0 +1,57 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { describe, expect, it } from 'vitest';+import { dec2frac } from '../dec-to-frac';+import { numDec } from '../num-dec';+import { round } from '../round';++describe('numfmt numeric foundations', () => {+ it('preserves the 3.2.6 rounding behavior during migration', () => {+ expect(round(1.4)).toBe(1);+ expect(round(1.5)).toBe(2);+ expect(round(-1.5)).toBe(-2);+ expect(round(1499, -2)).toBe(1500);+ });++ it('converts decimal fractions', () => {+ expect(dec2frac(1 / 3)).toEqual([1, 3]);+ expect(dec2frac(-0.25)).toEqual([-1, 4]);+ });++ it('reports the same digit metadata as upstream', () => {+ expect(numDec(0)).toEqual({+ total: 1,+ sign: 0,+ period: 0,+ int: 1,+ frac: 0,+ });+ expect(numDec(-12.34)).toEqual({+ total: 6,+ digits: 4,+ sign: 1,+ period: 1,+ int: 2,+ frac: 2,+ });+ });+});diff --git a/packages/core/src/shared/numfmt/__tests__/fragmented-numbers.spec.ts b/packages/core/src/shared/numfmt/__tests__/fragmented-numbers.spec.tsnew file mode 100644index 0000000000..87f95b9358--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/fragmented-numbers.spec.ts@@ -0,0 +1,48 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++numfmtTest('Fragmented number parts', (t) => {+ // exps with fragments+ t.format('0.00E+0x0', 123456789, '1.23E+0x8');+ t.format('0.00E+0x0', 123456789, '1.23E+0x8');+ t.format('0.00E+?x?', 123456789, '1.23E+ x8');+ t.format('0.00E+#x#', 123456789, '1.23E+x8');+ t.format('0.0x0E+0', 123456789, '1.2x3E+8');+ t.format('0x0.00E+0', 123456789, '0x1.23E+8');+ t.format('0x0.0x0E+0x0', 1, '0x1.0x0E+0x0');+ t.format('#x#.#x#E+#x#', 1, 'x1.xE+x0');+ t.format('?x?.?x?E+?x?', 1, ' x1. x E+ x0');++ t.format('00 00/00', 1, '01 00/01');+ t.format('00x00/00', 12345.67, '12345x65/97');+ t.format('0z0 00/00', 12345.67, '1234z5 65/97');+ t.format('00 0z0/00', 12345.67, '1234 5z65/97');+ t.format('00 00/0z0', 12345.67, '12345 02/3z0');+ t.format('00 0/0', 12345.67, '12345 2/3');+ t.format('00 ??/?z?', 12345.67, '12345 2/3z ');++ t.format('000E+00', 12345.67, '012E+03');+ t.format('00x0E+00', 12345.67, '01x2E+03');+ t.format('000E+0x0', 12345.67, '012E+0x3');+ t.format('0.0E+0x00', 1234567890000, '1.2E+0x12');+});diff --git a/packages/core/src/shared/numfmt/__tests__/info.spec.ts b/packages/core/src/shared/numfmt/__tests__/info.spec.tsnew file mode 100644index 0000000000..0dd7eee36c--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/info.spec.ts@@ -0,0 +1,438 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { getFormatInfo } from '../api';+import { numfmtTest } from './test-utils';++numfmtTest('numfmt.info', (t) => {+ const i1 = { ...getFormatInfo('0') };+ t.equal(typeof i1, 'object', 'getFormatInfo emits object');+ t.deepEqual(i1, {+ type: 'number',+ isDate: false,+ isText: false,+ isPercent: false,+ maxDecimals: 0,+ color: 0,+ scale: 1,+ parentheses: 0,+ grouped: 0,+ code: 'F0',+ level: 4,+ }, 'numfmt.info object is what we expect');++ const i2 = { ...getFormatInfo('0') };+ t.equal(typeof i2, 'object', 'formatters have info objects');+ t.deepEqual(i2, {+ type: 'number',+ isDate: false,+ isText: false,+ isPercent: false,+ maxDecimals: 0,+ scale: 1,+ color: 0,+ parentheses: 0,+ grouped: 0,+ code: 'F0',+ level: 4,+ }, 'formatters info is what we expect');++ const borked = { ...getFormatInfo('y 0') };+ t.deepEqual(borked, {+ type: 'error',+ isDate: false,+ isText: false,+ isPercent: false,+ maxDecimals: 0,+ scale: 1,+ color: 0,+ parentheses: 0,+ grouped: 0,+ code: 'G',+ level: 0,+ }, 'info makes sense even when pattern is bogus');+});++numfmtTest('General', (t) => {+ t.assertInfo('General', {+ type: 'general',+ maxDecimals: 9,+ code: 'G',+ });+ t.assertInfo('General;-General', {+ type: 'general',+ maxDecimals: 9,+ code: 'G',+ });+ t.assertInfo('(General);[blue](-General);0;@', {+ type: 'general',+ maxDecimals: 9,+ code: 'G-()',+ color: 1,+ parentheses: 1,+ });+});++numfmtTest('Numbers', (t) => {+ t.assertInfo('0', {+ type: 'number',+ maxDecimals: 0,+ code: 'F0',+ level: 4,+ });+ t.assertInfo('0.0', {+ type: 'number',+ maxDecimals: 1,+ code: 'F1',+ level: 4,+ });+ t.assertInfo('0.000', {+ type: 'number',+ maxDecimals: 3,+ code: 'F3',+ level: 4,+ });+ t.assertInfo('0.000000000000000', {+ type: 'number',+ maxDecimals: 15,+ code: 'F15',+ level: 4,+ });+ t.assertInfo('0.0000000000000000', {+ type: 'number',+ maxDecimals: 16,+ code: 'F15',+ level: 4,+ });++ t.assertInfo('#,##0', {+ type: 'grouped',+ maxDecimals: 0,+ code: ',0',+ grouped: 1,+ level: 10.2,+ });+ t.assertInfo('#,##0.00', {+ type: 'grouped',+ maxDecimals: 2,+ code: ',2',+ grouped: 1,+ level: 10.2,+ });+ t.assertInfo('(#,##0.00)', {+ type: 'grouped',+ maxDecimals: 2,+ code: ',2()',+ parentheses: 1,+ grouped: 1,+ level: 10.2,+ });++ t.assertInfo('0.00,"K"', {+ type: 'number',+ maxDecimals: 2,+ code: 'F2',+ scale: 0.001,+ level: 4,+ });+ t.assertInfo('0.00,,"K"', {+ type: 'number',+ maxDecimals: 2,+ code: 'F2',+ scale: 0.000001,+ level: 4,+ });+});++numfmtTest('Parentheses', (t) => {+ t.assertInfo('(0)', {+ type: 'number',+ parentheses: 1,+ code: 'F0()',+ level: 4,+ });+ t.assertInfo('0;(0)', {+ type: 'number',+ code: 'F0',+ level: 4,+ });+ t.assertInfo('0;0;(0)', {+ type: 'number',+ code: 'F0',+ level: 4,+ });+ t.assertInfo('(General)', {+ type: 'general',+ parentheses: 1,+ code: 'G()',+ maxDecimals: 9,+ });+ t.assertInfo('(0', {+ type: 'number',+ parentheses: 1,+ code: 'F0()',+ level: 4,+ });+ t.assertInfo('0)', {+ type: 'number',+ code: 'F0',+ level: 4,+ });+});++numfmtTest('Fractions', (t) => {+ t.assertInfo('# ?/?', {+ type: 'fraction',+ maxDecimals: 0,+ code: 'G',+ level: 2,+ });+ t.assertInfo('0 ??/??', {+ type: 'fraction',+ maxDecimals: 0,+ code: 'G',+ level: 2,+ });+});++numfmtTest('Text', (t) => {+ t.assertInfo('@', {+ type: 'text',+ isText: true,+ code: 'G',+ level: 15,+ });+ t.assertInfo('(@)', {+ type: 'text',+ isText: true,+ code: 'G',+ level: 15,+ });+});++numfmtTest('Text', (t) => {+ t.assertInfo('@', {+ type: 'text',+ isText: true,+ code: 'G',+ level: 15,+ });+ t.assertInfo('(@)', {+ type: 'text',+ isText: true,+ code: 'G',+ level: 15,+ });+});++numfmtTest('Currency', (t) => {+ t.assertInfo('$#,##0;($#,##0)', {+ type: 'currency',+ code: 'C0',+ grouped: 1,+ level: 10.4,+ });+ t.assertInfo('#,##0.00 €', {+ type: 'currency',+ code: 'C2',+ maxDecimals: 2,+ grouped: 1,+ level: 10.4,+ });+ t.assertInfo('₿ 0.0000', {+ type: 'currency',+ code: 'C4',+ maxDecimals: 4,+ level: 10.4,+ });++ // can pass in own currency+ const testCurrency = (str: string, identifier: string, code: string) => {+ const info = getFormatInfo(str, { currency: identifier });+ t.equal(info.code, code, str);+ };+ // Excel doesn't really have a great solution to this:+ // It just contorts the string to ensure that the current+ // currency identifier is a separate token when parsed.+ testCurrency('#,##0.00 "ISK"', 'ISK', 'C2');+ testCurrency('#,##0\\ "fiskur"', 'ISK', ',0');+ testCurrency('#,##0\\ "fISKur"', 'ISK', ',0');+ testCurrency('#,##0\\ "f ISK ur"', 'ISK', ',0');+ testCurrency('#,##0\\ \\f"ISK"\\u\\r', 'ISK', 'C0');+ testCurrency('#,##0\\ "ISK"', 'ISK', 'C0');+ testCurrency('#,##0\\a"ISK"\\a', 'ISK', 'C0');+ testCurrency('#,##0"aISKa"', 'ISK', ',0');+});++numfmtTest('Percentages', (t) => {+ t.assertInfo('0%', {+ type: 'percent',+ isPercent: true,+ scale: 100,+ code: 'P0',+ level: 10.6,+ });+ t.assertInfo('0.00%;[red]0.00%', {+ type: 'percent',+ isPercent: true,+ scale: 100,+ code: 'P2-',+ color: 1,+ maxDecimals: 2,+ level: 10.6,+ });+});++numfmtTest('Scientific', (t) => {+ t.assertInfo('0E+0', {+ type: 'scientific',+ code: 'S0',+ level: 6,+ });+ t.assertInfo('0.00E+00', {+ type: 'scientific',+ code: 'S2',+ maxDecimals: 2,+ level: 6,+ });+ t.assertInfo('0.0E+0;[red]0.0E+0', {+ type: 'scientific',+ code: 'S1-',+ color: 1,+ maxDecimals: 1,+ level: 6,+ });+});++numfmtTest('Dates', (t) => {+ const dt = { type: 'date', isDate: true, level: 10.8 } as const;+ const tm = { type: 'time', isDate: true, level: 10.8 } as const;+ // D1+ t.assertInfo('dd-mmm-yyyy h:mm:ss A/P', { ...dt, code: 'D1', type: 'datetime' });+ t.assertInfo('dd-mmm-yyyy h:mm:ss', { ...dt, code: 'D1', type: 'datetime' });+ t.assertInfo('dd-mmm-yyyy', { ...dt, code: 'D1' });+ t.assertInfo('d-mmm-yyyy', { ...dt, code: 'D1' });+ t.assertInfo('d-mm-yyyy', { ...dt, code: 'D1' });+ t.assertInfo('d-m-yyyy', { ...dt, code: 'D1' });+ t.assertInfo('d-m-yy', { ...dt, code: 'D1' });+ t.assertInfo('d-m-b', { ...dt, code: 'D1' });+ // D2+ t.assertInfo('dd-mmmm h:mm A/P', { ...dt, code: 'D2', type: 'datetime' });+ t.assertInfo('dd-mmm h:mm:ss', { ...dt, code: 'D2', type: 'datetime' });+ t.assertInfo('dd-mmm', { ...dt, code: 'D2' });+ t.assertInfo('d-mmm', { ...dt, code: 'D2' });+ t.assertInfo('d-mm', { ...dt, code: 'D2' });+ t.assertInfo('d-m', { ...dt, code: 'D2' });+ t.assertInfo('d-m-m', { ...dt, code: 'D2' });+ t.assertInfo('d-m-d', { ...dt, code: 'D2' });+ // D3+ t.assertInfo('mmmm-yyyy h:mm A/P', { ...dt, code: 'D3', type: 'datetime' });+ t.assertInfo('mmmm-yyyy', { ...dt, code: 'D3' });+ t.assertInfo('m-y', { ...dt, code: 'D3' });+ t.assertInfo('m-y-m', { ...dt, code: 'D3' });+ t.assertInfo('m-y-d', { ...dt, code: 'D3' });+ t.assertInfo('m-b', { ...dt, code: 'D3' });+ // D4 (same as D1 but month first)+ t.assertInfo('mmm-dd-yyyy h:mm:ss A/P', { ...dt, code: 'D4', type: 'datetime' });+ t.assertInfo('mmm-dd-yyyy h:mm:ss', { ...dt, code: 'D4', type: 'datetime' });+ t.assertInfo('mmm-dd-yyyy', { ...dt, code: 'D4' });+ t.assertInfo('mmm-d-yyyy', { ...dt, code: 'D4' });+ t.assertInfo('mm-d-yyyy', { ...dt, code: 'D4' });+ t.assertInfo('m-d-yyyy', { ...dt, code: 'D4' });+ t.assertInfo('m-d-yy', { ...dt, code: 'D4' });+ t.assertInfo('m-d-y-m', { ...dt, code: 'D4' });+ t.assertInfo('m-d-b', { ...dt, code: 'D4' });+ // D5 (same as D2 but month first)+ t.assertInfo('mmmm-dd h:mm A/P', { ...dt, code: 'D5', type: 'datetime' });+ t.assertInfo('mmm-dd h:mm:ss', { ...dt, code: 'D5', type: 'datetime' });+ t.assertInfo('mmm-dd', { ...dt, code: 'D5' });+ t.assertInfo('mmm-d', { ...dt, code: 'D5' });+ t.assertInfo('mm-d', { ...dt, code: 'D5' });+ t.assertInfo('m-d', { ...dt, code: 'D5' });+ t.assertInfo('m-d-d', { ...dt, code: 'D5' });+ t.assertInfo('m-d-m', { ...dt, code: 'D5' });+ t.assertInfo('m-d-d-y', { ...dt, code: 'D5' });+ // D6+ t.assertInfo('h:mm:ss AM/PM', { ...tm, code: 'D6' });+ t.assertInfo('h:mm:ss "foo" AM/PM', { ...tm, code: 'D6' });+ t.assertInfo('h:m:s A/P', { ...tm, code: 'D6' });+ // D7+ t.assertInfo('h:mm AM/PM', { ...tm, code: 'D7' });+ t.assertInfo('h:mm "foo" AM/PM', { ...tm, code: 'D7' });+ t.assertInfo('h:m A/P', { ...tm, code: 'D7' });+ // D8+ t.assertInfo('h:mm:ss', { ...tm, code: 'D8' });+ t.assertInfo('"foo" h:mm:ss "bar"', { ...tm, code: 'D8' });+ t.assertInfo('h:m:s', { ...tm, code: 'D8' });+ // D9+ t.assertInfo('h:mm', { ...tm, code: 'D9' });+ t.assertInfo('"foo" h:mm "bar"', { ...tm, code: 'D9' });+ t.assertInfo('h:m', { ...tm, code: 'D9' });+ // Non coded dates+ t.assertInfo('yyyy', { ...dt, code: 'G' });+ t.assertInfo('yyyy-mm-dd', { ...dt, code: 'G' });+ t.assertInfo('yyyy-mm-dd"T"hh:mm:ss', { ...dt, code: 'G', type: 'datetime' });+ t.assertInfo('dddd h:mm:ss', { ...dt, code: 'G', type: 'datetime' });+});++numfmtTest('dateInfo', (t) => {+ // numfmt.getDateInfo returns "all off" for non dates+ t.assertDateInfo('0', {});++ // dateInfo makes sense even when pattern is bogus+ t.assertDateInfo('y 0', {});++ t.assertDateInfo('yyyy', { year: true });+ t.assertDateInfo('yyy', { year: true });+ t.assertDateInfo('yy', { year: true });+ t.assertDateInfo('y', { year: true });+ t.assertDateInfo('mmmm', { month: true });+ t.assertDateInfo('mmm', { month: true });+ t.assertDateInfo('mm', { month: true });+ t.assertDateInfo('m', { month: true });+ t.assertDateInfo('dddd', { day: true });+ t.assertDateInfo('ddd', { day: true });+ t.assertDateInfo('dd', { day: true });+ t.assertDateInfo('d', { day: true });+ t.assertDateInfo('hh', { hours: true });+ t.assertDateInfo('h', { hours: true });+ t.assertDateInfo('h:mm', { hours: true, minutes: true });+ t.assertDateInfo('h:m', { hours: true, minutes: true });+ t.assertDateInfo('ss', { seconds: true });+ t.assertDateInfo('s', { seconds: true });+ t.assertDateInfo('hh am/pm', { hours: true, clockType: 12 });+ t.assertDateInfo('hh A/P', { hours: true, clockType: 12 });++ t.assertDateInfo('yyyy-mm', { year: true, month: true });+ t.assertDateInfo('yyyy-mm-dd', { year: true, month: true, day: true });+ t.assertDateInfo('yyyy-mm-ddThh', { year: true, month: true, day: true, hours: true });+ t.assertDateInfo('yyyy-mm-ddThh:mm', { year: true, month: true, day: true, hours: true, minutes: true });+ t.assertDateInfo('yyyy-mm-ddThh:mm:ss', { year: true, month: true, day: true, hours: true, minutes: true, seconds: true });+ t.assertDateInfo('yyyy-mm-ddThh:mm:ss AM/PM', { year: true, month: true, day: true, hours: true, minutes: true, seconds: true, clockType: 12 });++ t.assertDateInfo('yy dd mm:ss', { year: true, day: true, month: true, seconds: true });++ t.assertDateInfo('dd', { year: false, month: false, day: true });++ t.assertDateInfo('yyyy-mm-dd', { year: true, month: true, day: true });+ t.assertDateInfo('dd-mm-yyyy', { year: true, month: true, day: true });+ t.assertDateInfo('dd yyyy', { year: true, day: true });+});diff --git a/packages/core/src/shared/numfmt/__tests__/leap-1900.spec.ts b/packages/core/src/shared/numfmt/__tests__/leap-1900.spec.tsnew file mode 100644index 0000000000..359f0146f9--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/leap-1900.spec.ts@@ -0,0 +1,154 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++const ISODATE = 'yyyy-mm-dd';++numfmtTest('Excel leap 1900 bug: ON', (t) => {+ t.format(ISODATE, 61, '1900-03-01', { leap1900: true });+ t.format(ISODATE, 60, '1900-02-29', { leap1900: true });+ t.format(ISODATE, 59, '1900-02-28', { leap1900: true });+ t.format(ISODATE, 58, '1900-02-27', { leap1900: true });+ t.format(ISODATE, 57, '1900-02-26', { leap1900: true });+ t.format(ISODATE, 56, '1900-02-25', { leap1900: true });+ t.format(ISODATE, 55, '1900-02-24', { leap1900: true });+ t.format(ISODATE, 54, '1900-02-23', { leap1900: true });+ t.format(ISODATE, 53, '1900-02-22', { leap1900: true });+ t.format(ISODATE, 52, '1900-02-21', { leap1900: true });+ t.format(ISODATE, 51, '1900-02-20', { leap1900: true });+ t.format(ISODATE, 50, '1900-02-19', { leap1900: true });+ t.format(ISODATE, 49, '1900-02-18', { leap1900: true });+ t.format(ISODATE, 48, '1900-02-17', { leap1900: true });+ t.format(ISODATE, 47, '1900-02-16', { leap1900: true });+ t.format(ISODATE, 46, '1900-02-15', { leap1900: true });+ t.format(ISODATE, 45, '1900-02-14', { leap1900: true });+ t.format(ISODATE, 44, '1900-02-13', { leap1900: true });+ t.format(ISODATE, 43, '1900-02-12', { leap1900: true });+ t.format(ISODATE, 42, '1900-02-11', { leap1900: true });+ t.format(ISODATE, 41, '1900-02-10', { leap1900: true });+ t.format(ISODATE, 40, '1900-02-09', { leap1900: true });+ t.format(ISODATE, 39, '1900-02-08', { leap1900: true });+ t.format(ISODATE, 38, '1900-02-07', { leap1900: true });+ t.format(ISODATE, 37, '1900-02-06', { leap1900: true });+ t.format(ISODATE, 36, '1900-02-05', { leap1900: true });+ t.format(ISODATE, 35, '1900-02-04', { leap1900: true });+ t.format(ISODATE, 34, '1900-02-03', { leap1900: true });+ t.format(ISODATE, 33, '1900-02-02', { leap1900: true });+ t.format(ISODATE, 32, '1900-02-01', { leap1900: true });+ t.format(ISODATE, 31, '1900-01-31', { leap1900: true });+ t.format(ISODATE, 30, '1900-01-30', { leap1900: true });+ t.format(ISODATE, 29, '1900-01-29', { leap1900: true });+ t.format(ISODATE, 28, '1900-01-28', { leap1900: true });+ t.format(ISODATE, 27, '1900-01-27', { leap1900: true });+ t.format(ISODATE, 26, '1900-01-26', { leap1900: true });+ t.format(ISODATE, 25, '1900-01-25', { leap1900: true });+ t.format(ISODATE, 24, '1900-01-24', { leap1900: true });+ t.format(ISODATE, 23, '1900-01-23', { leap1900: true });+ t.format(ISODATE, 22, '1900-01-22', { leap1900: true });+ t.format(ISODATE, 21, '1900-01-21', { leap1900: true });+ t.format(ISODATE, 20, '1900-01-20', { leap1900: true });+ t.format(ISODATE, 19, '1900-01-19', { leap1900: true });+ t.format(ISODATE, 18, '1900-01-18', { leap1900: true });+ t.format(ISODATE, 17, '1900-01-17', { leap1900: true });+ t.format(ISODATE, 16, '1900-01-16', { leap1900: true });+ t.format(ISODATE, 15, '1900-01-15', { leap1900: true });+ t.format(ISODATE, 14, '1900-01-14', { leap1900: true });+ t.format(ISODATE, 13, '1900-01-13', { leap1900: true });+ t.format(ISODATE, 12, '1900-01-12', { leap1900: true });+ t.format(ISODATE, 11, '1900-01-11', { leap1900: true });+ t.format(ISODATE, 10, '1900-01-10', { leap1900: true });+ t.format(ISODATE, 9, '1900-01-09', { leap1900: true });+ t.format(ISODATE, 8, '1900-01-08', { leap1900: true });+ t.format(ISODATE, 7, '1900-01-07', { leap1900: true });+ t.format(ISODATE, 6, '1900-01-06', { leap1900: true });+ t.format(ISODATE, 5, '1900-01-05', { leap1900: true });+ t.format(ISODATE, 4, '1900-01-04', { leap1900: true });+ t.format(ISODATE, 3, '1900-01-03', { leap1900: true });+ t.format(ISODATE, 2, '1900-01-02', { leap1900: true });+ t.format(ISODATE, 1, '1900-01-01', { leap1900: true });+ t.format(ISODATE, 0, '1900-01-00', { leap1900: true });+});++numfmtTest('Excel 1900 bug: OFF', (t) => {+ t.format(ISODATE, 61, '1900-03-01', { leap1900: false });+ t.format(ISODATE, 60, '1900-02-28', { leap1900: false });+ t.format(ISODATE, 59, '1900-02-27', { leap1900: false });+ t.format(ISODATE, 58, '1900-02-26', { leap1900: false });+ t.format(ISODATE, 57, '1900-02-25', { leap1900: false });+ t.format(ISODATE, 56, '1900-02-24', { leap1900: false });+ t.format(ISODATE, 55, '1900-02-23', { leap1900: false });+ t.format(ISODATE, 54, '1900-02-22', { leap1900: false });+ t.format(ISODATE, 53, '1900-02-21', { leap1900: false });+ t.format(ISODATE, 52, '1900-02-20', { leap1900: false });+ t.format(ISODATE, 51, '1900-02-19', { leap1900: false });+ t.format(ISODATE, 50, '1900-02-18', { leap1900: false });+ t.format(ISODATE, 49, '1900-02-17', { leap1900: false });+ t.format(ISODATE, 48, '1900-02-16', { leap1900: false });+ t.format(ISODATE, 47, '1900-02-15', { leap1900: false });+ t.format(ISODATE, 46, '1900-02-14', { leap1900: false });+ t.format(ISODATE, 45, '1900-02-13', { leap1900: false });+ t.format(ISODATE, 44, '1900-02-12', { leap1900: false });+ t.format(ISODATE, 43, '1900-02-11', { leap1900: false });+ t.format(ISODATE, 42, '1900-02-10', { leap1900: false });+ t.format(ISODATE, 41, '1900-02-09', { leap1900: false });+ t.format(ISODATE, 40, '1900-02-08', { leap1900: false });+ t.format(ISODATE, 39, '1900-02-07', { leap1900: false });+ t.format(ISODATE, 38, '1900-02-06', { leap1900: false });+ t.format(ISODATE, 37, '1900-02-05', { leap1900: false });+ t.format(ISODATE, 36, '1900-02-04', { leap1900: false });+ t.format(ISODATE, 35, '1900-02-03', { leap1900: false });+ t.format(ISODATE, 34, '1900-02-02', { leap1900: false });+ t.format(ISODATE, 33, '1900-02-01', { leap1900: false });+ t.format(ISODATE, 32, '1900-01-31', { leap1900: false });+ t.format(ISODATE, 31, '1900-01-30', { leap1900: false });+ t.format(ISODATE, 30, '1900-01-29', { leap1900: false });+ t.format(ISODATE, 29, '1900-01-28', { leap1900: false });+ t.format(ISODATE, 28, '1900-01-27', { leap1900: false });+ t.format(ISODATE, 27, '1900-01-26', { leap1900: false });+ t.format(ISODATE, 26, '1900-01-25', { leap1900: false });+ t.format(ISODATE, 25, '1900-01-24', { leap1900: false });+ t.format(ISODATE, 24, '1900-01-23', { leap1900: false });+ t.format(ISODATE, 23, '1900-01-22', { leap1900: false });+ t.format(ISODATE, 22, '1900-01-21', { leap1900: false });+ t.format(ISODATE, 21, '1900-01-20', { leap1900: false });+ t.format(ISODATE, 20, '1900-01-19', { leap1900: false });+ t.format(ISODATE, 19, '1900-01-18', { leap1900: false });+ t.format(ISODATE, 18, '1900-01-17', { leap1900: false });+ t.format(ISODATE, 17, '1900-01-16', { leap1900: false });+ t.format(ISODATE, 16, '1900-01-15', { leap1900: false });+ t.format(ISODATE, 15, '1900-01-14', { leap1900: false });+ t.format(ISODATE, 14, '1900-01-13', { leap1900: false });+ t.format(ISODATE, 13, '1900-01-12', { leap1900: false });+ t.format(ISODATE, 12, '1900-01-11', { leap1900: false });+ t.format(ISODATE, 11, '1900-01-10', { leap1900: false });+ t.format(ISODATE, 10, '1900-01-09', { leap1900: false });+ t.format(ISODATE, 9, '1900-01-08', { leap1900: false });+ t.format(ISODATE, 8, '1900-01-07', { leap1900: false });+ t.format(ISODATE, 7, '1900-01-06', { leap1900: false });+ t.format(ISODATE, 6, '1900-01-05', { leap1900: false });+ t.format(ISODATE, 5, '1900-01-04', { leap1900: false });+ t.format(ISODATE, 4, '1900-01-03', { leap1900: false });+ t.format(ISODATE, 3, '1900-01-02', { leap1900: false });+ t.format(ISODATE, 2, '1900-01-01', { leap1900: false });+ t.format(ISODATE, 1, '1899-12-31', { leap1900: false });+ t.format(ISODATE, 0, '1899-12-30', { leap1900: false });+});diff --git a/packages/core/src/shared/numfmt/__tests__/locale-registry.spec.ts b/packages/core/src/shared/numfmt/__tests__/locale-registry.spec.tsnew file mode 100644index 0000000000..cf809fb0a0--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/locale-registry.spec.ts@@ -0,0 +1,53 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { describe, expect, it } from 'vitest';+import {+ addLocale,+ getLocale,+ listLocales,+ parseLocale,+ resolveLocale,+} from '../locale';++describe('numfmt locale registry', () => {+ it('parses BCP 47 tags and Excel LCIDs', () => {+ expect(parseLocale('zh-CN')).toEqual({+ lang: 'zh_CN',+ language: 'zh',+ territory: 'CN',+ });+ expect(resolveLocale(0x0409)).toBe('en_US');+ expect(resolveLocale('[$-409]')).toBeNull();+ });++ it('registers a partial locale over defaults', () => {+ const locale = addLocale({ decimal: '·', group: '~' }, 'xy');+ expect(locale.decimal).toBe('·');+ expect(locale.group).toBe('~');+ expect(getLocale('xy')).toBe(locale);+ expect(listLocales()).toContain('xy');+ });++ it('rejects malformed locale tags', () => {+ expect(() => parseLocale('not a locale!')).toThrow(SyntaxError);+ });+});diff --git a/packages/core/src/shared/numfmt/__tests__/locale.spec.ts b/packages/core/src/shared/numfmt/__tests__/locale.spec.tsnew file mode 100644index 0000000000..71bf161875--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/locale.spec.ts@@ -0,0 +1,134 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { addLocale } from '../api';+import { numfmtTest } from './test-utils';++const date = 3290.1278435; // 1909-01-02 03:04:05.678++numfmtTest('locale options', (t) => {+ // default locale+ t.format('dddd, dd. mmmm yyy', date, 'Saturday, 02. January 1909');++ // General is localized+ addLocale({+ decimal: '·',+ positive: 'ᐩ',+ negative: '÷',+ percent: '٪',+ exponent: 'X',+ }, 'xx');+ t.format('General', 123456700000000, '1·23457Xᐩ14', { locale: 'xx' });+ t.format('General', 10000000000, '10000000000', { locale: 'xx' });+ t.format('General', 0.000000001, '0·000000001', { locale: 'xx' });+ t.format('General', 1234.56, '1234·56', { locale: 'xx' });+ t.format('General', 0.1, '0·1', { locale: 'xx' });++ // general should respect locale in all cases+ t.format('General', 0.0001, '0,0001', { locale: 'de' });+ t.format('General', 10000000000, '10000000000', { locale: 'de' });+ t.format('General', 1.1, '1,1', { locale: 'de' });+ t.format('General', 1.1, '1,1', { locale: 'de' });+ t.format('General', 1000000000.1, '1000000000', { locale: 'de' });+ t.format('General', 1.1111111111, '1,111111111', { locale: 'de' });+ t.format('General', 1.1e-9, '1,1E-09', { locale: 'de' });+ t.format('General', 1.1e-10, '1,1E-10', { locale: 'de' });+ t.format('General', 1.1e-10, '1,1E-10', { locale: 'de' });++ // #59+ t.format('General', 111.1111111, '111,1111111', { locale: 'de' });+ t.format('General', 111.11111111, '111,1111111', { locale: 'de' });+ t.format('General', 111.111111111, '111,1111111', { locale: 'de' });++ // different locale address modes (both is-IS and is_IS are supported)+ t.format('[$-is]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-is_IS]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-is_IS]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-is_IS]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-is-IS]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-040F]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-01040F]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-00040F]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-0000040F]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('[$-0101040F]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909');+ t.format('dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909', { locale: 'is' });+ // setting a locale does not overwrite the format locale+ t.format('[$-040F]dddd, dd. mmmm yyy', date, 'laugardagur, 02. janúar 1909', { locale: 'fr' });++ // all types are present+ t.format('d dd ddd dddd ddddd', date, '2 02 lau. laugardagur laugardagur', { locale: 'is' });+ t.format('m mm mmm mmmm mmmmm', date, '1 01 jan. janúar j', { locale: 'is' });+ t.format('#,##0.000', date, '3.290,128', { locale: 'is' });+ t.format('h AM/PM', date, '3 f.h.', { locale: 'is' });++ t.format('d dd ddd dddd ddddd', date, '2 02 周六 星期六 星期六', { locale: 'zh-CH' });+ t.format('m mm mmm mmmm mmmmm', date, '1 01 1月 一月 一', { locale: 'zh-CH' });+ t.format('#,##0.000', date, '3,290.128', { locale: 'zh-CH' });+ t.format('h AM/PM', date, '3 上午', { locale: 'zh-CH' });++ t.format('d dd ddd dddd ddddd', date, '2 02 сб суббота суббота', { locale: 0x0419 as never });+ t.format('m mm mmm mmmm mmmmm', date, '1 01 янв. января я', { locale: 0x0419 as never });+ t.format('#,##0.000', date, '3\u00A0290,128', { locale: 0x0419 as never });+ t.format('h AM/PM', date, '3 AM', { locale: 0x0419 as never });++ // Currency+ t.format('[$$-409]#,##0', 1234, '$1,234');+ t.format('#,##0\\ [$kr-438]', 1234, '1,234 kr');+ t.format('[$ISK] #,##0', 1234, 'ISK 1,234');+ t.format('[$ISK-] #,##0', 1234, 'ISK 1,234');+ t.format('[$NZ$-481]#,##0', 1234, 'NZ$1,234');+ t.format('[$whatever is here just gets through] #,##0', 1234, 'whatever is here just gets through 1,234');++ // Hijri month names are emitted+ t.format('[$-060409]mmmm', 42999, 'Muharram');+ t.format('[$-060409]mmmm', 43029, 'Safar');+ t.format('[$-060409]mmmm', 43058, 'Rabiʻ I');+ t.format('[$-060409]mmmm', 43088, 'Rabiʻ II');+ t.format('[$-060409]mmmm', 43118, 'Jumada I');+ t.format('[$-060409]mmmm', 43148, 'Jumada II');+ t.format('[$-060409]mmmm', 43177, 'Rajab');+ t.format('[$-060409]mmmm', 43207, 'Shaʻban');+ t.format('[$-060409]mmmm', 43237, 'Ramadan');+ t.format('[$-060409]mmmm', 43266, 'Shawwal');+ t.format('[$-060409]mmmm', 43295, 'Dhuʻl-Qiʻdah');+ t.format('[$-060409]mmmm', 43324, 'Dhuʻl-Hijjah');++ t.format('[$Fr.-807] #,##0.00', 12345.67, 'Fr. 12\'345.67');++ // TODO: names for hijri months+ // Next test is known to be incorrect, Excel emits "1439 محرم 1"+ t.format('B2yyyy mmmm d', 42999, '1439 Muharram 1', 'B2yyyy mmmm d' as never);++ t.format('[$-060409]yyyy mmmm d', 42999, '1439 Muharram 1', '[$-060409]yyyy mmmm d' as never);+ t.format('[$-060C01]yyyy mmmm d', 42999, '1439 رمضان 1', '[$-060C01]yyyy mmmm d' as never);+ t.format('[$-010C01]yyyy mmmm d', 42999, '2017 سبتمبر 21', '[$-010C01]yyyy mmmm d' as never);++ t.format('[$-0409]B2yyyy mmmm d', 42999, '2017 September 21', '[$-0409]yyyy mmmm d' as never);++ t.format('General', true, 'TRUE', { locale: 'en' });+ t.format('General', false, 'FALSE', { locale: 'en' });+ t.format('General', true, 'VRAI', { locale: 'fr' });+ t.format('General', false, 'FAUX', { locale: 'fr' });+ t.format('General', true, 'TRUE', { locale: 'is' });+ t.format('General', false, 'FALSE', { locale: 'is' });+ t.format('General', true, 'WAAR', { locale: 'nl' });+ t.format('General', false, 'ONWAAR', { locale: 'nl' });+});diff --git a/packages/core/src/shared/numfmt/__tests__/num-dec.spec.ts b/packages/core/src/shared/numfmt/__tests__/num-dec.spec.tsnew file mode 100644index 0000000000..f9a5174ff0--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/num-dec.spec.ts@@ -0,0 +1,575 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numDec } from '../num-dec';+import { numfmtTest } from './test-utils';++/* eslint-disable no-loss-of-precision */+// tests converted from SSF++function _f(v: number): number {+ return numDec(v).total;+}++numfmtTest('numdec', (t) => {+ t.equal(_f(1.234567e-14), 22, '1.234567E-14');+ t.equal(_f(1.234567e-13), 21, '1.234567E-13');+ t.equal(_f(0.000000000001234567), 20, '0.000000000001234567');+ t.equal(_f(0.00000000001234567), 19, '0.00000000001234567');+ t.equal(_f(0.0000000001234567), 18, '0.0000000001234567');+ t.equal(_f(0.000000001234567), 17, '0.000000001234567');+ t.equal(_f(0.00000001234567), 16, '0.00000001234567');+ t.equal(_f(0.0000001234567), 15, '0.0000001234567');+ t.equal(_f(0.000001234567), 14, '0.000001234567');+ t.equal(_f(0.00001234567), 13, '0.00001234567');+ t.equal(_f(0.0001234567), 12, '0.0001234567');+ t.equal(_f(0.001234567), 11, '0.001234567');+ t.equal(_f(0.01234567), 10, '0.01234567');+ t.equal(_f(0.1234567), 9, '0.1234567');+ t.equal(_f(1.234567), 8, '1.234567');+ t.equal(_f(12.34567), 8, '12.34567');+ t.equal(_f(123.4567), 8, '123.4567');+ t.equal(_f(1234.567), 8, '1234.567');+ t.equal(_f(12345.67), 8, '12345.67');+ t.equal(_f(123456.7), 8, '123456.7');+ t.equal(_f(1234567), 7, '1234567');+ t.equal(_f(12345670), 8, '12345670');+ t.equal(_f(123456700), 9, '123456700');+ t.equal(_f(1234567000), 10, '1234567000');+ t.equal(_f(12345670000), 11, '12345670000');+ t.equal(_f(123456700000), 12, '123456700000');+ t.equal(_f(1234567000000), 13, '1234567000000');+ t.equal(_f(12345670000000), 14, '12345670000000');+ t.equal(_f(123456700000000), 15, '123456700000000');+ t.equal(_f(0.00000000000001), 16, '0.00000000000001');+ t.equal(_f(0.0000000000001), 15, '0.0000000000001');+ t.equal(_f(0.000000000001), 14, '0.000000000001');+ t.equal(_f(0.00000000001), 13, '0.00000000001');+ t.equal(_f(0.0000000001), 12, '0.0000000001');+ t.equal(_f(0.000000001), 11, '0.000000001');+ t.equal(_f(0.00000001), 10, '0.00000001');+ t.equal(_f(0.0000001), 9, '0.0000001');+ t.equal(_f(0.000001), 8, '0.000001');+ t.equal(_f(0.00001), 7, '0.00001');+ t.equal(_f(0.0001), 6, '0.0001');+ t.equal(_f(0.001), 5, '0.001');+ t.equal(_f(0.01), 4, '0.01');+ t.equal(_f(0.1), 3, '0.1');+ t.equal(_f(1), 1, '1');+ t.equal(_f(10), 2, '10');+ t.equal(_f(100), 3, '100');+ t.equal(_f(1000), 4, '1000');+ t.equal(_f(10000), 5, '10000');+ t.equal(_f(100000), 6, '100000');+ t.equal(_f(1000000), 7, '1000000');+ t.equal(_f(10000000), 8, '10000000');+ t.equal(_f(100000000), 9, '100000000');+ t.equal(_f(1000000000), 10, '1000000000');+ t.equal(_f(10000000000), 11, '10000000000');+ t.equal(_f(100000000000), 12, '100000000000');+ t.equal(_f(1000000000000), 13, '1000000000000');+ t.equal(_f(10000000000000), 14, '10000000000000');+ t.equal(_f(100000000000000), 15, '100000000000000');+ t.equal(_f(0.000000000000012), 17, '0.000000000000012');+ t.equal(_f(0.00000000000012), 16, '0.00000000000012');+ t.equal(_f(0.0000000000012), 15, '0.0000000000012');+ t.equal(_f(0.000000000012), 14, '0.000000000012');+ t.equal(_f(0.00000000012), 13, '0.00000000012');+ t.equal(_f(0.0000000012), 12, '0.0000000012');+ t.equal(_f(0.000000012), 11, '0.000000012');+ t.equal(_f(0.00000012), 10, '0.00000012');+ t.equal(_f(0.0000012), 9, '0.0000012');+ t.equal(_f(0.000012), 8, '0.000012');+ t.equal(_f(0.00012), 7, '0.00012');+ t.equal(_f(0.0012), 6, '0.0012');+ t.equal(_f(0.012), 5, '0.012');+ t.equal(_f(0.12), 4, '0.12');+ t.equal(_f(1.2), 3, '1.2');+ t.equal(_f(12), 2, '12');+ t.equal(_f(120), 3, '120');+ t.equal(_f(1200), 4, '1200');+ t.equal(_f(12000), 5, '12000');+ t.equal(_f(120000), 6, '120000');+ t.equal(_f(1200000), 7, '1200000');+ t.equal(_f(12000000), 8, '12000000');+ t.equal(_f(120000000), 9, '120000000');+ t.equal(_f(1200000000), 10, '1200000000');+ t.equal(_f(12000000000), 11, '12000000000');+ t.equal(_f(120000000000), 12, '120000000000');+ t.equal(_f(1200000000000), 13, '1200000000000');+ t.equal(_f(12000000000000), 14, '12000000000000');+ t.equal(_f(120000000000000), 15, '120000000000000');+ t.equal(_f(0.0000000000000123), 18, '0.0000000000000123');+ t.equal(_f(0.000000000000123), 17, '0.000000000000123');+ t.equal(_f(0.00000000000123), 16, '0.00000000000123');+ t.equal(_f(0.0000000000123), 15, '0.0000000000123');+ t.equal(_f(0.000000000123), 14, '0.000000000123');+ t.equal(_f(0.00000000123), 13, '0.00000000123');+ t.equal(_f(0.0000000123), 12, '0.0000000123');+ t.equal(_f(0.000000123), 11, '0.000000123');+ t.equal(_f(0.00000123), 10, '0.00000123');+ t.equal(_f(0.0000123), 9, '0.0000123');+ t.equal(_f(0.000123), 8, '0.000123');+ t.equal(_f(0.00123), 7, '0.00123');+ t.equal(_f(0.0123), 6, '0.0123');+ t.equal(_f(0.123), 5, '0.123');+ t.equal(_f(1.23), 4, '1.23');+ t.equal(_f(12.3), 4, '12.3');+ t.equal(_f(123), 3, '123');+ t.equal(_f(1230), 4, '1230');+ t.equal(_f(12300), 5, '12300');+ t.equal(_f(123000), 6, '123000');+ t.equal(_f(1230000), 7, '1230000');+ t.equal(_f(12300000), 8, '12300000');+ t.equal(_f(123000000), 9, '123000000');+ t.equal(_f(1230000000), 10, '1230000000');+ t.equal(_f(12300000000), 11, '12300000000');+ t.equal(_f(123000000000), 12, '123000000000');+ t.equal(_f(1230000000000), 13, '1230000000000');+ t.equal(_f(12300000000000), 14, '12300000000000');+ t.equal(_f(123000000000000), 15, '123000000000000');+ t.equal(_f(0.00000000000001234), 19, '0.00000000000001234');+ t.equal(_f(0.0000000000001234), 18, '0.0000000000001234');+ t.equal(_f(0.000000000001234), 17, '0.000000000001234');+ t.equal(_f(0.00000000001234), 16, '0.00000000001234');+ t.equal(_f(0.0000000001234), 15, '0.0000000001234');+ t.equal(_f(0.000000001234), 14, '0.000000001234');+ t.equal(_f(0.00000001234), 13, '0.00000001234');+ t.equal(_f(0.0000001234), 12, '0.0000001234');+ t.equal(_f(0.000001234), 11, '0.000001234');+ t.equal(_f(0.00001234), 10, '0.00001234');+ t.equal(_f(0.0001234), 9, '0.0001234');+ t.equal(_f(0.001234), 8, '0.001234');+ t.equal(_f(0.01234), 7, '0.01234');+ t.equal(_f(0.1234), 6, '0.1234');+ t.equal(_f(1.234), 5, '1.234');+ t.equal(_f(12.34), 5, '12.34');+ t.equal(_f(123.4), 5, '123.4');+ t.equal(_f(1234), 4, '1234');+ t.equal(_f(12340), 5, '12340');+ t.equal(_f(123400), 6, '123400');+ t.equal(_f(1234000), 7, '1234000');+ t.equal(_f(12340000), 8, '12340000');+ t.equal(_f(123400000), 9, '123400000');+ t.equal(_f(1234000000), 10, '1234000000');+ t.equal(_f(12340000000), 11, '12340000000');+ t.equal(_f(123400000000), 12, '123400000000');+ t.equal(_f(1234000000000), 13, '1234000000000');+ t.equal(_f(12340000000000), 14, '12340000000000');+ t.equal(_f(123400000000000), 15, '123400000000000');+ t.equal(_f(0.000000000000012345), 20, '0.000000000000012345');+ t.equal(_f(0.00000000000012345), 19, '0.00000000000012345');+ t.equal(_f(0.0000000000012345), 18, '0.0000000000012345');+ t.equal(_f(0.000000000012345), 17, '0.000000000012345');+ t.equal(_f(0.00000000012345), 16, '0.00000000012345');+ t.equal(_f(0.0000000012345), 15, '0.0000000012345');+ t.equal(_f(0.000000012345), 14, '0.000000012345');+ t.equal(_f(0.00000012345), 13, '0.00000012345');+ t.equal(_f(0.0000012345), 12, '0.0000012345');+ t.equal(_f(0.000012345), 11, '0.000012345');+ t.equal(_f(0.00012345), 10, '0.00012345');+ t.equal(_f(0.0012345), 9, '0.0012345');+ t.equal(_f(0.012345), 8, '0.012345');+ t.equal(_f(0.12345), 7, '0.12345');+ t.equal(_f(1.2345), 6, '1.2345');+ t.equal(_f(12.345), 6, '12.345');+ t.equal(_f(123.45), 6, '123.45');+ t.equal(_f(1234.5), 6, '1234.5');+ t.equal(_f(12345), 5, '12345');+ t.equal(_f(123450), 6, '123450');+ t.equal(_f(1234500), 7, '1234500');+ t.equal(_f(12345000), 8, '12345000');+ t.equal(_f(123450000), 9, '123450000');+ t.equal(_f(1234500000), 10, '1234500000');+ t.equal(_f(12345000000), 11, '12345000000');+ t.equal(_f(123450000000), 12, '123450000000');+ t.equal(_f(1234500000000), 13, '1234500000000');+ t.equal(_f(12345000000000), 14, '12345000000000');+ t.equal(_f(123450000000000), 15, '123450000000000');+ t.equal(_f(1.23456e-14), 21, '1.23456E-14');+ t.equal(_f(0.000000000000123456), 20, '0.000000000000123456');+ t.equal(_f(0.00000000000123456), 19, '0.00000000000123456');+ t.equal(_f(0.0000000000123456), 18, '0.0000000000123456');+ t.equal(_f(0.000000000123456), 17, '0.000000000123456');+ t.equal(_f(0.00000000123456), 16, '0.00000000123456');+ t.equal(_f(0.0000000123456), 15, '0.0000000123456');+ t.equal(_f(0.000000123456), 14, '0.000000123456');+ t.equal(_f(0.00000123456), 13, '0.00000123456');+ t.equal(_f(0.0000123456), 12, '0.0000123456');+ t.equal(_f(0.000123456), 11, '0.000123456');+ t.equal(_f(0.00123456), 10, '0.00123456');+ t.equal(_f(0.0123456), 9, '0.0123456');+ t.equal(_f(0.123456), 8, '0.123456');+ t.equal(_f(1.23456), 7, '1.23456');+ t.equal(_f(12.3456), 7, '12.3456');+ t.equal(_f(123.456), 7, '123.456');+ t.equal(_f(1234.56), 7, '1234.56');+ t.equal(_f(12345.6), 7, '12345.6');+ t.equal(_f(123456), 6, '123456');+ t.equal(_f(1234560), 7, '1234560');+ t.equal(_f(12345600), 8, '12345600');+ t.equal(_f(123456000), 9, '123456000');+ t.equal(_f(1234560000), 10, '1234560000');+ t.equal(_f(12345600000), 11, '12345600000');+ t.equal(_f(123456000000), 12, '123456000000');+ t.equal(_f(1234560000000), 13, '1234560000000');+ t.equal(_f(12345600000000), 14, '12345600000000');+ t.equal(_f(123456000000000), 15, '123456000000000');+ t.equal(_f(1.234567e-14), 22, '1.234567E-14');+ t.equal(_f(1.234567e-13), 21, '1.234567E-13');+ t.equal(_f(0.000000000001234567), 20, '0.000000000001234567');+ t.equal(_f(0.00000000001234567), 19, '0.00000000001234567');+ t.equal(_f(0.0000000001234567), 18, '0.0000000001234567');+ t.equal(_f(0.000000001234567), 17, '0.000000001234567');+ t.equal(_f(0.00000001234567), 16, '0.00000001234567');+ t.equal(_f(0.0000001234567), 15, '0.0000001234567');+ t.equal(_f(0.000001234567), 14, '0.000001234567');+ t.equal(_f(0.00001234567), 13, '0.00001234567');+ t.equal(_f(0.0001234567), 12, '0.0001234567');+ t.equal(_f(0.001234567), 11, '0.001234567');+ t.equal(_f(0.01234567), 10, '0.01234567');+ t.equal(_f(0.1234567), 9, '0.1234567');+ t.equal(_f(1.234567), 8, '1.234567');+ t.equal(_f(12.34567), 8, '12.34567');+ t.equal(_f(123.4567), 8, '123.4567');+ t.equal(_f(1234.567), 8, '1234.567');+ t.equal(_f(12345.67), 8, '12345.67');+ t.equal(_f(123456.7), 8, '123456.7');+ t.equal(_f(1234567), 7, '1234567');+ t.equal(_f(12345670), 8, '12345670');+ t.equal(_f(123456700), 9, '123456700');+ t.equal(_f(1234567000), 10, '1234567000');+ t.equal(_f(12345670000), 11, '12345670000');+ t.equal(_f(123456700000), 12, '123456700000');+ t.equal(_f(1234567000000), 13, '1234567000000');+ t.equal(_f(12345670000000), 14, '12345670000000');+ t.equal(_f(123456700000000), 15, '123456700000000');+ t.equal(_f(1.2345678e-14), 23, '1.2345678E-14');+ t.equal(_f(1.2345678e-13), 22, '1.2345678E-13');+ t.equal(_f(1.2345678e-12), 21, '1.2345678E-12');+ t.equal(_f(0.000000000012345678), 20, '0.000000000012345678');+ t.equal(_f(0.00000000012345678), 19, '0.00000000012345678');+ t.equal(_f(0.0000000012345678), 18, '0.0000000012345678');+ t.equal(_f(0.000000012345678), 17, '0.000000012345678');+ t.equal(_f(0.00000012345678), 16, '0.00000012345678');+ t.equal(_f(0.0000012345678), 15, '0.0000012345678');+ t.equal(_f(0.000012345678), 14, '0.000012345678');+ t.equal(_f(0.00012345678), 13, '0.00012345678');+ t.equal(_f(0.0012345678), 12, '0.0012345678');+ t.equal(_f(0.012345678), 11, '0.012345678');+ t.equal(_f(0.12345678), 10, '0.12345678');+ t.equal(_f(1.2345678), 9, '1.2345678');+ t.equal(_f(12.345678), 9, '12.345678');+ t.equal(_f(123.45678), 9, '123.45678');+ t.equal(_f(1234.5678), 9, '1234.5678');+ t.equal(_f(12345.678), 9, '12345.678');+ t.equal(_f(123456.78), 9, '123456.78');+ t.equal(_f(1234567.8), 9, '1234567.8');+ t.equal(_f(12345678), 8, '12345678');+ t.equal(_f(123456780), 9, '123456780');+ t.equal(_f(1234567800), 10, '1234567800');+ t.equal(_f(12345678000), 11, '12345678000');+ t.equal(_f(123456780000), 12, '123456780000');+ t.equal(_f(1234567800000), 13, '1234567800000');+ t.equal(_f(12345678000000), 14, '12345678000000');+ t.equal(_f(123456780000000), 15, '123456780000000');+ t.equal(_f(1.23456789e-14), 24, '1.23456789E-14');+ t.equal(_f(1.23456789e-13), 23, '1.23456789E-13');+ t.equal(_f(1.23456789e-12), 22, '1.23456789E-12');+ t.equal(_f(1.23456789e-11), 21, '1.23456789E-11');+ t.equal(_f(0.000000000123456789), 20, '0.000000000123456789');+ t.equal(_f(0.00000000123456789), 19, '0.00000000123456789');+ t.equal(_f(0.0000000123456789), 18, '0.0000000123456789');+ t.equal(_f(0.000000123456789), 17, '0.000000123456789');+ t.equal(_f(0.00000123456789), 16, '0.00000123456789');+ t.equal(_f(0.0000123456789), 15, '0.0000123456789');+ t.equal(_f(0.000123456789), 14, '0.000123456789');+ t.equal(_f(0.00123456789), 13, '0.00123456789');+ t.equal(_f(0.0123456789), 12, '0.0123456789');+ t.equal(_f(0.123456789), 11, '0.123456789');+ t.equal(_f(1.23456789), 10, '1.23456789');+ t.equal(_f(12.3456789), 10, '12.3456789');+ t.equal(_f(123.456789), 10, '123.456789');+ t.equal(_f(1234.56789), 10, '1234.56789');+ t.equal(_f(12345.6789), 10, '12345.6789');+ t.equal(_f(123456.789), 10, '123456.789');+ t.equal(_f(1234567.89), 10, '1234567.89');+ t.equal(_f(12345678.9), 10, '12345678.9');+ t.equal(_f(123456789), 9, '123456789');+ t.equal(_f(1234567890), 10, '1234567890');+ t.equal(_f(12345678900), 11, '12345678900');+ t.equal(_f(123456789000), 12, '123456789000');+ t.equal(_f(1234567890000), 13, '1234567890000');+ t.equal(_f(12345678900000), 14, '12345678900000');+ t.equal(_f(123456789000000), 15, '123456789000000');+ t.equal(_f(1.234567891e-14), 25, '1.234567891E-14');+ t.equal(_f(1.234567891e-13), 24, '1.234567891E-13');+ t.equal(_f(1.234567891e-12), 23, '1.234567891E-12');+ t.equal(_f(1.234567891e-11), 22, '1.234567891E-11');+ t.equal(_f(1.234567891e-10), 21, '1.234567891E-10');+ t.equal(_f(0.000000001234567891), 20, '0.000000001234567891');+ t.equal(_f(0.00000001234567891), 19, '0.00000001234567891');+ t.equal(_f(0.0000001234567891), 18, '0.0000001234567891');+ t.equal(_f(0.000001234567891), 17, '0.000001234567891');+ t.equal(_f(0.00001234567891), 16, '0.00001234567891');+ t.equal(_f(0.0001234567891), 15, '0.0001234567891');+ t.equal(_f(0.001234567891), 14, '0.001234567891');+ t.equal(_f(0.01234567891), 13, '0.01234567891');+ t.equal(_f(0.1234567891), 12, '0.1234567891');+ t.equal(_f(1.234567891), 11, '1.234567891');+ t.equal(_f(12.34567891), 11, '12.34567891');+ t.equal(_f(123.4567891), 11, '123.4567891');+ t.equal(_f(1234.567891), 11, '1234.567891');+ t.equal(_f(12345.67891), 11, '12345.67891');+ t.equal(_f(123456.7891), 11, '123456.7891');+ t.equal(_f(1234567.891), 11, '1234567.891');+ t.equal(_f(12345678.91), 11, '12345678.91');+ t.equal(_f(123456789.1), 11, '123456789.1');+ t.equal(_f(1234567891), 10, '1234567891');+ t.equal(_f(12345678910), 11, '12345678910');+ t.equal(_f(123456789100), 12, '123456789100');+ t.equal(_f(1234567891000), 13, '1234567891000');+ t.equal(_f(12345678910000), 14, '12345678910000');+ t.equal(_f(123456789100000), 15, '123456789100000');+ t.equal(_f(1.2345678912e-14), 26, '1.2345678912E-14'); // 0.000000000000012345678912+ t.equal(_f(1.2345678912e-13), 25, '1.2345678912E-13');+ t.equal(_f(1.2345678912e-12), 24, '1.2345678912E-12');+ t.equal(_f(1.2345678912e-11), 23, '1.2345678912E-11');+ t.equal(_f(1.2345678912e-10), 22, '1.2345678912E-10');+ t.equal(_f(1.2345678912e-09), 21, '1.2345678912E-09');+ t.equal(_f(0.000000012345678912), 20, '0.000000012345678912');+ t.equal(_f(0.00000012345678912), 19, '0.00000012345678912');+ t.equal(_f(0.0000012345678912), 18, '0.0000012345678912');+ t.equal(_f(0.000012345678912), 17, '0.000012345678912');+ t.equal(_f(0.00012345678912), 16, '0.00012345678912');+ t.equal(_f(0.0012345678912), 15, '0.0012345678912');+ t.equal(_f(0.012345678912), 14, '0.012345678912');+ t.equal(_f(0.12345678912), 13, '0.12345678912');+ t.equal(_f(1.2345678912), 12, '1.2345678912');+ t.equal(_f(12.345678912), 12, '12.345678912');+ t.equal(_f(123.45678912), 12, '123.45678912');+ t.equal(_f(1234.5678912), 12, '1234.5678912');+ t.equal(_f(12345.678912), 12, '12345.678912');+ t.equal(_f(123456.78912), 12, '123456.78912');+ t.equal(_f(1234567.8912), 12, '1234567.8912');+ t.equal(_f(12345678.912), 12, '12345678.912');+ t.equal(_f(123456789.12), 12, '123456789.12');+ t.equal(_f(1234567891.2), 12, '1234567891.2');+ t.equal(_f(12345678912), 11, '12345678912');+ t.equal(_f(123456789120), 12, '123456789120');+ t.equal(_f(1234567891200), 13, '1234567891200');+ t.equal(_f(12345678912000), 14, '12345678912000');+ t.equal(_f(123456789120000), 15, '123456789120000');+ t.equal(_f(1.23456789123e-14), 27, '1.23456789123E-14');+ t.equal(_f(1.23456789123e-13), 26, '1.23456789123E-13');+ t.equal(_f(1.23456789123e-12), 25, '1.23456789123E-12');+ t.equal(_f(1.23456789123e-11), 24, '1.23456789123E-11');+ t.equal(_f(1.23456789123e-10), 23, '1.23456789123E-10');+ t.equal(_f(1.23456789123e-09), 22, '1.23456789123E-09');+ t.equal(_f(1.23456789123e-08), 21, '1.23456789123E-08');+ t.equal(_f(0.000000123456789123), 20, '0.000000123456789123');+ t.equal(_f(0.00000123456789123), 19, '0.00000123456789123');+ t.equal(_f(0.0000123456789123), 18, '0.0000123456789123');+ t.equal(_f(0.000123456789123), 17, '0.000123456789123');+ t.equal(_f(0.00123456789123), 16, '0.00123456789123');+ t.equal(_f(0.0123456789123), 15, '0.0123456789123');+ t.equal(_f(0.123456789123), 14, '0.123456789123');+ t.equal(_f(1.23456789123), 13, '1.23456789123');+ t.equal(_f(12.3456789123), 13, '12.3456789123');+ t.equal(_f(123.456789123), 13, '123.456789123');+ t.equal(_f(1234.56789123), 13, '1234.56789123');+ t.equal(_f(12345.6789123), 13, '12345.6789123');+ t.equal(_f(123456.789123), 13, '123456.789123');+ t.equal(_f(1234567.89123), 13, '1234567.89123');+ t.equal(_f(12345678.9123), 13, '12345678.9123');+ t.equal(_f(123456789.123), 13, '123456789.123');+ t.equal(_f(1234567891.23), 13, '1234567891.23');+ t.equal(_f(12345678912.3), 13, '12345678912.3');+ t.equal(_f(123456789123), 12, '123456789123');+ t.equal(_f(1234567891230), 13, '1234567891230');+ t.equal(_f(12345678912300), 14, '12345678912300');+ t.equal(_f(123456789123000), 15, '123456789123000');+ t.equal(_f(1.234567891234e-14), 28, '1.234567891234E-14');+ t.equal(_f(1.234567891234e-13), 27, '1.234567891234E-13');+ t.equal(_f(1.234567891234e-12), 26, '1.234567891234E-12');+ t.equal(_f(1.234567891234e-11), 25, '1.234567891234E-11');+ t.equal(_f(1.234567891234e-10), 24, '1.234567891234E-10');+ t.equal(_f(1.234567891234e-09), 23, '1.234567891234E-09');+ t.equal(_f(1.234567891234e-08), 22, '1.234567891234E-08');+ t.equal(_f(1.234567891234e-07), 21, '1.234567891234E-07');+ t.equal(_f(0.000001234567891234), 20, '0.000001234567891234');+ t.equal(_f(0.00001234567891234), 19, '0.00001234567891234');+ t.equal(_f(0.0001234567891234), 18, '0.0001234567891234');+ t.equal(_f(0.001234567891234), 17, '0.001234567891234');+ t.equal(_f(0.01234567891234), 16, '0.01234567891234');+ t.equal(_f(0.1234567891234), 15, '0.1234567891234');+ t.equal(_f(1.234567891234), 14, '1.234567891234');+ t.equal(_f(12.34567891234), 14, '12.34567891234');+ t.equal(_f(123.4567891234), 14, '123.4567891234');+ t.equal(_f(1234.567891234), 14, '1234.567891234');+ t.equal(_f(12345.67891234), 14, '12345.67891234');+ t.equal(_f(123456.7891234), 14, '123456.7891234');+ t.equal(_f(1234567.891234), 14, '1234567.891234');+ t.equal(_f(12345678.91234), 14, '12345678.91234');+ t.equal(_f(123456789.1234), 14, '123456789.1234');+ t.equal(_f(1234567891.234), 14, '1234567891.234');+ t.equal(_f(12345678912.34), 14, '12345678912.34');+ t.equal(_f(123456789123.4), 14, '123456789123.4');+ t.equal(_f(1234567891234), 13, '1234567891234');+ t.equal(_f(12345678912340), 14, '12345678912340');+ t.equal(_f(123456789123400), 15, '123456789123400');+ t.equal(_f(1.2345678912345e-14), 29, '1.2345678912345E-14');+ t.equal(_f(1.2345678912345e-13), 28, '1.2345678912345E-13');+ t.equal(_f(1.2345678912345e-12), 27, '1.2345678912345E-12');+ t.equal(_f(1.2345678912345e-11), 26, '1.2345678912345E-11');+ t.equal(_f(1.2345678912345e-10), 25, '1.2345678912345E-10');+ t.equal(_f(1.2345678912345e-09), 24, '1.2345678912345E-09');+ t.equal(_f(1.2345678912345e-08), 23, '1.2345678912345E-08');+ t.equal(_f(1.2345678912345e-07), 22, '1.2345678912345E-07');+ t.equal(_f(1.2345678912345e-06), 21, '1.2345678912345E-06');+ t.equal(_f(0.000012345678912345), 20, '0.000012345678912345');+ t.equal(_f(0.00012345678912345), 19, '0.00012345678912345');+ t.equal(_f(0.0012345678912345), 18, '0.0012345678912345');+ t.equal(_f(0.012345678912345), 17, '0.012345678912345');+ t.equal(_f(0.12345678912345), 16, '0.12345678912345');+ t.equal(_f(1.2345678912345), 15, '1.2345678912345');+ t.equal(_f(12.345678912345), 15, '12.345678912345');+ t.equal(_f(123.45678912345), 15, '123.45678912345');+ t.equal(_f(1234.5678912345), 15, '1234.5678912345');+ t.equal(_f(12345.678912345), 15, '12345.678912345');+ t.equal(_f(123456.78912345), 15, '123456.78912345');+ t.equal(_f(1234567.8912345), 15, '1234567.8912345');+ t.equal(_f(12345678.912345), 15, '12345678.912345');+ t.equal(_f(123456789.12345), 15, '123456789.12345');+ t.equal(_f(1234567891.2345), 15, '1234567891.2345');+ t.equal(_f(12345678912.345), 15, '12345678912.345');+ t.equal(_f(123456789123.45), 15, '123456789123.45');+ t.equal(_f(1234567891234.5), 15, '1234567891234.5');+ t.equal(_f(12345678912345), 14, '12345678912345');+ t.equal(_f(123456789123450), 15, '123456789123450');+ t.equal(_f(1.23456789123456e-14), 30, '1.23456789123456E-14');+ t.equal(_f(1.23456789123456e-13), 29, '1.23456789123456E-13');+ t.equal(_f(1.23456789123456e-12), 28, '1.23456789123456E-12');+ t.equal(_f(1.23456789123456e-11), 27, '1.23456789123456E-11');+ t.equal(_f(1.23456789123456e-10), 26, '1.23456789123456E-10');+ t.equal(_f(1.23456789123456e-09), 25, '1.23456789123456E-09');+ t.equal(_f(1.23456789123456e-08), 24, '1.23456789123456E-08');+ t.equal(_f(1.23456789123456e-07), 23, '1.23456789123456E-07');+ t.equal(_f(1.23456789123456e-06), 22, '1.23456789123456E-06');+ t.equal(_f(1.23456789123456e-05), 21, '1.23456789123456E-05');+ t.equal(_f(0.000123456789123456), 20, '0.000123456789123456');+ t.equal(_f(0.00123456789123456), 19, '0.00123456789123456');+ t.equal(_f(0.0123456789123456), 18, '0.0123456789123456');+ t.equal(_f(0.123456789123456), 17, '0.123456789123456');+ t.equal(_f(1.23456789123456), 16, '1.23456789123456');+ t.equal(_f(12.3456789123456), 16, '12.3456789123456');+ t.equal(_f(123.456789123456), 16, '123.456789123456');+ t.equal(_f(1234.56789123456), 16, '1234.56789123456');+ t.equal(_f(12345.6789123456), 16, '12345.6789123456');+ t.equal(_f(123456.789123456), 16, '123456.789123456');+ t.equal(_f(1234567.89123456), 16, '1234567.89123456');+ t.equal(_f(12345678.9123456), 16, '12345678.9123456');+ t.equal(_f(123456789.123456), 16, '123456789.123456');+ t.equal(_f(1234567891.23456), 16, '1234567891.23456');+ t.equal(_f(12345678912.3456), 16, '12345678912.3456');+ t.equal(_f(123456789123.456), 16, '123456789123.456');+ t.equal(_f(1234567891234.56), 16, '1234567891234.56');+ t.equal(_f(12345678912345.6), 16, '12345678912345.6');+ t.equal(_f(123456789123456), 15, '123456789123456');+ t.equal(_f(-1.234567e-14), 23, '-1.234567E-14');+ t.equal(_f(-1.234567e-13), 22, '-1.234567E-13');+ t.equal(_f(-0.000000000001234567), 21, '-0.000000000001234567');+ t.equal(_f(-0.00000000001234567), 20, '-0.00000000001234567');+ t.equal(_f(-0.0000000001234567), 19, '-0.0000000001234567');+ t.equal(_f(-0.000000001234567), 18, '-0.000000001234567');+ t.equal(_f(-0.00000001234567), 17, '-0.00000001234567');+ t.equal(_f(-0.0000001234567), 16, '-0.0000001234567');+ t.equal(_f(-0.000001234567), 15, '-0.000001234567');+ t.equal(_f(-0.00001234567), 14, '-0.00001234567');+ t.equal(_f(-0.0001234567), 13, '-0.0001234567');+ t.equal(_f(-0.001234567), 12, '-0.001234567');+ t.equal(_f(-0.01234567), 11, '-0.01234567');+ t.equal(_f(-0.1234567), 10, '-0.1234567');+ t.equal(_f(-1.234567), 9, '-1.234567');+ t.equal(_f(-12.34567), 9, '-12.34567');+ t.equal(_f(-123.4567), 9, '-123.4567');+ t.equal(_f(-1234.567), 9, '-1234.567');+ t.equal(_f(-12345.67), 9, '-12345.67');+ t.equal(_f(-123456.7), 9, '-123456.7');+ t.equal(_f(-1234567), 8, '-1234567');+ t.equal(_f(-12345670), 9, '-12345670');+ t.equal(_f(-123456700), 10, '-123456700');+ t.equal(_f(-1234567000), 11, '-1234567000');+ t.equal(_f(-12345670000), 12, '-12345670000');+ t.equal(_f(-123456700000), 13, '-123456700000');+ t.equal(_f(-1234567000000), 14, '-1234567000000');+ t.equal(_f(-12345670000000), 15, '-12345670000000');+ t.equal(_f(-123456700000000), 16, '-123456700000000');++ // supposed corner cases, found on teh internets+ // https://stackoverflow.com/questions/9539513/+ t.equal(_f(0.0028), 6, '0.0028');+ t.equal(_f(0.0029), 6, '0.0029');+ t.equal(_f(0.0408), 6, '0.0408');+ t.equal(_f(0.1584), 6, '0.1584');+ t.equal(_f(4.3573), 6, '4.3573');+ t.equal(_f(11.6894), 7, '11.6894');+ t.equal(_f(0), 1, '0');+ t.equal(_f(1), 1, '1.0');+ t.equal(_f(0.123), 5, '0.123');+ t.equal(_f(1e-3), 5, '1e-3');+ t.equal(_f(-1e2), 4, '-1e2');+ t.equal(_f(-1e-2), 5, '-1e-2');+ t.equal(_f(-0.1), 4, '-0.1');+ t.equal(_f(1 / 3), 17, '1/3');+ t.equal(_f(3.14), 4, '3.14');+ t.equal(_f(2e-3), 5, '2e-3');+ t.equal(_f(2e-14), 16, '2e-14');+ t.equal(_f(Math.PI), 16, 'Math.PI');+ t.equal(_f(1e-9), 11, '1e-9');+ t.equal(_f(1e-10), 12, '1e-10');+ t.equal(_f(-3.14e-13), 18, '-3.14e-13');+ t.equal(_f(3e-13), 15, '3e-13');+ t.equal(_f(3e-14), 16, '3e-14');+ t.equal(_f(123.12345678901234567890), 16, '123.12345678901235...'); // overflows+ t.equal(_f(5555), 4, '5555');+ t.equal(_f(555.5), 5, '555.5');+ t.equal(_f(55.55), 5, '55.55');+ t.equal(_f(0.0000005), 9, '0.0000005');+ t.equal(_f(5e-7), 9, '5e-7');+ t.equal(_f(0.00000055), 10, '0.00000055');+ t.equal(_f(5e-8), 10, '5e-8');+ t.equal(_f(0.000006), 8, '0.000006');+ t.equal(_f(0.0000007), 9, '0.0000007');+ t.equal(_f(0.123), 5, '0.123');+ t.equal(_f(0.121), 5, '0.121');+ t.equal(_f(0.1215), 6, '0.1215');++ // truncation test 4+11 = 15 (plus period)+ t.equal(_f(1000.00000000001), 16, '1000.00000000001');+ t.equal(_f(-1000.00000000001), 17, '-1000.00000000001');+ // truncation test 4+12 = 16+ t.equal(_f(1000.000000000001), 4, '1000.000000000001');+ // truncation test 4+13 = 17+ t.equal(_f(1000.0000000000001), 4, '1000.0000000000001');+ // truncation test 5+13 = 18+ t.equal(_f(10000.0000000000001), 5, '10000.0000000000001');+});diff --git a/packages/core/src/shared/numfmt/__tests__/numfmt.spec.ts b/packages/core/src/shared/numfmt/__tests__/numfmt.spec.tsnew file mode 100644index 0000000000..06a77cce82--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/numfmt.spec.ts@@ -0,0 +1,318 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { isDateFormat, isPercentFormat, isTextFormat, format as numfmt } from '../api';+import { getTimeZoneName, getTimeZoneOffset, numfmtTest } from './test-utils';++/* globals process */+/* eslint-disable no-loss-of-precision */++numfmtTest('near zero negatives:', (t) => {+ t.format('-0', -1, '--1');+ t.format('-general', -1, '--1');+ t.throws(() => numfmt('0.0 general', undefined), '0.0 general');+ t.format('0.0', -1, '-1.0');+ t.format('0.0', -0.1, '-0.1');+ t.format('-0.0', -0.01, '-0.0');+ t.format('0.0', -0.01, '0.0');+ t.format(' - 0.0', -0.01, ' - 0.0');+ t.format(' - 0.0', -1, '- - 1.0');+ t.format('0.0;-0.0', -0.01, '-0.0');+ t.format('# ?/?', -0.01, '-0 ');+ t.format('\\p\\o\\s 0.0;\\n\\e\\g 0.0;', -0.01, 'neg 0.0');+});++numfmtTest('scaling should not mess number up:', (t) => {+ t.format('0.0%', 0.0295, '3.0%');+ t.format('0.0,', 2950, '3.0');+ t.format('0%', 0, '0%');+});++numfmtTest('Excel-compatible decimal rounding:', (t) => {+ t.format('0.00', 10.155, '10.16');+ t.format('0.00', 1.005, '1.01');+ t.format('0.00', 2.155, '2.16');+ t.format('0.00', -10.155, '-10.16');+ t.format('0.00', -1.005, '-1.01');+ t.format('0.00', -2.155, '-2.16');+ t.format('0.00', 1.00499999999999, '1.00');+ t.format('0.00', 1.00500000000001, '1.01');+ t.format('0.00', 9.995, '10.00');+ t.format('0.00%', 0.10155, '10.16%');+ t.format('0.00', -0.004, '0.00');+ t.format('0.000000000000000', 0.1 + 0.2, '0.300000000000000');+ t.format('0.00', 999999999999999, '999999999999999.00');+ t.format('0.00', 450000000000000.44, '450000000000000.00');+});++numfmtTest('Misc input:', (t) => {+ t.format('0', undefined, '');+ t.format('0', null, '');+ t.format('0', Number.NaN, 'NaN');+ t.format('0', Infinity, '∞');+ t.format('0', -Infinity, '-∞');+ t.format('0', true, 'TRUE');+ t.format('0', false, 'FALSE');+});++numfmtTest('isDate:', (t) => {+ t.equal(isDateFormat('y'), true, 'isDate(y)');+ t.equal(isDateFormat('#;y'), true, 'isDate(#;y)');+ t.equal(isDateFormat('"y"'), false, 'isDate("y")');+ t.equal(isDateFormat('#;"y"'), false, 'isDate(#;"y")');+ t.equal(isDateFormat('\\y'), false, 'isDate(\\y)');+ t.equal(isDateFormat('#;\\y'), false, 'isDate(#;\\y)');+ t.equal(isDateFormat('#'), false, 'isDate(#)');+ t.equal(isDateFormat('@'), false, 'isDate(@)');+ t.equal(isDateFormat(''), false, 'isDate()');+});++numfmtTest('isPercent:', (t) => {+ t.equal(isPercentFormat('0%'), true, 'isPercent(0%)');+ t.equal(isPercentFormat('#%'), true, 'isPercent(#%)');+ t.equal(isPercentFormat('#;#%'), true, 'isPercent(#;#%)');+ t.equal(isPercentFormat('%'), true, 'isPercent(%)');+ t.equal(isPercentFormat('#"%"'), false, 'isPercent(#"%")');+ t.equal(isPercentFormat('#\\%'), false, 'isPercent(#\\%)');+ t.equal(isPercentFormat('@'), false, 'isPercent(@)');+ t.equal(isPercentFormat(''), false, 'isPercent()');+});++numfmtTest('isText:', (t) => {+ t.equal(isTextFormat('0%'), false, 'isText(0%)');+ t.equal(isTextFormat('#%'), false, 'isText(#%)');+ t.equal(isTextFormat('#;#%'), false, 'isText(#;#%)');+ t.equal(isTextFormat('%'), false, 'isText(%)');+ t.equal(isTextFormat('#"%"'), false, 'isText(#"%")');+ t.equal(isTextFormat('#\\%'), false, 'isText(#\\%)');+ t.equal(isTextFormat(''), false, 'isText()');+ t.equal(isTextFormat('@'), true, 'isText(@)');+ t.equal(isTextFormat('[blue]@'), true, 'isText([blue]@)');+ t.equal(isTextFormat('#;@'), false, 'isText(#;@)');+ t.equal(isTextFormat('#;#;@'), false, 'isText(#;#;@)');+ t.equal(isTextFormat('#;#;#;@'), false, 'isText(#;#;#;@)');+});++numfmtTest('Date object as a value:', (t) => {+ process.env.TZ = 'Etc/UTC';+ t.equal(getTimeZoneName(), 'Coordinated Universal Time');++ t.format('0.######', new Date(1900, 1 - 1, 0), '0.');+ t.format('0.######', new Date(1900, 1 - 1, 1), '1.');+ t.format('0.######', new Date(1900, 1 - 1, 2), '2.');+ t.format('0.######', new Date(1900, 1 - 1, 3), '3.');+ t.format('0.######', new Date(1900, 1 - 1, 4), '4.');+ t.format('0.######', new Date(1900, 1 - 1, 5), '5.');+ t.format('0.######', new Date(1900, 1 - 1, 20), '20.');+ t.format('0.######', new Date(1900, 2 - 1, 1), '32.');+ t.equal(numfmt('0.######', new Date(1900, 2 - 1, 28)), '59.', 'new Date(1900, 2 - 1, 28, 0, 0, 0)');+ // 1900-02-29 (serial number 60) is a date that only exists in Excel+ t.equal(numfmt('0.######', new Date(1900, 3 - 1, 1)), '61.', 'new Date(1900, 3 - 1, 1, 0, 0, 0)');+ t.equal(numfmt('0.######', new Date(1900, 3 - 1, 2)), '62.', 'new Date(1900, 3 - 1, 2, 0, 0, 0)');+ t.equal(numfmt('0.######', new Date(1900, 3 - 1, 3)), '63.', 'new Date(1900, 3 - 1, 3, 0, 0, 0)');+ t.format('0.######', new Date(2000, 10 - 1, 10), '36809.');+ t.format('0.######', new Date(2100, 10 - 1, 30), '73353.');+ t.format('0.######', new Date(2004, 2 - 1, 29), '38046.');+ t.format('0.######', new Date(2020, 2 - 1, 29), '43890.');+ t.format('0.######', new Date(2000, 5 - 1, 9, 1, 0, 0), '36655.041667');+ t.format('0.######', new Date(1900, 1 - 1, 0, 1, 0, 0), '0.041667');+ t.format('0.######', new Date(1900, 1 - 1, 0, 0, 1, 0), '0.000694');+ t.format('0.######', new Date(1900, 1 - 1, 0, 0, 0, 1), '0.000012');+ t.format('0.######', new Date(1900, 1 - 1, 0, 23, 0, 0), '0.958333');+ t.format('0.######', new Date(1900, 1 - 1, 0, 0, 59, 0), '0.040972');+ t.format('0.######', new Date(1900, 1 - 1, 0, 0, 0, 59), '0.000683');+ t.format('0.######', new Date(1900, 1 - 1, 0, 23, 59, 59), '0.999988');+ t.format('0.######', new Date(1909, 1 - 1, 2, 3, 4, 5), '3290.127836');+ t.format('0.######', new Date(1909, 1 - 1, 2, 3, 4, 5), '3290.127836');+ // these were yielding "Sep 0, 2020"+ t.format('MMM D, YYYY', new Date(2020, 8 - 1, 31, 13, 3, 0), 'Aug 31, 2020');+ t.format('MMM D, YYYY', new Date(Date.parse('2020-08-31T02:42:00.1')), 'Aug 31, 2020');++ // test ignoreTimezone+ const testYMD = (y: number, m: number, d: number) => {+ const dt = new Date(y, m, d);+ const tzSkew = getTimeZoneOffset(dt) / (60 * 24);+ const output = numfmt('General', dt, { ignoreTimezone: true });+ const diff = +output.replace(/^\d*(\.\d*)?$/, '0$1') - tzSkew;+ return Math.abs(diff);+ };++ t.ok(testYMD(1900, 0, 0) < 0.00001, '1900 [ignoreTimezone]');+ t.ok(testYMD(1950, 0, 0) < 0.00001, '1950 [ignoreTimezone]');+ t.ok(testYMD(2000, 0, 0) < 0.00001, '2000 [ignoreTimezone]');+});++numfmtTest('Significant digits truncation:', (t) => {+ t.format('General', 3300.0000000000005, '3300');+ t.format('General', -33000.000000000001, '-33000');+});++numfmtTest('Order of operators in fractions doesn\'t matter:', (t) => {+ // 0 after #+ t.format('#.##0', -10.29, '-10.290');+ t.format('#.###0', -10.29, '-10.290');+ t.format('#.####0', -10.29, '-10.290');+ t.format('#.###000', -10.29, '-10.29000');+ t.format('#.#0#0#0', -10.29, '-10.2900');+ t.format('#.#00', 1, '1.00');+ t.format('#.####0', 1, '1.0');+ t.format('#.###000', 1, '1.000');+ t.format('#.#0#0#0', 1, '1.000');+ t.format('#.##0', 0.01, '.010');+ t.format('#.###0', 0.01, '.010');+ t.format('#.#00', 0.01, '.010');+ t.format('#.####0', 0.0001, '.00010');+ t.format('#.#00', 0.0001, '.00');+ t.format('#.#0', 0.1, '.10');+ t.format('#.##0', 0.1, '.10');+ t.format('#.###0', 0.1, '.10');+ // 0 after ?+ t.format('#.?00', 1, '1. 00');+ t.format('#.?0', 0.0001, '. 0');+ t.format('#.????0', -10.29, '-10.29 0');+ t.format('#.????0', 0.01, '.01 0');+ // split pattern+ t.format('#.#x#0', 1, '1.x0');+ t.format('#.#x#0', 0.1, '.1x0');+ t.format('#.??x?0', 0.01, '.01x 0');+});++numfmtTest('Order of operators in integers doesn\'t matter:', (t) => {+ t.format('0#', 0, '0');+ t.format('0?', 0, '0 ');+ t.format('0#0#', 0, '00');+ t.format('0?0?', 0, '0 0 ');+});++numfmtTest('Automatic minus injection for the third condition:', (t) => { // issue #27+ t.format('[>=100]#,##0;[<=-100]-#,##0;#,##0.00', -3.96, '-3.96');+ t.format('[>=100]#,##0;[<=-100]-#,##0;-#,##0.00', -3.96, '--3.96');+ t.format('[>=100]0;[<=-100]-0;"xx"0', -10, '-xx10');+ t.format('[<=-100]-0;"xx"0', -10, 'xx10');+});++numfmtTest('Excel ignores extra , in fractions:', (t) => { // issue #22+ t.format('#.##0,00', 0, '.000');+ t.format('#.##0,0,0', 0, '.000');+});++numfmtTest.skip('Order of operators in exponential notation does not matter:', (t) => {+ t.format('0?.?0E+1', 0, '00. 0E+1');+ t.format('0?.?0E+0', 0, '00. 0E+0');+});++numfmtTest.skip('Digits following denominator are padding', (t) => {+ t.format('00 00/0z0', 12345.67, '12345 02/3z0');+ t.format('00 00/0 0', 12345.67, '12345 02/3 0');+ t.format('00 00/? ?', 12345.67, '12345 02/3 ');+ t.format('00 00/# #', 12345.67, '12345 02/3 0');+});++numfmtTest('Integer gets injected if not present:', (t) => {+ t.format('.0', 1234, '1234.0');+ t.format(' .0', 1234, ' 1234.0');+ t.format('x.0', 1234, 'x1234.0');+ t.format(' . 0', 1234, ' 1234. 0');+ t.format('0 0/0', 1234, '1234 0/1');+ t.format('0/0', 1234, '1234/1');+});++numfmtTest('Padding:', (t) => {+ t.format('0', 1, '1');+ t.format('0?', 1, '01');+ t.format('0??', 1, '0 1');+ t.format('0???', 1, '0 1');+ t.format('0????', 1, '0 1');+ t.format('0', 0, '0');+ t.format('0?', 0, '0 ');+ t.format('0??', 0, '0 ');+ t.format('0???', 0, '0 ');+ t.format('0????', 0, '0 ');+ t.format('0', 1, '1');+ t.format('0#', 1, '01');+ t.format('0##', 1, '01');+ t.format('0###', 1, '01');+ t.format('0####', 1, '01');+ t.format('0', 0, '0');+ t.format('0#', 0, '0');+ t.format('0##', 0, '0');+ t.format('0###', 0, '0');+ t.format('0####', 0, '0');++ t.format('0,', 1, '0');+ t.format('0,?', 1, '01');+ t.format('0,??', 1, '0 1');+ t.format('0,???', 1, '0, 1');+ t.format('0,????', 1, '0 1');+ t.format('0,', 0, '0');+ t.format('0,?', 0, '0 ');+ t.format('0,??', 0, '0 ');+ t.format('0,???', 0, '0, ');+ t.format('0,????', 0, '0 ');++ t.format('.0', 1, '1.0');+ t.format('.?0', 1, '1. 0');+ t.format('.??0', 1, '1. 0');+ t.format('.???0', 1, '1. 0');+ t.format('.????0', 1, '1. 0');+ t.format('.0', 0, '.0');+ t.format('.?0', 0, '. 0');+ t.format('.??0', 0, '. 0');+ t.format('.???0', 0, '. 0');+ t.format('.????0', 0, '. 0');+ t.format('.0', 1, '1.0');+ t.format('.#0', 1, '1.0');+ t.format('.##0', 1, '1.0');+ t.format('.###0', 1, '1.0');+ t.format('.####0', 1, '1.0');+ t.format('.0', 0, '.0');+ t.format('.#0', 0, '.0');+ t.format('.##0', 0, '.0');+ t.format('.###0', 0, '.0');+ t.format('.####0', 0, '.0');+});++numfmtTest('Tokenizer is not case sensitive:', (t) => {+ t.format('mmmm', 1234, 'May');+ t.format('MMMM', 1234, 'May');+ t.format('Mmmm', 1234, 'May');+ t.format('MmMm', 1234, 'May');+ t.format('dddd', 1234, 'Monday');+ t.format('DDDD', 1234, 'Monday');+ t.format('Dddd', 1234, 'Monday');+ t.format('dDdD', 1234, 'Monday');+});++numfmtTest('Comma resolution test:', (t) => {+ t.format('#,,"M"', 6000000, '6M');+ t.format('#,,"M";', 6000000, '6M');+ t.format('#,,"M";#,,"M";0', 6000000, '6M');+});++numfmtTest('Issue #64 (very small number):', (t) => {+ t.format('0.000E+000', 2.33e-32, '2.330E-032');+ t.format('0.000E+000', 2.33e-321, '2.330E-321');+ t.format('0.000E+000', 2.33e+307, '2.330E+307');+ t.format('0.000E+000', 2.33e+309, '∞');++ t.format('General', 2.33e-321, '2.33E-321');+ t.format('0.0', 2.33e-321, '0.0');+});diff --git a/packages/core/src/shared/numfmt/__tests__/options.spec.ts b/packages/core/src/shared/numfmt/__tests__/options.spec.tsnew file mode 100644index 0000000000..b65f95efda--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/options.spec.ts@@ -0,0 +1,114 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { format } from '../api';+import { getTimeZoneName, numfmtTest } from './test-utils';++/* global process */++const excelOpts = { dateSpanLarge: false, dateErrorNumber: false };++numfmtTest('option: overflow', (t) => {+ t.format('yyyy', -1, '######', { ...excelOpts });+ t.format('yyyy', -1, '🦆', { ...excelOpts, overflow: '🦆' });+ t.format('yyyy', -1, '👻', { ...excelOpts, overflow: '👻' });+});++numfmtTest('option: locale', (t) => {+ t.format('mmmm', 2000, 'June');+ t.format('mmmm', 2000, '六月', { locale: 'zh_CN' });+ t.format('mmmm', 2000, 'kesäkuuta', { locale: 'fi' });+});++numfmtTest('option: throws', (t) => {+ t.throws(() => format('h #', 0), '{}');+ t.equal(format('h #', 0, { throws: false }), '######', '{ throws: false }');+ t.throws(() => format('h #', 0, { throws: true }), '{ throws: true }');+});++numfmtTest('option: invalid', (t) => {+ t.format('h #', 0, '######', { throws: false });+ t.format('h #', 0, '🦂', { invalid: '🦂', throws: false });+ t.format('h #', 0, '#VALUE!', { invalid: '#VALUE!', throws: false });+ t.format('h #', 0, 'true', { invalid: true as unknown as string, throws: false });+});++numfmtTest('option: leap1900', (t) => {+ t.format('yyyy-mm-dd', 60, '1900-02-29', {});+ t.format('yyyy-mm-dd', 60, '1900-02-29', { leap1900: true });+ t.format('yyyy-mm-dd', 60, '1900-02-28', { leap1900: false });+});++numfmtTest('option: dateErrorThrows', (t) => {+ t.format('yyyy', -694325, '-694325', {});+ t.format('yyyy', -1, '-1', { dateSpanLarge: false });+ t.formatThrows('yyyy', -1, '-1', { dateSpanLarge: false, dateErrorThrows: true });+ t.formatThrows('yyyy', -694325, '-694325', { dateErrorThrows: true });+});++numfmtTest('option: dateErrorNumber', (t) => {+ t.format('yyyy', -1, '-1', { dateSpanLarge: false });+ t.format('yyyy', -1, '-1', { dateSpanLarge: false, dateErrorNumber: true });+ t.format('yyyy', -1, '######', { dateSpanLarge: false, dateErrorNumber: false });+});++numfmtTest('option: nbsp', (t) => {+ const spaceFmt = '???0" ". 0??';+ t.format(spaceFmt, 1, ' 1 . 0 ');+ t.format(spaceFmt, 1, ' 1 . 0 ', { nbsp: true });+ t.format(spaceFmt, 1, ' 1 . 0 ', { nbsp: false });+ t.format('0 "foo bar" .0', 1.1, '1 foo bar .1');+ t.format('0 "foo bar" .0', 1.1, '1 foo bar .1', { nbsp: false });+ t.format('0 "foo bar" .0', 1.1, '1 foo bar .1', { nbsp: true });+});++numfmtTest('option: grouping', (t) => {+ t.format('0', 1234567890, '1234567890', { grouping: [2, 2] });+ t.format('#,##0', 1234567890, '1,234,567,890', { grouping: [3, 3] });+ t.format('#,##0', 1234567890, '1,234,567,890', { grouping: [3] });+ t.format('#,##0', 1234567890, '1,23,45,67,890', { grouping: [3, 2] });+ t.format('#,##0', 1234567890, '12,34,56,78,90', { grouping: [2, 2] });+ t.format('#,##0', 1234567890, '12,34,56,78,90', { grouping: [2] });+ t.format('#,##0', 1234567890, '12,345,678,90', { grouping: [2, 3] });+});++numfmtTest('option: grouping', (t) => {+ t.format('_($* #,##0.00_)', 12345.67, ' $12,345.67 ');+ t.format('_($* #,##0.00_)', 12345.67, '\x03($12,345.67\x03)', { skipChar: '\x03' });+ t.format('_($* #,##0.00_)', 12345.67, 'ÆÐ($12,345.67ÆÐ)', { skipChar: 'ÆÐ' });+ t.format('_($* #,##0.00_)', 12345.67, ' $\x04 12,345.67 ', { fillChar: '\x04' });+ t.format('_($* #,##0.00_)', 12345.67, ' $ÞÖ 12,345.67 ', { fillChar: 'ÞÖ' });+ t.format('_($* #,##0.00_)', 12345.67, '\x03($\x04 12,345.67\x03)', { skipChar: '\x03', fillChar: '\x04' });+});++// this test is flaky at best in node versions < 14 so only run it in 14++if (Number.parseInt(process.version.replace(/^v/, ''), 10) >= 14) {+ numfmtTest('option: ignoreTimezone', (t) => {+ process.env.TZ = 'Asia/Calcutta';+ t.equal(getTimeZoneName(), 'India Standard Time', 'Timezone is IST');+ const baseDate = new Date(2000, 0, 1);+ t.equal(baseDate.toUTCString(), 'Fri, 31 Dec 1999 18:30:00 GMT', 'Date has a timezone');+ const gmtStr = 'ddd, dd mmm yyyy hh:mm:ss "GMT"';+ t.format(gmtStr, baseDate, 'Sat, 01 Jan 2000 00:00:00 GMT', { nbsp: 0 as unknown as boolean });+ t.format(gmtStr, baseDate, 'Fri, 31 Dec 1999 18:30:00 GMT', { nbsp: 0 as unknown as boolean, ignoreTimezone: true });+ t.format(gmtStr, baseDate, 'Sat, 01 Jan 2000 00:00:00 GMT', { nbsp: 0 as unknown as boolean, ignoreTimezone: false });+ });+}diff --git a/packages/core/src/shared/numfmt/__tests__/parse-value.spec.ts b/packages/core/src/shared/numfmt/__tests__/parse-value.spec.tsnew file mode 100644index 0000000000..9301ec6b06--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/parse-value.spec.ts@@ -0,0 +1,762 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { addLocale, dateToSerial, format, parseBool, parseDate, parseNumber, parseTime, parseValue } from '../api';+import { getLocale, listLocales } from '../locale';+import { getTimeZoneName, isLeapYear, numfmtTest } from './test-utils';++/* globals process */++const currentYear = dateToSerial([new Date().getUTCFullYear(), 1, 1]) || 0;+const leapDay = isLeapYear(new Date().getUTCFullYear()) ? 1 : 0;++/**+ * @type {[ string, number | boolean | null, string | null ][]}+ * @ignore+ */+const tests: Array<[string, number | boolean | null, string | null]> = [+ // general+ ['1234', 1234, null],+ ['12.34', 12.34, null],+ ['12.34 ', 12.34, null],+ [' 12.34', 12.34, null],+ ['+12.34 ', 12.34, null],+ ['-12.34 ', -12.34, null],+ ['- 12.34 ', -12.34, null],+ ['- 12.34 ', -12.34, null],+ ['(12.34) ', -12.34, null],+ ['((12.34)) ', null, null],+ ['( 12.34 ) ', -12.34, null],+ ['(-12.34) ', null, null],+ ['1,234,443', 1234443, '#,##0'],+ ['1,234,4434', 12344434, '#,##0'], // Same as Sheets++ // percent (a)+ ['%12', 0.12, '0%'],+ ['%-12', -0.12, '0%'],+ ['-%12', -0.12, '0%'],+ ['-%-12', null, null], // this is what Sheets does+ ['12%', 0.12, '0%'],+ ['(12)%', -0.12, '0%'],+ ['(12%)', -0.12, '0%'],+ ['-12%', -0.12, '0%'],+ ['% 12', 0.12, '0%'], // Excel allows, Sheets does not+ ['12 %', 0.12, '0%'], // Excel allows, Sheets does not++ // "number"+ ['1,234', 1234, '#,##0'],+ ['1,234.', 1234, '#,##0.00'],+ ['1,234.00', 1234, '#,##0.00'],+ ['1,234.12', 1234.12, '#,##0.00'],+ ['1,234.56', 1234.56, '#,##0.00'],++ // percent (b)+ ['12.34%', 0.1234, '0.00%'],+ [' 12.34%', 0.1234, '0.00%'],+ ['12.34% ', 0.1234, '0.00%'],+ ['10.0% ', 0.1, '0.00%'],+ ['10.% ', 0.1, '0.00%'],+ ['12.50% ', 0.125, '0.00%'],+ ['12.345% ', 0.12345, '0.00%'],+ ['.12% ', 0.0012, '0.00%'],+ ['(.12)% ', -0.0012, '0.00%'],+ ['(.12%) ', -0.0012, '0.00%'],+ ['.(12)% ', null, null],+ ['0.12% ', 0.0012, '0.00%'],++ // scientific+ ['1.23e+2', 123, '0.00E+00'],+ ['12e0', 12, '0.00E+00'],+ ['12e-0', 12, '0.00E+00'],+ ['12e+0', 12, '0.00E+00'],+ ['1e5', 100000, '0.00E+00'],+ ['1e+5', 100000, '0.00E+00'],+ ['-1e+5', -100000, '0.00E+00'],+ ['- 1e+5', -100000, '0.00E+00'],+ ['(1e+5)', -100000, '0.00E+00'],+ ['1e-05', 0.00001, '0.00E+00'],+ ['-1e-05', -0.00001, '0.00E+00'],++ // euro (a)+ ['€1234', 1234, '€#,##0'],+ ['€1,234', 1234, '€#,##0'],+ ['€ 1234', 1234, '€#,##0'],+ ['€ 1234', 1234, '€#,##0'],+ ['-€1234', -1234, '€#,##0'],+ ['- € 1234', -1234, '€#,##0'],+ ['€-1234', -1234, '€#,##0'],+ ['-€-1234', null, null], // Sheets allows this+ ['(€1234)', -1234, '€#,##0'],+ ['€(1234)', -1234, '€#,##0'],+ // euro (b)+ ['€.1234', 0.1234, '€#,##0.00'],+ ['€1.1234', 1.1234, '€#,##0.00'],+ ['€1.0', 1, '€#,##0.00'],+ ['€1,234.', 1234, '€#,##0.00'],+ ['€1234.', 1234, '€#,##0.00'],+ ['€1234.00', 1234, '€#,##0.00'],+ ['€1234.56', 1234.56, '€#,##0.00'],+ ['€-1234.56', -1234.56, '€#,##0.00'],+ ['-€-1234.56', null, null], // Sheets allows this+ ['-€1234.56', -1234.56, '€#,##0.00'],+ ['€(1234.56)', -1234.56, '€#,##0.00'],+ [' € ( 1234.56 ) ', -1234.56, '€#,##0.00'],+ ['(€1234.56)', -1234.56, '€#,##0.00'],+ ['((€1234.56))', null, null],+ // euro (c)+ ['1234€', 1234, '#,##0€'],+ ['1,234€', 1234, '#,##0€'],+ ['-1234€', -1234, '#,##0€'],+ ['- 1234 €', -1234, '#,##0€'],+ ['(1234€)', -1234, '#,##0€'],+ ['( 1234 € )', -1234, '#,##0€'],+ ['(1234)€', -1234, '#,##0€'],+ ['( 1234 ) €', -1234, '#,##0€'],+ // euro (d)+ ['.1234€', 0.1234, '#,##0.00€'],+ ['1.1234€', 1.1234, '#,##0.00€'],+ ['1.0€', 1, '#,##0.00€'],+ ['1,234.€', 1234, '#,##0.00€'],+ ['1234.€', 1234, '#,##0.00€'],+ ['1234.00€', 1234, '#,##0.00€'],+ ['1234.56€', 1234.56, '#,##0.00€'],+ ['-1234.56€', -1234.56, '#,##0.00€'],+ ['- 1234.56 €', -1234.56, '#,##0.00€'],+ ['(1234.56)€', -1234.56, '#,##0.00€'],+ [' ( 1234.56 ) € ', -1234.56, '#,##0.00€'],+ ['(1234.56€)', -1234.56, '#,##0.00€'],+ ['( 1234.56 € )', -1234.56, '#,##0.00€'],+ ['((1234.56€))', null, null],++ // dollar (a)+ ['$1234', 1234, '$#,##0'],+ ['$1,234', 1234, '$#,##0'],+ ['$ 1234', 1234, '$#,##0'],+ ['$ 1234', 1234, '$#,##0'],+ ['-$1234', -1234, '$#,##0'],+ ['- $ 1234', -1234, '$#,##0'],+ ['$-1234', -1234, '$#,##0'],+ ['-$-1234', null, null], // Sheets allows this+ ['($1234)', -1234, '$#,##0'],+ ['$(1234)', -1234, '$#,##0'],+ // dollar (b)+ ['$.1234', 0.1234, '$#,##0.00'],+ ['$1.1234', 1.1234, '$#,##0.00'],+ ['$1.0', 1, '$#,##0.00'],+ ['$1,234.', 1234, '$#,##0.00'],+ ['$1234.', 1234, '$#,##0.00'],+ ['$1234.00', 1234, '$#,##0.00'],+ ['$1234.56', 1234.56, '$#,##0.00'],+ ['$-1234.56', -1234.56, '$#,##0.00'],+ ['-$-1234.56', null, null], // Sheets allows this+ ['-$1234.56', -1234.56, '$#,##0.00'],+ ['$(1234.56)', -1234.56, '$#,##0.00'],+ [' $ ( 1234.56 ) ', -1234.56, '$#,##0.00'],+ ['($1234.56)', -1234.56, '$#,##0.00'],+ ['(($1234.56))', null, null],+ // dollar (c)+ ['1234$', 1234, '#,##0$'],+ ['1,234$', 1234, '#,##0$'],+ ['-1234$', -1234, '#,##0$'],+ ['- 1234 $', -1234, '#,##0$'],+ ['(1234$)', -1234, '#,##0$'],+ ['( 1234 $ )', -1234, '#,##0$'],+ ['(1234)$', -1234, '#,##0$'],+ ['( 1234 ) $', -1234, '#,##0$'],+ // dollar (d)+ ['.1234$', 0.1234, '#,##0.00$'],+ ['1.1234$', 1.1234, '#,##0.00$'],+ ['1.0$', 1, '#,##0.00$'],+ ['1,234.$', 1234, '#,##0.00$'],+ ['1234.$', 1234, '#,##0.00$'],+ ['1234.00$', 1234, '#,##0.00$'],+ ['1234.56$', 1234.56, '#,##0.00$'],+ ['-1234.56$', -1234.56, '#,##0.00$'],+ ['- 1234.56 $', -1234.56, '#,##0.00$'],+ ['(1234.56)$', -1234.56, '#,##0.00$'],+ [' ( 1234.56 ) $ ', -1234.56, '#,##0.00$'],+ ['(1234.56$)', -1234.56, '#,##0.00$'],+ ['( 1234.56 $ )', -1234.56, '#,##0.00$'],+ ['((1234.56$))', null, null],++ // multiple currency symbols in input+ ['$$1234', null, null],+ ['$€1234', null, null],+ ['€$1234', null, null],++ // some rejects+ ['%12e+1', null, null],+ ['$12e+1', null, null],+ ['0x12', null, null],+ ['&h12', null, null],++ // dates+ ['07/05/82', 30137, 'mm/dd/yy'],+ ['07/05/1984', 30868, 'mm/dd/yyyy'],+ ['07/4/82', 30136, 'mm/dd/yy'],+ ['07/4/1984', 30867, 'mm/dd/yyyy'],+ ['07/October/82', 30231, 'dd/mmmm/yy'],+ ['07/October/1984', 30962, 'dd/mmmm/yyyy'],+ ['07/Nov/82', 30262, 'dd/mmm/yy'],+ ['07/Nov/1984', 30993, 'dd/mmm/yyyy'],+ ['6/05/82', 30107, 'mm/dd/yy'],+ ['6/05/1984', 30838, 'mm/dd/yyyy'],+ ['6/4/82', 30106, 'm/d/yy'],+ ['6/4/1984', 30837, 'm/d/yyyy'],+ ['6/October/82', 30230, 'd/mmmm/yy'],+ ['6/October/1984', 30961, 'd/mmmm/yyyy'],+ ['6/Nov/82', 30261, 'd/mmm/yy'],+ ['6/Nov/1984', 30992, 'd/mmm/yyyy'],+ ['05/07/82', 30078, 'mm/dd/yy'],+ ['05/07/1984', 30809, 'mm/dd/yyyy'],+ ['4/07/82', 30048, 'mm/dd/yy'],+ ['4/07/1984', 30779, 'mm/dd/yyyy'],+ ['October/07/82', 30231, 'mmmm/dd/yy'],+ ['October/07/1984', 30962, 'mmmm/dd/yyyy'],+ ['Nov/07/82', 30262, 'mmm/dd/yy'],+ ['Nov/07/1984', 30993, 'mmm/dd/yyyy'],+ ['05/6/82', 30077, 'mm/dd/yy'],+ ['05/6/1984', 30808, 'mm/dd/yyyy'],+ ['4/6/82', 30047, 'm/d/yy'],+ ['4/6/1984', 30778, 'm/d/yyyy'],+ ['October/6/82', 30230, 'mmmm/d/yy'],+ ['October/6/1984', 30961, 'mmmm/d/yyyy'],+ ['Nov/6/82', 30261, 'mmm/d/yy'],+ ['Nov/6/1984', 30992, 'mmm/d/yyyy'],+ ['82/07/05', null, null],+ ['1984/07/05', 30868, 'yyyy/mm/dd'],+ ['82/07/4', null, null],+ ['1984/07/4', 30867, 'yyyy/mm/dd'],+ ['82/07/October', null, null],+ ['1984/07/October', null, null],+ ['82/07/Nov', null, null],+ ['1984/07/Nov', null, null],+ ['82/6/05', null, null],+ ['1984/6/05', 30838, 'yyyy/mm/dd'],+ ['82/6/4', null, null],+ ['1984/6/4', 30837, 'yyyy/m/d'],+ ['82/6/October', null, null],+ ['1984/6/October', null, null],+ ['82/6/Nov', null, null],+ ['1984/6/Nov', null, null],+ ['07/82/05', null, null],+ ['07/1984/05', null, null],+ ['07/82/4', null, null],+ ['07/1984/4', null, null],+ ['07/82/October', null, null],+ ['07/1984/October', null, null],+ ['07/82/Nov', null, null],+ ['07/1984/Nov', null, null],+ ['6/82/05', null, null],+ ['6/1984/05', null, null],+ ['6/82/4', null, null],+ ['6/1984/4', null, null],+ ['6/82/October', null, null],+ ['6/1984/October', null, null],+ ['6/82/Nov', null, null],+ ['6/1984/Nov', null, null],+ ['05/82/07', null, null],+ ['05/1984/07', null, null],+ ['4/82/07', null, null],+ ['4/1984/07', null, null],+ ['October/82/07', null, null],+ ['October/1984/07', null, null],+ ['Nov/82/07', null, null],+ ['Nov/1984/07', null, null],+ ['05/82/6', null, null],+ ['05/1984/6', null, null],+ ['4/82/6', null, null],+ ['4/1984/6', null, null],+ ['October/82/6', null, null],+ ['October/1984/6', null, null],+ ['Nov/82/6', null, null],+ ['Nov/1984/6', null, null],+ ['82/05/07', null, null],+ ['1984/05/07', 30809, 'yyyy/mm/dd'],+ ['82/4/07', null, null],+ ['1984/4/07', 30779, 'yyyy/mm/dd'],+ ['82/October/07', 30231, 'yy/mmmm/dd'],+ ['1984/October/07', 30962, 'yyyy/mmmm/dd'],+ ['82/Nov/07', 30262, 'yy/mmm/dd'],+ ['1984/Nov/07', 30993, 'yyyy/mmm/dd'],+ ['82/05/6', null, null],+ ['1984/05/6', 30808, 'yyyy/mm/dd'],+ ['82/4/6', null, null],+ ['1984/4/6', 30778, 'yyyy/m/d'],+ ['82/October/6', 30230, 'yy/mmmm/d'],+ ['1984/October/6', 30961, 'yyyy/mmmm/d'],+ ['82/Nov/6', 30261, 'yy/mmm/d'],+ ['1984/Nov/6', 30992, 'yyyy/mmm/d'],+ ['07/05', currentYear + leapDay + 185, 'mm/dd'],+ ['07/4', currentYear + leapDay + 184, 'mm/dd'],+ ['07/October', currentYear + leapDay + 279, 'dd/mmmm'],+ ['07/Nov', currentYear + leapDay + 310, 'dd/mmm'],+ ['6/05', currentYear + leapDay + 155, 'mm/dd'],+ ['6/4', currentYear + leapDay + 154, 'm/d'],+ ['6/October', currentYear + leapDay + 278, 'd/mmmm'],+ ['6/Nov', currentYear + leapDay + 309, 'd/mmm'],+ ['07/82', null, null],+ ['07/1984', 30864, 'mm/yyyy'],+ ['6/82', null, null],+ ['6/1984', 30834, 'm/yyyy'],+ ['05/07', currentYear + leapDay + 126, 'mm/dd'],+ ['4/07', currentYear + leapDay + 96, 'mm/dd'],+ ['October/07', 39356, 'mmmm/yy'],+ ['Nov/07', 39387, 'mmm/yy'],+ ['05/6', currentYear + leapDay + 125, 'mm/dd'],+ ['4/6', currentYear + leapDay + 95, 'm/d'],+ ['October/6', null, null],+ ['Nov/6', null, null],+ ['05/82', null, null],+ ['05/1984', 30803, 'mm/yyyy'],+ ['4/82', null, null],+ ['4/1984', 30773, 'm/yyyy'],+ ['October/82', 30225, 'mmmm/yy'],+ ['October/1984', 30956, 'mmmm/yyyy'],+ ['Nov/82', 30256, 'mmm/yy'],+ ['Nov/1984', 30987, 'mmm/yyyy'],+ ['82/07', null, null],+ ['1984/07', 30864, 'yyyy/mm'],+ ['82/6', null, null],+ ['1984/6', 30834, 'yyyy/m'],+ ['82/05', null, null],+ ['1984/05', 30803, 'yyyy/mm'],+ ['82/4', null, null],+ ['1984/4', 30773, 'yyyy/m'],+ ['82/October', null, null],+ ['1984/October', 30956, 'yyyy/mmmm'],+ ['82/Nov', null, null],+ ['1984/Nov', 30987, 'yyyy/mmm'],+ // date leading zeros & date separators+ ['2000-1-1', 36526, 'yyyy-m-d'],+ ['2000-1-01', 36526, 'yyyy-mm-dd'],+ ['2000-01-1', 36526, 'yyyy-mm-dd'],+ ['2000-01-01', 36526, 'yyyy-mm-dd'],+ ['2000-10-10', 36809, 'yyyy-mm-dd'],+ ['2000-11-11', 36841, 'yyyy-mm-dd'],+ ['2000-11-1', 36831, 'yyyy-m-d'],+ ['2000-1-11', 36536, 'yyyy-m-d'],+ ['01 oct 1975', 27668, 'dd mmm yyyy'],+ ['1 oct 1975', 27668, 'd mmm yyyy'],+ ['10 oct 1975', 27677, 'd mmm yyyy'],+ ['11 oct 1975', 27678, 'd mmm yyyy'],+ // cannot mix and match date separators+ ['11-oct 1975', null, null],+ ['11/oct 1975', null, null],+ ['11-oct/1975', null, null],+ ['11 oct-1975', null, null],+ // invalid dates+ ['29 feb 1975', null, null], // not a leap year+ ['29 feb 2004', 38046, 'd mmm yyyy'], // actual leap year+ ['31 apr 2000', null, null], // apr has 30 days+ ['2000-13-01', null, null], // 13th month+ ['2000-00-01', null, null], // zero month+ ['10 oct 0000', null, null], // Google treats this as year 2000+ ['10 oct 00', 36809, 'd mmm yy'], // year 2000+ // year boundaries: Excel 1900-9999, Sheets 0-99999+ ['31 dec 1899', null, null], // 0 jan 1900 => 0 Excel date+ ['1 jan 1900', 1, 'd mmm yyyy'],+ ['2 jan 1900', 2, 'd mmm yyyy'],+ ['1899-12-31', null, null],+ ['1900-01-01', 1, 'yyyy-mm-dd'],+ ['1900-01-02', 2, 'yyyy-mm-dd'],+ ['1 jan 9999', 2958101, 'd mmm yyyy'],+ ['31 dec 9999', 2958465, 'd mmm yyyy'],+ ['1 jan 10000', null, null],+ ['9999-01-01', 2958101, 'yyyy-mm-dd'],+ ['9999-12-31', 2958465, 'yyyy-mm-dd'],+ ['10000-01-01', null, null],+ // 1900 leap year bug.+ ['27 Feb 1900', 58, 'd mmm yyyy'],+ ['28 Feb 1900', 59, 'd mmm yyyy'],+ ['29 Feb 1900', 60, 'd mmm yyyy'],+ ['1 Mar 1900', 61, 'd mmm yyyy'],+ ['2 Mar 1900', 62, 'd mmm yyyy'],++ // weekdays+ ['Sunday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['Monday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['Tuesday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['Wednesday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['Thursday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['Friday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['Saturday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['Sun 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['Mon 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['Tue 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['Wed 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['Thu 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['Fri 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['Sat 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['Sunday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['12 Sunday April 1984', null, null],+ ['12 April Sunday 1984', null, null],+ ['12 April 1984 Sunday', 30784, 'd mmmm yyyy dddd'],+ ['Thursday 12 April 1984', 30784, 'dddd d mmmm yyyy'],+ ['12 Thursday April 1984', null, null],+ ['12 April Thursday 1984', null, null],+ ['12 April 1984 Thursday', 30784, 'd mmmm yyyy dddd'],+ ['Sun 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['12 Sun April 1984', null, null],+ ['12 April Sun 1984', null, null],+ ['12 April 1984 Sun', 30784, 'd mmmm yyyy ddd'],+ ['Thu 12 April 1984', 30784, 'ddd d mmmm yyyy'],+ ['12 Thu April 1984', null, null],+ ['12 April Thu 1984', null, null],+ ['12 April 1984 Thu', 30784, 'd mmmm yyyy ddd'],+ ['Sun 82/October/6', 30230, 'ddd yy/mmmm/d'],+ ['Sun/82/October/6', null, null],+ ['82/October/6 Sun', 30230, 'yy/mmmm/d ddd'],+ ['82/Sun/October/6', null, null],+ ['Sunday, 12 April 1984', 30784, 'dddd, d mmmm yyyy'],+ ['12. April, 1984, Sunday', 30784, 'd. mmmm, yyyy, dddd'],+ ['12. April, 1984 Sunday', 30784, 'd. mmmm, yyyy dddd'],+ ['Sunday, 12 April 1984 10:45', 30784.447916666668, 'dddd, d mmmm yyyy hh:mm'],+ ['12 April 1984 Sunday 10:45', 30784.447916666668, 'd mmmm yyyy dddd hh:mm'],+ ['12 April 1984, Sunday 10:45', 30784.447916666668, 'd mmmm yyyy, dddd hh:mm'],+ ['12. April 1984', 30784, 'd. mmmm yyyy'],+ ['12. Apr. 1984', 30784, 'd. mmm. yyyy'],+ ['12, Apr, 1984', 30784, 'd, mmm, yyyy'],+ ['12- Apr- 1984', 30784, 'd- mmm- yyyy'],+ ['12 - Apr - 1984', 30784, 'd - mmm - yyyy'],+ ['12 - Apr - 1984', 30784, 'd - mmm - yyyy'],++ // period as seprator+ ['12.Apr.1984', 30784, 'd.mmm.yyyy'],+ ['12.4.1984', 31020, 'm.d.yyyy'],+ ['12. 1984', 31017, 'm. yyyy'],+ ['12.1984', 12.1984, null], // value parsing has priority (see text below)++ // comma is not a "real" seprator, it demands a space following it+ ['12,Apr,1984', null, null],+ ['12,4,1984', 1241984, '#,##0'], // value parsing has priority+ ['12, 1984', 31017, 'm, yyyy'],+ ['12,1984', 121984, '#,##0'], // value parsing has priority++ // time+ ['1 AM', 0.041666666666666664, 'h:mm AM/PM'],+ ['01 AM', 0.041666666666666664, 'hh:mm AM/PM'],+ ['10 AM', 0.4166666666666667, 'hh:mm AM/PM'],+ ['10:11 AM', 0.42430555555555555, 'hh:mm AM/PM'],+ ['1:2 AM', 0.043055555555555555, 'h:mm AM/PM'],+ ['01:02 AM', 0.043055555555555555, 'hh:mm AM/PM'],+ ['10:11:12 AM', 0.42444444444444446, 'hh:mm:ss AM/PM'],+ ['01:02:03 AM', 0.043090277777777776, 'hh:mm:ss AM/PM'],+ ['1:2:3 AM', 0.043090277777777776, 'h:mm:ss AM/PM'],+ ['24:11', 1.007638888888889, 'hh:mm'],+ ['24:11:12', 1.0077777777777779, 'hh:mm:ss'],+ ['1:2', 0.043055555555555555, 'h:mm'],+ ['1:2 A', 0.043055555555555555, 'h:mm AM/PM'],+ ['1:2 P', 0.5430555555555555, 'h:mm AM/PM'],+ ['1 A', 0.041666666666666664, 'h:mm AM/PM'],+ ['1 P', 0.5416666666666666, 'h:mm AM/PM'],+ ['10:11:12.123', 0.42444586805555556, 'hh:mm:ss'],+ ['10:11:12.12', 0.42444583333333336, 'hh:mm:ss'],+ ['10:11:12.1', 0.4244456018518518, 'hh:mm:ss'],+ ['AM 12:11', null, null],+ ['AM 12', null, null],+ ['1:2AM', 0.043055555555555555, 'h:mm AM/PM'],+ ['01:02AM', 0.043055555555555555, 'hh:mm AM/PM'],+ ['24:11:12 AM', null, null],+ ['10.456 AM', null, null],+ ['10:12.456', null, null],+ ['10:12:13.456', 0.4251557407407407, 'hh:mm:ss'],+ ['10:12:13.0123456789', 0.42515060585276504, 'hh:mm:ss'],+ ['00:00:00.0123456789', 0.00000014288980208333333, 'hh:mm:ss'],+ ['01:02:03', 0.043090277777777776, 'hh:mm:ss'],+ ['01:02:0', 0.043055555555555555, 'hh:mm:ss'],+ ['01:02:', 0.043055555555555555, 'hh:mm:ss'],+ ['01:02', 0.043055555555555555, 'hh:mm'],+ ['01:0', 0.041666666666666664, 'hh:mm'],+ ['01:', 0.041666666666666664, 'hh:mm:ss'],++ ['00:00 AM', 0, 'hh:mm AM/PM'],+ ['01:00 AM', 0.041666666666666664, 'hh:mm AM/PM'],+ ['02:00 AM', 0.08333333333333333, 'hh:mm AM/PM'],+ ['03:00 AM', 0.125, 'hh:mm AM/PM'],+ ['04:00 AM', 0.16666666666666666, 'hh:mm AM/PM'],+ ['05:00 AM', 0.20833333333333334, 'hh:mm AM/PM'],+ ['06:00 AM', 0.25, 'hh:mm AM/PM'],+ ['07:00 AM', 0.2916666666666667, 'hh:mm AM/PM'],+ ['08:00 AM', 0.3333333333333333, 'hh:mm AM/PM'],+ ['09:00 AM', 0.375, 'hh:mm AM/PM'],+ ['10:00 AM', 0.4166666666666667, 'hh:mm AM/PM'],+ ['11:00 AM', 0.4583333333333333, 'hh:mm AM/PM'],+ ['12:00 AM', 0, 'hh:mm AM/PM'],+ ['12:59 AM', 0.04097222222222222, 'hh:mm AM/PM'],+ ['12:60 AM', null, null],+ ['12:61 AM', null, null],+ ['12:99 AM', null, null],+ ['13:00 AM', null, null],+ ['14:00 AM', null, null],+ ['15:00 AM', null, null],+ ['16:00 AM', null, null],+ ['17:00 AM', null, null],+ ['18:00 AM', null, null],+ ['19:00 AM', null, null],+ ['20:00 AM', null, null],+ ['21:00 AM', null, null],+ ['22:00 AM', null, null],+ ['23:00 AM', null, null],+ ['24:00 AM', null, null],+ ['00:00 PM', 0.5, 'hh:mm AM/PM'],+ ['01:00 PM', 0.5416666666666666, 'hh:mm AM/PM'],+ ['02:00 PM', 0.5833333333333334, 'hh:mm AM/PM'],+ ['03:00 PM', 0.625, 'hh:mm AM/PM'],+ ['04:00 PM', 0.6666666666666666, 'hh:mm AM/PM'],+ ['05:00 PM', 0.7083333333333334, 'hh:mm AM/PM'],+ ['06:00 PM', 0.75, 'hh:mm AM/PM'],+ ['07:00 PM', 0.7916666666666666, 'hh:mm AM/PM'],+ ['08:00 PM', 0.8333333333333334, 'hh:mm AM/PM'],+ ['09:00 PM', 0.875, 'hh:mm AM/PM'],+ ['10:00 PM', 0.9166666666666666, 'hh:mm AM/PM'],+ ['11:00 PM', 0.9583333333333334, 'hh:mm AM/PM'],+ ['12:00 PM', 0.5, 'hh:mm AM/PM'],+ ['12:59 PM', 0.5409722222222222, 'hh:mm AM/PM'],+ ['12:60 PM', null, null],+ ['12:61 PM', null, null],+ ['12:99 PM', null, null],+ ['13:00 PM', null, null],+ ['14:00 PM', null, null],+ ['15:00 PM', null, null],+ ['16:00 PM', null, null],+ ['17:00 PM', null, null],+ ['18:00 PM', null, null],+ ['19:00 PM', null, null],+ ['20:00 PM', null, null],+ ['21:00 PM', null, null],+ ['22:00 PM', null, null],+ ['23:00 PM', null, null],+ ['24:00 PM', null, null],++ // date + time - composed of parsers above so testing needs are limited+ ['1984-09-10 11:12:13.1234', 30935.46681855787, 'yyyy-mm-dd hh:mm:ss'],+ ['07/05/1984 07:00 AM', 30868.291666666668, 'mm/dd/yyyy hh:mm AM/PM'],++ // whitespace+ [' -12.34 ', -12.34, null],+ [' 07/05/1984 ', 30868, 'mm/dd/yyyy'],+ [' 07/05/1984 07:00 AM ', 30868.291666666668, 'mm/dd/yyyy hh:mm AM/PM'],+ [' 07:00 AM ', 0.2916666666666667, 'hh:mm AM/PM'],++ // booleans+ ['TRUE', true, null],+ ['true', true, null],+ ['tRuE', true, null],+ [' TRUE ', true, null],+ ['FALSE', false, null],+ ['false', false, null],+ ['faLsE', false, null],+ [' FALSE ', false, null],+];++numfmtTest('parseNumber', (t) => {+ process.env.TZ = 'Asia/Calcutta';+ t.equal(getTimeZoneName(), 'India Standard Time', 'Timezone is IST');++ t.deepLooseEqual(+ parseNumber('-123'),+ { v: -123 },+ 'parseNumber parses numbers'+ );+ t.deepLooseEqual(+ parseNumber('1999.10.01'),+ null,+ 'parseNumber does not parse invalid numbers'+ );+ t.deepLooseEqual(+ parseNumber('1999-10-01'),+ null,+ 'parseNumber does not parse non-numbers'+ );++ t.deepLooseEqual(+ parseDate('1999-10-01 12:00:00'),+ { v: 36434.5, z: 'yyyy-mm-dd hh:mm:ss' },+ 'parseDate parses dates'+ );+ t.deepLooseEqual(+ parseDate('-123'),+ null,+ 'parseDate does not parse non-dates'+ );++ t.deepLooseEqual(+ parseTime('09:18 PM'),+ { v: 0.8875, z: 'hh:mm AM/PM' },+ 'parseTime parses time'+ );+ t.deepLooseEqual(+ parseTime('-123'),+ null,+ 'parseTime does not parse non-time'+ );++ t.deepLooseEqual(+ parseBool('False'),+ { v: false },+ 'parseBool parses booleans'+ );+ t.deepLooseEqual(+ parseBool('-123'),+ null,+ 'parseBool does not parse non-booleans'+ );++ t.deepLooseEqual(+ parseBool('False'),+ { v: false },+ 'parseBool parses booleans'+ );+ t.deepLooseEqual(+ parseBool('-123'),+ null,+ 'parseBool does not parse non-booleans'+ );++ t.deepLooseEqual(+ parseDate('5.2022'),+ null,+ 'parseDate does not parse "decimals"'+ );++ // test value parsing+ tests.forEach((ts) => {+ const [input, value] = ts;+ const p = parseValue(input);+ if (p == null) {+ t.equal(null, value, input);+ } else {+ t.equal(p.v, value, `valueOf("${input}")`);+ }+ });++ // test format selection+ tests.forEach((ts) => {+ const [input, , expectedZ] = ts;+ const p = parseValue(input);+ if (p == null) {+ t.equal(null, expectedZ, input);+ } else {+ t.equal(p.z ?? null, expectedZ, `formatOf("${input}")`);+ }+ });+});++numfmtTest('parseNumber locale support', (t) => {+ // can parse numbers in any language+ t.deepEqual(parseNumber('1,234,567.89', { locale: 'en' }), { v: 1234567.89, z: '#,##0.00' });+ t.deepEqual(parseNumber('1.234.567,89', { locale: 'en' }), null);++ t.deepEqual(parseNumber('1,234,567.89', { locale: 'de' }), null);+ t.deepEqual(parseNumber('1.234.567,89', { locale: 'de' }), { v: 1234567.89, z: '#,##0.00' });++ t.deepEqual(parseNumber('1,234,567.89', { locale: 'de' }), null);+ t.deepEqual(parseNumber('1.234.567,89', { locale: 'de' }), { v: 1234567.89, z: '#,##0.00' });++ addLocale({+ decimal: '·',+ group: '~',+ positive: 'ᐩ',+ negative: '÷',+ percent: '٪',+ exponent: 'X',+ }, 'xy');+ // t.format('#,##0.00', 1234567.89, '1~234~567·89', { locale: 'xy' });+ t.deepEqual(parseNumber('1~234~567·89', { locale: 'xy' }), { v: 1234567.89, z: '#,##0.00' });+ t.deepEqual(parseNumber('1\u202F234\u202F567,89', { locale: 'fr' }), { v: 1234567.89, z: '#,##0.00' });+ t.deepEqual(parseNumber('1٬234٬567٫89', { locale: 'ar' }), { v: 1234567.89, z: '#,##0.00' });+});++numfmtTest('parseDate locale support', (t) => {+ // can parse dates in any language+ t.deepEqual(parseDate('Wednesday, 13. march 1989', { locale: 'en' }), { v: 32580, z: 'dddd, d. mmmm yyyy' });+ t.deepEqual(parseDate('sreda, 13. marec 1989', { locale: 'sl' }), { v: 32580, z: 'dddd, d. mmmm yyyy' });+ t.deepEqual(parseDate('miðvikudagur, 13. mars 1989', { locale: 'is' }), { v: 32580, z: 'dddd, d. mmmm yyyy' });++ t.deepEqual(parseDate('Fri, 23 Dec 1988', { locale: 'en' }), { v: 32500, z: 'ddd, d mmm yyyy' });+ t.deepEqual(parseDate('Fös, 23 DES 1988', { locale: 'is' }), { v: 32500, z: 'ddd, d mmm yyyy' });+ t.deepEqual(parseDate('vin, 23 dec 1988', { locale: 'ro' }), { v: 32500, z: 'ddd, d mmm yyyy' });++ t.deepEqual(parseDate('31/febrero/27', { locale: 'es_UY' }), { v: 11381, z: 'yy/mmmm/d' });++ t.deepEqual(parseDate('kedd 29 február 1916', { locale: 'hu' }), { v: 5904, z: 'dddd d mmmm yyyy' });+ t.deepEqual(parseDate('01 oct 1975', { locale: 'eb' }), { v: 27668, z: 'dd mmm yyyy' });++ const fm = [+ 'dddd d mmmm yyyy',+ 'ddd d mmmm yyyy',+ 'd mmmm yyyy ddd',+ 'dddd, d mmmm yyyy',+ 'd mmmm yyyy, dddd hh:mm',+ 'd - mmm - yyyy',+ 'd.mmm.yyyy',+ 'm.d.yyyy',+ 'm. yyyy',+ 'yyyy/mmmm',+ 'mmmm/yy',+ 'yy/mmmm/d',+ ];+ const loc = listLocales().filter((l) => l !== 'xx' && l !== 'xy');+ for (const l of loc) {+ const opt = { locale: l };+ for (const f of fm) {+ const o = format(f, 3290.1278435, opt);+ const parsed = parseDate(o, opt);+ t.ok(!!parsed, `Locale: "${f}" in ${l} (${o})`);+ }+ // locales with preferMDY should allow dates that fit, else only allow DMY+ const MDY = getLocale(l)?.preferMDY;+ if (MDY) {+ t.deepEqual(parseDate('07/05/82', opt), { v: 30137, z: 'mm/dd/yy' }, `${l} prefers MDY (07/05/82)`);+ t.deepEqual(parseDate('31/05/82', opt), null, `${l} prefers MDY (31/05/82)`);+ t.deepEqual(parseDate('05/31/82', opt), { v: 30102, z: 'mm/dd/yy' }, `${l} prefers MDY (05/31/82)`);+ } else {+ t.deepEqual(parseDate('07/05/82', opt), { v: 30078, z: 'dd/mm/yy' }, `${l} prefers DMY (07/05/82)`);+ t.deepEqual(parseDate('07/31/82', opt), null, `${l} prefers DMY (07/31/82)`);+ t.deepEqual(parseDate('31/05/82', opt), { v: 30102, z: 'dd/mm/yy' }, `${l} prefers MDY (31/05/82)`);+ }+ }+});++numfmtTest('parseTime locale support', (t) => {+ t.deepEqual(parseTime('01:31 a', { locale: 'fi' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'fi: 01:31 a');+ t.deepEqual(parseTime('01:31 am', { locale: 'fi' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'fi: 01:31 am');+ t.deepEqual(parseTime('01:31 ap.', { locale: 'fi' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'fi: 01:31 ap.');+ t.deepEqual(parseTime('01:31 ap', { locale: 'fi' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'fi: 01:31 ap');+ t.deepEqual(parseTime('01:31 a', { locale: 'is' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'is: 01:31 a');+ t.deepEqual(parseTime('01:31 am', { locale: 'is' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'is: 01:31 am');+ t.deepEqual(parseTime('01:31 fh', { locale: 'is' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'is: 01:31 fh');+ t.deepEqual(parseTime('01:31 fh.', { locale: 'is' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'is: 01:31 fh.');+ t.deepEqual(parseTime('01:31 f.h.', { locale: 'is' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'is: 01:31 f.h.');+ t.deepEqual(parseTime('01:31 f. h.', { locale: 'is' }), { v: 0.06319444444444444, z: 'hh:mm AM/PM' }, 'is: 01:31 f. h.');+});++numfmtTest('parseBool locale support', (t) => {+ t.deepEqual(parseBool('TRUE', { locale: 'en' }), { v: true }, 'en: TRUE');+ t.deepEqual(parseBool('FALSE', { locale: 'en' }), { v: false }, 'en: FALSE');+ t.deepEqual(parseBool('TRUE', { locale: 'jn' }), { v: true }, 'jn: TRUE');+ t.deepEqual(parseBool('FALSE', { locale: 'jn' }), { v: false }, 'jn: FALSE');+ t.deepEqual(parseBool('TRUE', { locale: 'hu' }), { v: true }, 'hu: TRUE');+ t.deepEqual(parseBool('FALSE', { locale: 'hu' }), { v: false }, 'hu: FALSE');+ t.deepEqual(parseBool('IGAZ', { locale: 'hu' }), { v: true }, 'hu: IGAZ');+ t.deepEqual(parseBool('HAMIS', { locale: 'hu' }), { v: false }, 'hu: HAMIS');+});diff --git a/packages/core/src/shared/numfmt/__tests__/pattern-parser.spec.ts b/packages/core/src/shared/numfmt/__tests__/pattern-parser.spec.tsnew file mode 100644index 0000000000..d0f9e36194--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/pattern-parser.spec.ts@@ -0,0 +1,74 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { describe, expect, it } from 'vitest';+import { dateInfo, info } from '../format-info';+import { parsePattern } from '../parse-pattern';+import { tokenize } from '../tokenize';++describe('numfmt pattern parser', () => {+ it('tokenizes number operators', () => {+ expect(tokenize('0.00').map(({ type, value, raw }) => ({ type, value, raw }))).toEqual([+ { type: 'zero', value: '0', raw: '0' },+ { type: 'point', value: '.', raw: '.' },+ { type: 'zero', value: '0', raw: '0' },+ { type: 'zero', value: '0', raw: '0' },+ ]);+ });++ it('partitions conditions and colors', () => {+ const parsed = parsePattern('[Red][>=10]0.00;[Blue]-0.00');+ expect(parsed.partitions).toHaveLength(2);+ expect(parsed.partitions[0]).toMatchObject({+ color: 'red',+ condition: ['>=', 10],+ frac_max: 2,+ });+ });++ it('reports format metadata', () => {+ const number = parsePattern('#,##0.00');+ expect(info(number.partitions)).toEqual({+ type: 'grouped',+ isDate: false,+ isText: false,+ isPercent: false,+ maxDecimals: 2,+ scale: 1,+ color: 0,+ parentheses: 0,+ grouped: 1,+ code: ',2',+ level: 10.2,+ });++ const date = parsePattern('yyyy-mm-dd hh:mm:ss');+ expect(dateInfo(date.partitions)).toEqual({+ year: true,+ month: true,+ day: true,+ hours: true,+ minutes: true,+ seconds: true,+ clockType: 24,+ });+ });+});diff --git a/packages/core/src/shared/numfmt/__tests__/robust-mode.spec.ts b/packages/core/src/shared/numfmt/__tests__/robust-mode.spec.tsnew file mode 100644index 0000000000..c9ce3f5bcb--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/robust-mode.spec.ts@@ -0,0 +1,47 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { format, formatColor, isDateFormat } from '../api';+import { numfmtTest } from './test-utils';++const excelOpts = { dateSpanLarge: false, dateErrorNumber: false };++numfmtTest('Robust mode', (t) => {+ t.equal(format('dddd, dd. mmmm yyy', -1, excelOpts), '######');++ // these things should throw+ t.throws(() => format('a;b;c;d;', 0, excelOpts), 'a;b;c;d;');+ t.throws(() => format('y 0', 0, excelOpts), 'y 0');++ // ...but not in robust mode+ const opts = { locale: 'en', throws: false, ...excelOpts };+ t.equal(format('a;b;c;d;', 0, opts), '######', 'format does not throw with "a;b;c;d;"');+ t.equal(format('y 0', 1, opts), '######', 'format does not throw with "y 0"');+ t.equal(format('dddd, dd. mmmm yyy', -1, opts), '######', 'format does not throw with "dddd, dd. mmmm yyy"');+ t.equal(format('y 0', 1, opts), '######', 'format does not throw with "dddd, dd. mmmm yyy"');++ t.equal(formatColor('a;b;c;d;', 0, opts), null, 'formatColor does not throw');+ t.equal(+ (isDateFormat as (pattern: string, options?: unknown) => boolean)('a;b;c;d;', opts),+ false,+ 'isDateFormat does not throw'+ );+});diff --git a/packages/core/src/shared/numfmt/__tests__/serial-date.spec.ts b/packages/core/src/shared/numfmt/__tests__/serial-date.spec.tsnew file mode 100644index 0000000000..34cb289dde--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/serial-date.spec.ts@@ -0,0 +1,107 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { dateFromSerial, dateToSerial } from '../api';+import { getTimeZoneName, numfmtTest } from './test-utils';++/* globals process */++function round(n: number) {+ return Math.round(n * 1e10) / 1e10;+}++numfmtTest('dateToSerial (Date):', (t) => {+ process.env.TZ = 'Asia/Calcutta';+ t.equal(getTimeZoneName(), 'India Standard Time', 'Timezone is IST');++ const testYMD = (y: number, m: number, d: number, hh: number, mm: number, ss: number, tz = false) => {+ const dt = new Date(y, m - 1, d, hh, mm, ss);+ return round(dateToSerial(dt, { ignoreTimezone: tz })!);+ };++ t.equal(testYMD(1978, 5, 17, 10, 25, 30, true), 28627.2052083333, '[1978, 5, 17, 10, 25, 30] ignoreTimezone');+ t.equal(testYMD(1978, 5, 17, 10, 25, 30), 28627.434375, '[1978, 5, 17, 10, 25, 30]');++ t.equal(testYMD(2022, 3, 1, 13, 53, 11), 44621.578599537, '[2022, 3, 1, 13, 53, 11]');+ t.equal(testYMD(2022, 3, 1, 13, 53, 11, true), 44621.3494328704, '[2022, 3, 1, 13, 53, 11] ignoreTimezone');++ t.equal(testYMD(1900, 1, 1, 0, 0, 0), 1, '[1900, 1, 1, 0, 0, 0]');+ t.equal(testYMD(1900, 1, 1, 0, 0, 0, true), 0.7769675926, '[1900, 1, 1, 0, 0, 0] ignoreTimezone');++ t.equal(testYMD(1950, 1, 1, 0, 0, 0), 18264, '[1950, 1, 1, 0, 0, 0]');+ t.equal(testYMD(1950, 1, 1, 0, 0, 0, true), 18263.7708333333, '[1950, 1, 1, 0, 0, 0] ignoreTimezone');++ t.equal(testYMD(2000, 1, 1, 0, 0, 0), 36526, '[2000, 1, 1, 0, 0, 0]');+ t.equal(testYMD(2000, 1, 1, 0, 0, 0, true), 36525.7708333333, '[2000, 1, 1, 0, 0, 0] ignoreTimezone');+});++numfmtTest('dateToSerial (Array):', (t) => {+ const testYMD = (y: number, m: number, d: number, hh: number, mm: number, ss: number, tz = false) => {+ return round(dateToSerial(+ [y, m, d, hh, mm, ss],+ { ignoreTimezone: tz }+ )!);+ };+ t.equal(testYMD(1978, 5, 17, 10, 25, 30, false), 28627.434375, '[1978, 5, 17, 10, 25, 30]');+ t.equal(testYMD(1978, 5, 17, 10, 25, 30, true), 28627.434375, '[1978, 5, 17, 10, 25, 30]');+ t.equal(testYMD(2022, 3, 1, 13, 53, 11, false), 44621.578599537, '[2022, 3, 1, 13, 53, 11]');+ t.equal(testYMD(2022, 3, 1, 13, 53, 11, true), 44621.578599537, '[2022, 3, 1, 13, 53, 11]');+ t.equal(testYMD(1900, 1, 1, 0, 0, 0, false), 1, '[1900, 1, 1, 0, 0, 0]');+ t.equal(testYMD(1900, 1, 1, 0, 0, 0, true), 1, '[1900, 1, 1, 0, 0, 0]');+ t.equal(testYMD(1950, 1, 1, 0, 0, 0, false), 18264, '[1950, 1, 1, 0, 0, 0]');+ t.equal(testYMD(1950, 1, 1, 0, 0, 0, true), 18264, '[1950, 1, 1, 0, 0, 0]');+ t.equal(testYMD(2000, 1, 1, 0, 0, 0, false), 36526, '[2000, 1, 1, 0, 0, 0]');+ t.equal(testYMD(2000, 1, 1, 0, 0, 0, true), 36526, '[2000, 1, 1, 0, 0, 0]');+});++numfmtTest('dateFromSerial:', (t) => {+ process.env.TZ = 'Europe/Amsterdam';+ t.ok(+ /^Central European (Standard|Summer) Time$/.test(getTimeZoneName()),+ 'Timezone is what we think it is'+ );++ t.deepLooseEqual(+ dateFromSerial(1234),+ [1903, 5, 18, 0, 0, 0],+ 'dateFromSerial(1234)'+ );+ t.deepLooseEqual(+ dateFromSerial(1234.567),+ [1903, 5, 18, 13, 36, 28],+ 'dateFromSerial(1234)'+ );+ t.deepLooseEqual(+ dateFromSerial(12),+ [1900, 1, 12, 0, 0, 0],+ 'dateFromSerial(12)'+ );+ t.deepLooseEqual(+ dateFromSerial(24052.8361),+ [1965, 11, 6, 20, 3, 59],+ 'dateFromSerial(24052.8361)'+ );+ t.deepLooseEqual(+ dateFromSerial(42341),+ [2015, 12, 3, 0, 0, 0],+ 'dateFromSerial(42341)'+ );+});diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-cal.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-cal.spec.tsnew file mode 100644index 0000000000..007a62ab12--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-cal.spec.ts@@ -0,0 +1,24 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTableTest } from './test-utils';++numfmtTableTest('SSF calendar table', 'cal-updated.tsv.gz');diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-comma.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-comma.spec.tsnew file mode 100644index 0000000000..9a120e41e6--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-comma.spec.ts@@ -0,0 +1,150 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++// tests converted from SSF++numfmtTest('Exponential: #.0000,,,', (t) => {+ t.format('#.0000,,,', 0.99, '.0000');+ t.format('#.0000,,,', 1.2345, '.0000');+ t.format('#.0000,,,', 12.345, '.0000');+ t.format('#.0000,,,', 123.456, '.0000');+ t.format('#.0000,,,', 1234, '.0000');+ t.format('#.0000,,,', 12345, '.0000');+ t.format('#.0000,,,', 123456, '.0001');+ t.format('#.0000,,,', 1234567, '.0012');+ t.format('#.0000,,,', 12345678, '.0123');+ t.format('#.0000,,,', 123456789, '.1235');+ t.format('#.0000,,,', 1234567890, '1.2346');+ t.format('#.0000,,,', 12345678901, '12.3457');+ t.format('#.0000,,,', 123456789012, '123.4568');+ t.format('#.0000,,,', 4321, '.0000');+ t.format('#.0000,,,', 4321234, '.0043');+});++numfmtTest('Exponential: #.0000,,', (t) => {+ t.format('#.0000,,', 0.99, '.0000');+ t.format('#.0000,,', 1.2345, '.0000');+ t.format('#.0000,,', 12.345, '.0000');+ t.format('#.0000,,', 123.456, '.0001');+ t.format('#.0000,,', 1234, '.0012');+ t.format('#.0000,,', 12345, '.0123');+ t.format('#.0000,,', 123456, '.1235');+ t.format('#.0000,,', 1234567, '1.2346');+ t.format('#.0000,,', 12345678, '12.3457');+ t.format('#.0000,,', 123456789, '123.4568');+ t.format('#.0000,,', 1234567890, '1234.5679');+ t.format('#.0000,,', 12345678901, '12345.6789');+ t.format('#.0000,,', 123456789012, '123456.7890');+ t.format('#.0000,,', 4321, '.0043');+ t.format('#.0000,,', 4321234, '4.3212');+});++numfmtTest('Exponential: #.0000,', (t) => {+ t.format('#.0000,', 0.99, '.0010');+ t.format('#.0000,', 1.2345, '.0012');+ t.format('#.0000,', 12.345, '.0123');+ t.format('#.0000,', 123.456, '.1235');+ t.format('#.0000,', 1234, '1.2340');+ t.format('#.0000,', 12345, '12.3450');+ t.format('#.0000,', 123456, '123.4560');+ t.format('#.0000,', 1234567, '1234.5670');+ t.format('#.0000,', 12345678, '12345.6780');+ t.format('#.0000,', 123456789, '123456.7890');+ t.format('#.0000,', 1234567890, '1234567.8900');+ t.format('#.0000,', 12345678901, '12345678.9010');+ t.format('#.0000,', 123456789012, '123456789.0120');+ t.format('#.0000,', 4321, '4.3210');+ t.format('#.0000,', 4321234, '4321.2340');+});++numfmtTest('Exponential: #,##0.0', (t) => {+ t.format('#,##0.0', 0.99, '1.0');+ t.format('#,##0.0', 1.2345, '1.2');+ t.format('#,##0.0', 12.345, '12.3');+ t.format('#,##0.0', 123.456, '123.5');+ t.format('#,##0.0', 1234, '1,234.0');+ t.format('#,##0.0', 12345, '12,345.0');+ t.format('#,##0.0', 123456, '123,456.0');+ t.format('#,##0.0', 1234567, '1,234,567.0');+ t.format('#,##0.0', 12345678, '12,345,678.0');+ t.format('#,##0.0', 123456789, '123,456,789.0');+ t.format('#,##0.0', 1234567890, '1,234,567,890.0');+ t.format('#,##0.0', 12345678901, '12,345,678,901.0');+ t.format('#,##0.0', 123456789012, '123,456,789,012.0');+ t.format('#,##0.0', 4321, '4,321.0');+ t.format('#,##0.0', 4321234, '4,321,234.0');+});++numfmtTest('Exponential: ###,##0', (t) => {+ t.format('###,##0', 0.99, '1');+ t.format('###,##0', 1.2345, '1');+ t.format('###,##0', 12.345, '12');+ t.format('###,##0', 123.456, '123');+ t.format('###,##0', 1234, '1,234');+ t.format('###,##0', 12345, '12,345');+ t.format('###,##0', 123456, '123,456');+ t.format('###,##0', 1234567, '1,234,567');+ t.format('###,##0', 12345678, '12,345,678');+ t.format('###,##0', 123456789, '123,456,789');+ t.format('###,##0', 1234567890, '1,234,567,890');+ t.format('###,##0', 12345678901, '12,345,678,901');+ t.format('###,##0', 123456789012, '123,456,789,012');+ t.format('###,##0', 4321, '4,321');+ t.format('###,##0', 4321234, '4,321,234');+});++numfmtTest('Exponential: ###,###', (t) => {+ t.format('###,###', 0.99, '1');+ t.format('###,###', 1.2345, '1');+ t.format('###,###', 12.345, '12');+ t.format('###,###', 123.456, '123');+ t.format('###,###', 1234, '1,234');+ t.format('###,###', 12345, '12,345');+ t.format('###,###', 123456, '123,456');+ t.format('###,###', 1234567, '1,234,567');+ t.format('###,###', 12345678, '12,345,678');+ t.format('###,###', 123456789, '123,456,789');+ t.format('###,###', 1234567890, '1,234,567,890');+ t.format('###,###', 12345678901, '12,345,678,901');+ t.format('###,###', 123456789012, '123,456,789,012');+ t.format('###,###', 4321, '4,321');+ t.format('###,###', 4321234, '4,321,234');+});++numfmtTest('Exponential: #,###.00', (t) => {+ t.format('#,###.00', 0.99, '.99');+ t.format('#,###.00', 1.2345, '1.23');+ t.format('#,###.00', 12.345, '12.35');+ t.format('#,###.00', 123.456, '123.46');+ t.format('#,###.00', 1234, '1,234.00');+ t.format('#,###.00', 12345, '12,345.00');+ t.format('#,###.00', 123456, '123,456.00');+ t.format('#,###.00', 1234567, '1,234,567.00');+ t.format('#,###.00', 12345678, '12,345,678.00');+ t.format('#,###.00', 123456789, '123,456,789.00');+ t.format('#,###.00', 1234567890, '1,234,567,890.00');+ t.format('#,###.00', 12345678901, '12,345,678,901.00');+ t.format('#,###.00', 123456789012, '123,456,789,012.00');+ t.format('#,###.00', 4321, '4,321.00');+ t.format('#,###.00', 4321234, '4,321,234.00');+});diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-dates.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-dates.spec.tsnew file mode 100644index 0000000000..03c44aadaf--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-dates.spec.ts@@ -0,0 +1,24 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTableTest } from './test-utils';++numfmtTableTest('SSF date table', 'ssf-dates.tsv.gz');diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-exp.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-exp.spec.tsnew file mode 100644index 0000000000..c27f407bc4--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-exp.spec.ts@@ -0,0 +1,216 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++// tests converted from SSF++numfmtTest('Exponential: #0.0E+0', (t) => {+ t.format('#0.0E+0', 1.23457e-13, '12.3E-14');+ t.format('#0.0E+0', 1.23457e-12, '1.2E-12');+ t.format('#0.0E+0', 1.23457e-11, '12.3E-12');+ t.format('#0.0E+0', 1.23457e-10, '1.2E-10');+ t.format('#0.0E+0', 1.23457e-09, '12.3E-10');+ t.format('#0.0E+0', 1.23457e-08, '1.2E-8');+ t.format('#0.0E+0', 0.000000123457, '12.3E-8');+ t.format('#0.0E+0', 0.00000123457, '1.2E-6');+ t.format('#0.0E+0', 0.0000123457, '12.3E-6');+ t.format('#0.0E+0', 0.000123457, '1.2E-4');+ t.format('#0.0E+0', 0.001234568, '12.3E-4');+ t.format('#0.0E+0', 0.012345679, '1.2E-2');+ t.format('#0.0E+0', 0.123456789, '12.3E-2');+ t.format('#0.0E+0', 1.23456789, '1.2E+0');+ t.format('#0.0E+0', 12.3456789, '12.3E+0');+ t.format('#0.0E+0', 123.456789, '1.2E+2');+ t.format('#0.0E+0', 1234.56789, '12.3E+2');+ t.format('#0.0E+0', 12345.6789, '1.2E+4');+ t.format('#0.0E+0', 123456.789, '12.3E+4');+ t.format('#0.0E+0', 1234567.89, '1.2E+6');+ t.format('#0.0E+0', 12345678.9, '12.3E+6');+ t.format('#0.0E+0', 123456789, '1.2E+8');+ t.format('#0.0E+0', 1234567890, '12.3E+8');+ t.format('#0.0E+0', 12345678900, '1.2E+10');+ t.format('#0.0E+0', 123456789000, '12.3E+10');+ t.format('#0.0E+0', 1234567890000, '1.2E+12');+ t.format('#0.0E+0', 12345678900000, '12.3E+12');+ t.format('#0.0E+0', 123456789000000, '1.2E+14');+ t.format('#0.0E+0', 1234567890000000, '12.3E+14');+ t.format('#0.0E+0', 12345678900000000, '1.2E+16');+ t.format('#0.0E+0', 123456789000000000, '12.3E+16');+ t.format('#0.0E+0', 1234567890000000000, '1.2E+18');+ t.format('#0.0E+0', 12345678900000000000, '12.3E+18');+ t.format('#0.0E+0', 123456789000000000000, '1.2E+20');+ t.format('#0.0E+0', 1234567890000000000000, '12.3E+20');+ t.format('#0.0E+0', 12345678900000000000000, '1.2E+22');+ t.format('#0.0E+0', 123456789000000000000000, '12.3E+22');+ t.format('#0.0E+0', 1234567890000000000000000, '1.2E+24');+ t.format('#0.0E+0', 12345678900000000000000000, '12.3E+24');+ t.format('#0.0E+0', 123456789000000000000000000, '1.2E+26');+ t.format('#0.0E+0', 1234567890000000000000000000, '12.3E+26');+ t.format('#0.0E+0', 12345678900000000000000000000, '1.2E+28');+ t.format('#0.0E+0', 123456789000000000000000000000, '12.3E+28');+ t.format('#0.0E+0', 1234567890000000000000000000000, '1.2E+30');+ t.format('#0.0E+0', 12345678900000000000000000000000, '12.3E+30');+});++numfmtTest('Exponential: ##0.0E+0', (t) => {+ t.format('##0.0E+0', 1.23457e-13, '123.5E-15');+ t.format('##0.0E+0', 1.23457e-12, '1.2E-12');+ t.format('##0.0E+0', 1.23457e-11, '12.3E-12');+ t.format('##0.0E+0', 1.23457e-10, '123.5E-12');+ t.format('##0.0E+0', 1.23457e-09, '1.2E-9');+ t.format('##0.0E+0', 1.23457e-08, '12.3E-9');+ t.format('##0.0E+0', 0.000000123457, '123.5E-9');+ t.format('##0.0E+0', 0.00000123457, '1.2E-6');+ t.format('##0.0E+0', 0.0000123457, '12.3E-6');+ t.format('##0.0E+0', 0.000123457, '123.5E-6');+ t.format('##0.0E+0', 0.001234568, '1.2E-3');+ t.format('##0.0E+0', 0.012345679, '12.3E-3');+ t.format('##0.0E+0', 0.123456789, '123.5E-3');+ t.format('##0.0E+0', 1.23456789, '1.2E+0');+ t.format('##0.0E+0', 12.3456789, '12.3E+0');+ t.format('##0.0E+0', 123.456789, '123.5E+0');+ t.format('##0.0E+0', 1234.56789, '1.2E+3');+ t.format('##0.0E+0', 12345.6789, '12.3E+3');+ t.format('##0.0E+0', 123456.789, '123.5E+3');+ t.format('##0.0E+0', 1234567.89, '1.2E+6');+ t.format('##0.0E+0', 12345678.9, '12.3E+6');+ t.format('##0.0E+0', 123456789, '123.5E+6');+ t.format('##0.0E+0', 1234567890, '1.2E+9');+ t.format('##0.0E+0', 12345678900, '12.3E+9');+ t.format('##0.0E+0', 123456789000, '123.5E+9');+ t.format('##0.0E+0', 1234567890000, '1.2E+12');+ t.format('##0.0E+0', 12345678900000, '12.3E+12');+ t.format('##0.0E+0', 123456789000000, '123.5E+12');+ t.format('##0.0E+0', 1234567890000000, '1.2E+15');+ t.format('##0.0E+0', 12345678900000000, '12.3E+15');+ t.format('##0.0E+0', 123456789000000000, '123.5E+15');+ t.format('##0.0E+0', 1234567890000000000, '1.2E+18');+ t.format('##0.0E+0', 12345678900000000000, '12.3E+18');+ t.format('##0.0E+0', 123456789000000000000, '123.5E+18');+ t.format('##0.0E+0', 1234567890000000000000, '1.2E+21');+ t.format('##0.0E+0', 12345678900000000000000, '12.3E+21');+ t.format('##0.0E+0', 123456789000000000000000, '123.5E+21');+ t.format('##0.0E+0', 1234567890000000000000000, '1.2E+24');+ t.format('##0.0E+0', 12345678900000000000000000, '12.3E+24');+ t.format('##0.0E+0', 123456789000000000000000000, '123.5E+24');+ t.format('##0.0E+0', 1234567890000000000000000000, '1.2E+27');+ t.format('##0.0E+0', 12345678900000000000000000000, '12.3E+27');+ t.format('##0.0E+0', 123456789000000000000000000000, '123.5E+27');+ t.format('##0.0E+0', 1234567890000000000000000000000, '1.2E+30');+ t.format('##0.0E+0', 12345678900000000000000000000000, '12.3E+30');+});++numfmtTest('Exponential: ###0.0E+0', (t) => {+ t.format('###0.0E+0', 1.23457e-13, '1234.6E-16');+ t.format('###0.0E+0', 1.23457e-12, '1.2E-12');+ t.format('###0.0E+0', 1.23457e-11, '12.3E-12');+ t.format('###0.0E+0', 1.23457e-10, '123.5E-12');+ t.format('###0.0E+0', 1.23457e-09, '1234.6E-12');+ t.format('###0.0E+0', 1.23457e-08, '1.2E-8');+ t.format('###0.0E+0', 0.000000123457, '12.3E-8');+ t.format('###0.0E+0', 0.00000123457, '123.5E-8');+ t.format('###0.0E+0', 0.0000123457, '1234.6E-8');+ t.format('###0.0E+0', 0.000123457, '1.2E-4');+ t.format('###0.0E+0', 0.001234568, '12.3E-4');+ t.format('###0.0E+0', 0.012345679, '123.5E-4');+ t.format('###0.0E+0', 0.123456789, '1234.6E-4');+ t.format('###0.0E+0', 1.23456789, '1.2E+0');+ t.format('###0.0E+0', 12.3456789, '12.3E+0');+ t.format('###0.0E+0', 123.456789, '123.5E+0');+ t.format('###0.0E+0', 1234.56789, '1234.6E+0');+ t.format('###0.0E+0', 12345.6789, '1.2E+4');+ t.format('###0.0E+0', 123456.789, '12.3E+4');+ t.format('###0.0E+0', 1234567.89, '123.5E+4');+ t.format('###0.0E+0', 12345678.9, '1234.6E+4');+ t.format('###0.0E+0', 123456789, '1.2E+8');+ t.format('###0.0E+0', 1234567890, '12.3E+8');+ t.format('###0.0E+0', 12345678900, '123.5E+8');+ t.format('###0.0E+0', 123456789000, '1234.6E+8');+ t.format('###0.0E+0', 1234567890000, '1.2E+12');+ t.format('###0.0E+0', 12345678900000, '12.3E+12');+ t.format('###0.0E+0', 123456789000000, '123.5E+12');+ t.format('###0.0E+0', 1234567890000000, '1234.6E+12');+ t.format('###0.0E+0', 12345678900000000, '1.2E+16');+ t.format('###0.0E+0', 123456789000000000, '12.3E+16');+ t.format('###0.0E+0', 1234567890000000000, '123.5E+16');+ t.format('###0.0E+0', 12345678900000000000, '1234.6E+16');+ t.format('###0.0E+0', 123456789000000000000, '1.2E+20');+ t.format('###0.0E+0', 1234567890000000000000, '12.3E+20');+ t.format('###0.0E+0', 12345678900000000000000, '123.5E+20');+ t.format('###0.0E+0', 123456789000000000000000, '1234.6E+20');+ t.format('###0.0E+0', 1234567890000000000000000, '1.2E+24');+ t.format('###0.0E+0', 12345678900000000000000000, '12.3E+24');+ t.format('###0.0E+0', 123456789000000000000000000, '123.5E+24');+ t.format('###0.0E+0', 1234567890000000000000000000, '1234.6E+24');+ t.format('###0.0E+0', 12345678900000000000000000000, '1.2E+28');+ t.format('###0.0E+0', 123456789000000000000000000000, '12.3E+28');+ t.format('###0.0E+0', 1234567890000000000000000000000, '123.5E+28');+ t.format('###0.0E+0', 12345678900000000000000000000000, '1234.6E+28');+});++numfmtTest('Exponential: ####0.0E+0', (t) => {+ t.format('####0.0E+0', 1.23457e-13, '123.5E-15');+ t.format('####0.0E+0', 1.23457e-12, '1234.6E-15');+ t.format('####0.0E+0', 1.23457e-11, '12345.7E-15');+ t.format('####0.0E+0', 1.23457e-10, '1.2E-10');+ t.format('####0.0E+0', 1.23457e-09, '12.3E-10');+ t.format('####0.0E+0', 1.23457e-08, '123.5E-10');+ t.format('####0.0E+0', 0.000000123457, '1234.6E-10');+ t.format('####0.0E+0', 0.00000123457, '12345.7E-10');+ t.format('####0.0E+0', 0.0000123457, '1.2E-5');+ t.format('####0.0E+0', 0.000123457, '12.3E-5');+ t.format('####0.0E+0', 0.001234568, '123.5E-5');+ t.format('####0.0E+0', 0.012345679, '1234.6E-5');+ t.format('####0.0E+0', 0.123456789, '12345.7E-5');+ t.format('####0.0E+0', 1.23456789, '1.2E+0');+ t.format('####0.0E+0', 12.3456789, '12.3E+0');+ t.format('####0.0E+0', 123.456789, '123.5E+0');+ t.format('####0.0E+0', 1234.56789, '1234.6E+0');+ t.format('####0.0E+0', 12345.6789, '12345.7E+0');+ t.format('####0.0E+0', 123456.789, '1.2E+5');+ t.format('####0.0E+0', 1234567.89, '12.3E+5');+ t.format('####0.0E+0', 12345678.9, '123.5E+5');+ t.format('####0.0E+0', 123456789, '1234.6E+5');+ t.format('####0.0E+0', 1234567890, '12345.7E+5');+ t.format('####0.0E+0', 12345678900, '1.2E+10');+ t.format('####0.0E+0', 123456789000, '12.3E+10');+ t.format('####0.0E+0', 1234567890000, '123.5E+10');+ t.format('####0.0E+0', 12345678900000, '1234.6E+10');+ t.format('####0.0E+0', 123456789000000, '12345.7E+10');+ t.format('####0.0E+0', 1234567890000000, '1.2E+15');+ t.format('####0.0E+0', 12345678900000000, '12.3E+15');+ t.format('####0.0E+0', 123456789000000000, '123.5E+15');+ t.format('####0.0E+0', 1234567890000000000, '1234.6E+15');+ t.format('####0.0E+0', 12345678900000000000, '12345.7E+15');+ t.format('####0.0E+0', 123456789000000000000, '1.2E+20');+ t.format('####0.0E+0', 1234567890000000000000, '12.3E+20');+ t.format('####0.0E+0', 12345678900000000000000, '123.5E+20');+ t.format('####0.0E+0', 123456789000000000000000, '1234.6E+20');+ t.format('####0.0E+0', 1234567890000000000000000, '12345.7E+20');+ t.format('####0.0E+0', 12345678900000000000000000, '1.2E+25');+ t.format('####0.0E+0', 123456789000000000000000000, '12.3E+25');+ t.format('####0.0E+0', 1234567890000000000000000000, '123.5E+25');+ t.format('####0.0E+0', 12345678900000000000000000000, '1234.6E+25');+ t.format('####0.0E+0', 123456789000000000000000000000, '12345.7E+25');+ t.format('####0.0E+0', 1234567890000000000000000000000, '1.2E+30');+ t.format('####0.0E+0', 12345678900000000000000000000000, '12.3E+30');+});diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-fraction.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-fraction.spec.tsnew file mode 100644index 0000000000..8c211b785a--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-fraction.spec.ts@@ -0,0 +1,165 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import type { FormatOptions } from '../types';+import { numfmtTest } from './test-utils';++numfmtTest('SSF-fractions tests', (t) => {+ t.format('# ?/?', 1, '1 ', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', -1.2, '-1 1/5', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', 12.3, '12 1/3', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', -12.34, '-12 1/3', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', 123.45, '123 4/9', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', -123.456, '-123 1/2', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', 1234.567, '1234 4/7', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', -1234.5678, '-1234 4/7', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', 12345.6789, '12345 2/3', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', -12345.67891, '-12345 2/3', '# ?/?' as unknown as FormatOptions);+ t.format('# ??/??', 1, '1 ', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', -1.2, '-1 1/5 ', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', 12.3, '12 3/10', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', -12.34, '-12 17/50', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', 123.45, '123 9/20', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', -123.456, '-123 26/57', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', 1234.567, '1234 55/97', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', -1234.5678, '-1234 46/81', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', 12345.6789, '12345 55/81', '# ??/??' as unknown as FormatOptions);+ t.format('# ??/??', -12345.67891, '-12345 55/81', '# ??/??' as unknown as FormatOptions);+ t.format('# ???/???', 1, '1 ', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', -1.2, '-1 1/5 ', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', 12.3, '12 3/10 ', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', -12.34, '-12 17/50 ', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', 123.45, '123 9/20 ', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', -123.456, '-123 57/125', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', 1234.567, '1234 55/97 ', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', -1234.5678, '-1234 67/118', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', 12345.6789, '12345 74/109', '# ???/???' as unknown as FormatOptions);+ t.format('# ???/???', -12345.67891, '-12345 573/844', '# ???/???' as unknown as FormatOptions);+ t.format('# ?/2', 1, '1 ', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', -1.2, '-1 ', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', 12.3, '12 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', -12.34, '-12 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', 123.45, '123 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', -123.456, '-123 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', 1234.567, '1234 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', -1234.5678, '-1234 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', 12345.6789, '12345 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/2', -12345.67891, '-12345 1/2', '# ?/2' as unknown as FormatOptions);+ t.format('# ?/4', 1, '1 ', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', -1.2, '-1 1/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', 12.3, '12 1/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', -12.34, '-12 1/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', 123.45, '123 2/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', -123.456, '-123 2/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', 1234.567, '1234 2/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', -1234.5678, '-1234 2/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', 12345.6789, '12345 3/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/4', -12345.67891, '-12345 3/4', '# ?/4' as unknown as FormatOptions);+ t.format('# ?/8', 1, '1 ', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', -1.2, '-1 2/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', 12.3, '12 2/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', -12.34, '-12 3/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', 123.45, '123 4/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', -123.456, '-123 4/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', 1234.567, '1234 5/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', -1234.5678, '-1234 5/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', 12345.6789, '12345 5/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ?/8', -12345.67891, '-12345 5/8', '# ?/8' as unknown as FormatOptions);+ t.format('# ??/16', 1, '1 ', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', -1.2, '-1 3/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', 12.3, '12 5/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', -12.34, '-12 5/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', 123.45, '123 7/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', -123.456, '-123 7/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', 1234.567, '1234 9/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', -1234.5678, '-1234 9/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', 12345.6789, '12345 11/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ??/16', -12345.67891, '-12345 11/16', '# ??/16' as unknown as FormatOptions);+ t.format('# ?/10', 1, '1 ', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', -1.2, '-1 2/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', 12.3, '12 3/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', -12.34, '-12 3/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', 123.45, '123 5/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', -123.456, '-123 5/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', 1234.567, '1234 6/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', -1234.5678, '-1234 6/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', 12345.6789, '12345 7/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ?/10', -12345.67891, '-12345 7/10', '# ?/10' as unknown as FormatOptions);+ t.format('# ??/100', 1, '1 ', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', -1.2, '-1 20/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', 12.3, '12 30/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', -12.34, '-12 34/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', 123.45, '123 45/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', -123.456, '-123 46/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', 1234.567, '1234 57/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', -1234.5678, '-1234 57/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', 12345.6789, '12345 68/100', '# ??/100' as unknown as FormatOptions);+ t.format('# ??/100', -12345.67891, '-12345 68/100', '# ??/100' as unknown as FormatOptions);+ t.format('??/??', 1, ' 1/1 ', '??/??' as unknown as FormatOptions);+ t.format('??/??', -1.2, '- 6/5 ', '??/??' as unknown as FormatOptions);+ t.format('??/??', 12.3, '123/10', '??/??' as unknown as FormatOptions);+ t.format('??/??', -12.34, '-617/50', '??/??' as unknown as FormatOptions);+ t.format('??/??', 123.45, '2469/20', '??/??' as unknown as FormatOptions);+ t.format('??/??', -123.456, '-7037/57', '??/??' as unknown as FormatOptions);+ t.format('??/??', 1234.567, '119753/97', '??/??' as unknown as FormatOptions);+ t.format('??/??', -1234.5678, '-100000/81', '??/??' as unknown as FormatOptions);+ t.format('??/??', 12345.6789, '1000000/81', '??/??' as unknown as FormatOptions);+ t.format('??/??', -12345.67891, '-1000000/81', '??/??' as unknown as FormatOptions);+ t.format('# ?/?', 0.3, ' 2/7', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', 1.3, '1 1/3', '# ?/?' as unknown as FormatOptions);+ t.format('# ?/?', 2.3, '2 2/7', '# ?/?' as unknown as FormatOptions);+ t.format('# ??/?????????', 0.123251512342345, ' 480894/3901729 ', '# ??/?????????' as unknown as FormatOptions);+ t.format('# ?? / ?????????', 0.123251512342345, ' 480894 / 3901729 ', '# ?? / ?????????' as unknown as FormatOptions);+ t.format('0', 0, '0', '0' as unknown as FormatOptions);+});++numfmtTest('More fraction cases', (t) => {+ t.formatInvalid('0/');+ t.formatInvalid('/0');+ t.formatInvalid('/');++ t.format('0/0', 0, '0/1');+ t.format('0/0', 1, '1/1');+ t.format('0/0', 123, '123/1');+ t.format('0/0', 12.345, '37/3');+ t.format('0 0/0', 0, '0 0/1');+ t.format('0 0/0', 1, '1 0/1');+ t.format('0 0/0', 123, '123 0/1');+ t.format('0 0/0', 12.345, '12 1/3');++ t.format('?/?', 0, '0/1');+ t.format('?/?', 1, '1/1');+ t.format('?/?', 123, '123/1');+ t.format('?/?', 12.345, '37/3');+ t.format('? ?/?', 0, '0 ');+ t.format('? ?/?', 1, '1 ');+ t.format('? ?/?', 123, '123 ');+ t.format('? ?/?', 12.345, '12 1/3');++ t.format('#/#', 0, '0/1');+ t.format('#/#', 1, '1/1');+ t.format('#/#', 123, '123/1');+ t.format('#/#', 12.345, '37/3');+ t.format('# #/#', 0, '0');+ t.format('# #/#', 1, '1');+ t.format('# #/#', 123, '123');+ t.format('# #/#', 12.345, '12 1/3');+});diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-general.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-general.spec.tsnew file mode 100644index 0000000000..d3118d7eaf--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-general.spec.ts@@ -0,0 +1,540 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++// tests converted from SSF++numfmtTest('General format', (t) => {+ t.format('General', 1.234567e-14, '1.23457E-14');+ t.format('General', 1.234567e-13, '1.23457E-13');+ t.format('General', 1.234567e-12, '1.23457E-12');+ t.format('General', 1.234567e-11, '1.23457E-11');+ t.format('General', 1.234567e-10, '1.23457E-10');+ t.format('General', 1.234567e-9, '1.23457E-09');+ t.format('General', 1.234567e-8, '1.23457E-08');+ t.format('General', 1.234567e-7, '1.23457E-07');+ t.format('General', 0.000001234567, '1.23457E-06');+ t.format('General', 0.00001234567, '1.23457E-05');+ t.format('General', 0.0001234567, '0.000123457');+ t.format('General', 0.001234567, '0.001234567');+ t.format('General', 0.01234567, '0.01234567');+ t.format('General', 0.1234567, '0.1234567');+ t.format('General', 1.234567, '1.234567');+ t.format('General', 12.34567, '12.34567');+ t.format('General', 123.4567, '123.4567');+ t.format('General', 1234.567, '1234.567');+ t.format('General', 12345.67, '12345.67');+ t.format('General', 123456.7, '123456.7');+ t.format('General', 1234567, '1234567');+ t.format('General', 12345670, '12345670');+ t.format('General', 123456700, '123456700');+ t.format('General', 1234567000, '1234567000');+ t.format('General', 12345670000, '12345670000');+ t.format('General', 123456700000, '1.23457E+11');+ t.format('General', 1234567000000, '1.23457E+12');+ t.format('General', 12345670000000, '1.23457E+13');+ t.format('General', 123456700000000, '1.23457E+14');+ t.format('General', 1e-14, '1E-14');+ t.format('General', 1e-13, '1E-13');+ t.format('General', 1e-12, '1E-12');+ t.format('General', 1e-11, '1E-11');+ t.format('General', 1e-10, '1E-10');+ t.format('General', 1e-9, '0.000000001');+ t.format('General', 1e-8, '0.00000001');+ t.format('General', 1e-7, '0.0000001');+ t.format('General', 0.000001, '0.000001');+ t.format('General', 0.00001, '0.00001');+ t.format('General', 0.0001, '0.0001');+ t.format('General', 0.001, '0.001');+ t.format('General', 0.01, '0.01');+ t.format('General', 0.1, '0.1');+ t.format('General', 1, '1');+ t.format('General', 10, '10');+ t.format('General', 100, '100');+ t.format('General', 1000, '1000');+ t.format('General', 10000, '10000');+ t.format('General', 100000, '100000');+ t.format('General', 1000000, '1000000');+ t.format('General', 10000000, '10000000');+ t.format('General', 100000000, '100000000');+ t.format('General', 1000000000, '1000000000');+ t.format('General', 10000000000, '10000000000');+ t.format('General', 100000000000, '1E+11');+ t.format('General', 1000000000000, '1E+12');+ t.format('General', 10000000000000, '1E+13');+ t.format('General', 100000000000000, '1E+14');+ t.format('General', 1.2e-14, '1.2E-14');+ t.format('General', 1.2e-13, '1.2E-13');+ t.format('General', 1.2e-12, '1.2E-12');+ t.format('General', 1.2e-11, '1.2E-11');+ t.format('General', 1.2e-10, '1.2E-10');+ t.format('General', 1.2e-9, '1.2E-09');+ t.format('General', 1.2e-8, '0.000000012');+ t.format('General', 1.2e-7, '0.00000012');+ t.format('General', 0.0000012, '0.0000012');+ t.format('General', 0.000012, '0.000012');+ t.format('General', 0.00012, '0.00012');+ t.format('General', 0.0012, '0.0012');+ t.format('General', 0.012, '0.012');+ t.format('General', 0.12, '0.12');+ t.format('General', 1.2, '1.2');+ t.format('General', 12, '12');+ t.format('General', 120, '120');+ t.format('General', 1200, '1200');+ t.format('General', 12000, '12000');+ t.format('General', 120000, '120000');+ t.format('General', 1200000, '1200000');+ t.format('General', 12000000, '12000000');+ t.format('General', 120000000, '120000000');+ t.format('General', 1200000000, '1200000000');+ t.format('General', 12000000000, '12000000000');+ t.format('General', 120000000000, '1.2E+11');+ t.format('General', 1200000000000, '1.2E+12');+ t.format('General', 12000000000000, '1.2E+13');+ t.format('General', 120000000000000, '1.2E+14');+ t.format('General', 1.23e-14, '1.23E-14');+ t.format('General', 1.23e-13, '1.23E-13');+ t.format('General', 1.23e-12, '1.23E-12');+ t.format('General', 1.23e-11, '1.23E-11');+ t.format('General', 1.23e-10, '1.23E-10');+ t.format('General', 1.23e-9, '1.23E-09');+ t.format('General', 1.23e-8, '1.23E-08');+ t.format('General', 1.23e-7, '0.000000123');+ t.format('General', 0.00000123, '0.00000123');+ t.format('General', 0.0000123, '0.0000123');+ t.format('General', 0.000123, '0.000123');+ t.format('General', 0.00123, '0.00123');+ t.format('General', 0.0123, '0.0123');+ t.format('General', 0.123, '0.123');+ t.format('General', 1.23, '1.23');+ t.format('General', 12.3, '12.3');+ t.format('General', 123, '123');+ t.format('General', 1230, '1230');+ t.format('General', 12300, '12300');+ t.format('General', 123000, '123000');+ t.format('General', 1230000, '1230000');+ t.format('General', 12300000, '12300000');+ t.format('General', 123000000, '123000000');+ t.format('General', 1230000000, '1230000000');+ t.format('General', 12300000000, '12300000000');+ t.format('General', 123000000000, '1.23E+11');+ t.format('General', 1230000000000, '1.23E+12');+ t.format('General', 12300000000000, '1.23E+13');+ t.format('General', 123000000000000, '1.23E+14');+ t.format('General', 1.234e-14, '1.234E-14');+ t.format('General', 1.234e-13, '1.234E-13');+ t.format('General', 1.234e-12, '1.234E-12');+ t.format('General', 1.234e-11, '1.234E-11');+ t.format('General', 1.234e-10, '1.234E-10');+ t.format('General', 1.234e-9, '1.234E-09');+ t.format('General', 1.234e-8, '1.234E-08');+ t.format('General', 1.234e-7, '1.234E-07');+ t.format('General', 0.000001234, '0.000001234');+ t.format('General', 0.00001234, '0.00001234');+ t.format('General', 0.0001234, '0.0001234');+ t.format('General', 0.001234, '0.001234');+ t.format('General', 0.01234, '0.01234');+ t.format('General', 0.1234, '0.1234');+ t.format('General', 1.234, '1.234');+ t.format('General', 12.34, '12.34');+ t.format('General', 123.4, '123.4');+ t.format('General', 1234, '1234');+ t.format('General', 12340, '12340');+ t.format('General', 123400, '123400');+ t.format('General', 1234000, '1234000');+ t.format('General', 12340000, '12340000');+ t.format('General', 123400000, '123400000');+ t.format('General', 1234000000, '1234000000');+ t.format('General', 12340000000, '12340000000');+ t.format('General', 123400000000, '1.234E+11');+ t.format('General', 1234000000000, '1.234E+12');+ t.format('General', 12340000000000, '1.234E+13');+ t.format('General', 123400000000000, '1.234E+14');+ t.format('General', 1.2345e-14, '1.2345E-14');+ t.format('General', 1.2345e-13, '1.2345E-13');+ t.format('General', 1.2345e-12, '1.2345E-12');+ t.format('General', 1.2345e-11, '1.2345E-11');+ t.format('General', 1.2345e-10, '1.2345E-10');+ t.format('General', 1.2345e-9, '1.2345E-09');+ t.format('General', 1.2345e-8, '1.2345E-08');+ t.format('General', 1.2345e-7, '1.2345E-07');+ t.format('General', 0.0000012345, '1.2345E-06');+ t.format('General', 0.000012345, '0.000012345');+ t.format('General', 0.00012345, '0.00012345');+ t.format('General', 0.0012345, '0.0012345');+ t.format('General', 0.012345, '0.012345');+ t.format('General', 0.12345, '0.12345');+ t.format('General', 1.2345, '1.2345');+ t.format('General', 12.345, '12.345');+ t.format('General', 123.45, '123.45');+ t.format('General', 1234.5, '1234.5');+ t.format('General', 12345, '12345');+ t.format('General', 123450, '123450');+ t.format('General', 1234500, '1234500');+ t.format('General', 12345000, '12345000');+ t.format('General', 123450000, '123450000');+ t.format('General', 1234500000, '1234500000');+ t.format('General', 12345000000, '12345000000');+ t.format('General', 123450000000, '1.2345E+11');+ t.format('General', 1234500000000, '1.2345E+12');+ t.format('General', 12345000000000, '1.2345E+13');+ t.format('General', 123450000000000, '1.2345E+14');+ t.format('General', 1.23456e-14, '1.23456E-14');+ t.format('General', 1.23456e-13, '1.23456E-13');+ t.format('General', 1.23456e-12, '1.23456E-12');+ t.format('General', 1.23456e-11, '1.23456E-11');+ t.format('General', 1.23456e-10, '1.23456E-10');+ t.format('General', 1.23456e-9, '1.23456E-09');+ t.format('General', 1.23456e-8, '1.23456E-08');+ t.format('General', 1.23456e-7, '1.23456E-07');+ t.format('General', 0.00000123456, '1.23456E-06');+ t.format('General', 0.0000123456, '1.23456E-05');+ t.format('General', 0.000123456, '0.000123456');+ t.format('General', 0.00123456, '0.00123456');+ t.format('General', 0.0123456, '0.0123456');+ t.format('General', 0.123456, '0.123456');+ t.format('General', 1.23456, '1.23456');+ t.format('General', 12.3456, '12.3456');+ t.format('General', 123.456, '123.456');+ t.format('General', 1234.56, '1234.56');+ t.format('General', 12345.6, '12345.6');+ t.format('General', 123456, '123456');+ t.format('General', 1234560, '1234560');+ t.format('General', 12345600, '12345600');+ t.format('General', 123456000, '123456000');+ t.format('General', 1234560000, '1234560000');+ t.format('General', 12345600000, '12345600000');+ t.format('General', 123456000000, '1.23456E+11');+ t.format('General', 1234560000000, '1.23456E+12');+ t.format('General', 12345600000000, '1.23456E+13');+ t.format('General', 123456000000000, '1.23456E+14');+ t.format('General', 1.234567e-14, '1.23457E-14');+ t.format('General', 1.234567e-13, '1.23457E-13');+ t.format('General', 1.234567e-12, '1.23457E-12');+ t.format('General', 1.234567e-11, '1.23457E-11');+ t.format('General', 1.234567e-10, '1.23457E-10');+ t.format('General', 1.234567e-9, '1.23457E-09');+ t.format('General', 1.234567e-8, '1.23457E-08');+ t.format('General', 1.234567e-7, '1.23457E-07');+ t.format('General', 0.000001234567, '1.23457E-06');+ t.format('General', 0.00001234567, '1.23457E-05');+ t.format('General', 0.0001234567, '0.000123457');+ t.format('General', 0.001234567, '0.001234567');+ t.format('General', 0.01234567, '0.01234567');+ t.format('General', 0.1234567, '0.1234567');+ t.format('General', 1.234567, '1.234567');+ t.format('General', 12.34567, '12.34567');+ t.format('General', 123.4567, '123.4567');+ t.format('General', 1234.567, '1234.567');+ t.format('General', 12345.67, '12345.67');+ t.format('General', 123456.7, '123456.7');+ t.format('General', 1234567, '1234567');+ t.format('General', 12345670, '12345670');+ t.format('General', 123456700, '123456700');+ t.format('General', 1234567000, '1234567000');+ t.format('General', 12345670000, '12345670000');+ t.format('General', 123456700000, '1.23457E+11');+ t.format('General', 1234567000000, '1.23457E+12');+ t.format('General', 12345670000000, '1.23457E+13');+ t.format('General', 123456700000000, '1.23457E+14');+ t.format('General', 1.2345678e-14, '1.23457E-14');+ t.format('General', 1.2345678e-13, '1.23457E-13');+ t.format('General', 1.2345678e-12, '1.23457E-12');+ t.format('General', 1.2345678e-11, '1.23457E-11');+ t.format('General', 1.2345678e-10, '1.23457E-10');+ t.format('General', 1.2345678e-9, '1.23457E-09');+ t.format('General', 1.2345678e-8, '1.23457E-08');+ t.format('General', 1.2345678e-7, '1.23457E-07');+ t.format('General', 0.0000012345678, '1.23457E-06');+ t.format('General', 0.000012345678, '1.23457E-05');+ t.format('General', 0.00012345678, '0.000123457');+ t.format('General', 0.0012345678, '0.001234568');+ t.format('General', 0.012345678, '0.012345678');+ t.format('General', 0.12345678, '0.12345678');+ t.format('General', 1.2345678, '1.2345678');+ t.format('General', 12.345678, '12.345678');+ t.format('General', 123.45678, '123.45678');+ t.format('General', 1234.5678, '1234.5678');+ t.format('General', 12345.678, '12345.678');+ t.format('General', 123456.78, '123456.78');+ t.format('General', 1234567.8, '1234567.8');+ t.format('General', 12345678, '12345678');+ t.format('General', 123456780, '123456780');+ t.format('General', 1234567800, '1234567800');+ t.format('General', 12345678000, '12345678000');+ t.format('General', 123456780000, '1.23457E+11');+ t.format('General', 1234567800000, '1.23457E+12');+ t.format('General', 12345678000000, '1.23457E+13');+ t.format('General', 123456780000000, '1.23457E+14');+ t.format('General', 1.23456789e-14, '1.23457E-14');+ t.format('General', 1.23456789e-13, '1.23457E-13');+ t.format('General', 1.23456789e-12, '1.23457E-12');+ t.format('General', 1.23456789e-11, '1.23457E-11');+ t.format('General', 1.23456789e-10, '1.23457E-10');+ t.format('General', 1.23456789e-9, '1.23457E-09');+ t.format('General', 1.23456789e-8, '1.23457E-08');+ t.format('General', 1.23456789e-7, '1.23457E-07');+ t.format('General', 0.00000123456789, '1.23457E-06');+ t.format('General', 0.0000123456789, '1.23457E-05');+ t.format('General', 0.000123456789, '0.000123457');+ t.format('General', 0.00123456789, '0.001234568');+ t.format('General', 0.0123456789, '0.012345679');+ t.format('General', 0.123456789, '0.123456789');+ t.format('General', 1.23456789, '1.23456789');+ t.format('General', 12.3456789, '12.3456789');+ t.format('General', 123.456789, '123.456789');+ t.format('General', 1234.56789, '1234.56789');+ t.format('General', 12345.6789, '12345.6789');+ t.format('General', 123456.789, '123456.789');+ t.format('General', 1234567.89, '1234567.89');+ t.format('General', 12345678.9, '12345678.9');+ t.format('General', 123456789, '123456789');+ t.format('General', 1234567890, '1234567890');+ t.format('General', 12345678900, '12345678900');+ t.format('General', 123456789000, '1.23457E+11');+ t.format('General', 1234567890000, '1.23457E+12');+ t.format('General', 12345678900000, '1.23457E+13');+ t.format('General', 123456789000000, '1.23457E+14');+ t.format('General', 1.234567891e-14, '1.23457E-14');+ t.format('General', 1.234567891e-13, '1.23457E-13');+ t.format('General', 1.234567891e-12, '1.23457E-12');+ t.format('General', 1.234567891e-11, '1.23457E-11');+ t.format('General', 1.234567891e-10, '1.23457E-10');+ t.format('General', 1.234567891e-9, '1.23457E-09');+ t.format('General', 1.234567891e-8, '1.23457E-08');+ t.format('General', 1.234567891e-7, '1.23457E-07');+ t.format('General', 0.000001234567891, '1.23457E-06');+ t.format('General', 0.00001234567891, '1.23457E-05');+ t.format('General', 0.0001234567891, '0.000123457');+ t.format('General', 0.001234567891, '0.001234568');+ t.format('General', 0.01234567891, '0.012345679');+ t.format('General', 0.1234567891, '0.123456789');+ t.format('General', 1.234567891, '1.234567891');+ t.format('General', 12.34567891, '12.34567891');+ t.format('General', 123.4567891, '123.4567891');+ t.format('General', 1234.567891, '1234.567891');+ t.format('General', 12345.67891, '12345.67891');+ t.format('General', 123456.7891, '123456.7891');+ t.format('General', 1234567.891, '1234567.891');+ t.format('General', 12345678.91, '12345678.91');+ t.format('General', 123456789.1, '123456789.1');+ t.format('General', 1234567891, '1234567891');+ t.format('General', 12345678910, '12345678910');+ t.format('General', 123456789100, '1.23457E+11');+ t.format('General', 1234567891000, '1.23457E+12');+ t.format('General', 12345678910000, '1.23457E+13');+ t.format('General', 123456789100000, '1.23457E+14');+ t.format('General', 1.2345678912e-14, '1.23457E-14');+ t.format('General', 1.2345678912e-13, '1.23457E-13');+ t.format('General', 1.2345678912e-12, '1.23457E-12');+ t.format('General', 1.2345678912e-11, '1.23457E-11');+ t.format('General', 1.2345678912e-10, '1.23457E-10');+ t.format('General', 1.2345678912e-9, '1.23457E-09');+ t.format('General', 1.2345678912e-8, '1.23457E-08');+ t.format('General', 1.2345678912e-7, '1.23457E-07');+ t.format('General', 0.0000012345678912, '1.23457E-06');+ t.format('General', 0.000012345678912, '1.23457E-05');+ t.format('General', 0.00012345678912, '0.000123457');+ t.format('General', 0.0012345678912, '0.001234568');+ t.format('General', 0.012345678912, '0.012345679');+ t.format('General', 0.12345678912, '0.123456789');+ t.format('General', 1.2345678912, '1.234567891');+ t.format('General', 12.345678912, '12.34567891');+ t.format('General', 123.45678912, '123.4567891');+ t.format('General', 1234.5678912, '1234.567891');+ t.format('General', 12345.678912, '12345.67891');+ t.format('General', 123456.78912, '123456.7891');+ t.format('General', 1234567.8912, '1234567.891');+ t.format('General', 12345678.912, '12345678.91');+ t.format('General', 123456789.12, '123456789.1');+ t.format('General', 1234567891.2, '1234567891');+ t.format('General', 12345678912, '12345678912');+ t.format('General', 123456789120, '1.23457E+11');+ t.format('General', 1234567891200, '1.23457E+12');+ t.format('General', 12345678912000, '1.23457E+13');+ t.format('General', 123456789120000, '1.23457E+14');+ t.format('General', 1.23456789123e-14, '1.23457E-14');+ t.format('General', 1.23456789123e-13, '1.23457E-13');+ t.format('General', 1.23456789123e-12, '1.23457E-12');+ t.format('General', 1.23456789123e-11, '1.23457E-11');+ t.format('General', 1.23456789123e-10, '1.23457E-10');+ t.format('General', 1.23456789123e-9, '1.23457E-09');+ t.format('General', 1.23456789123e-8, '1.23457E-08');+ t.format('General', 1.23456789123e-7, '1.23457E-07');+ t.format('General', 0.00000123456789123, '1.23457E-06');+ t.format('General', 0.0000123456789123, '1.23457E-05');+ t.format('General', 0.000123456789123, '0.000123457');+ t.format('General', 0.00123456789123, '0.001234568');+ t.format('General', 0.0123456789123, '0.012345679');+ t.format('General', 0.123456789123, '0.123456789');+ t.format('General', 1.23456789123, '1.234567891');+ t.format('General', 12.3456789123, '12.34567891');+ t.format('General', 123.456789123, '123.4567891');+ t.format('General', 1234.56789123, '1234.567891');+ t.format('General', 12345.6789123, '12345.67891');+ t.format('General', 123456.789123, '123456.7891');+ t.format('General', 1234567.89123, '1234567.891');+ t.format('General', 12345678.9123, '12345678.91');+ t.format('General', 123456789.123, '123456789.1');+ t.format('General', 1234567891.23, '1234567891');+ t.format('General', 12345678912.3, '12345678912');+ t.format('General', 123456789123, '1.23457E+11');+ t.format('General', 1234567891230, '1.23457E+12');+ t.format('General', 12345678912300, '1.23457E+13');+ t.format('General', 123456789123000, '1.23457E+14');+ t.format('General', 1.234567891234e-14, '1.23457E-14');+ t.format('General', 1.234567891234e-13, '1.23457E-13');+ t.format('General', 1.234567891234e-12, '1.23457E-12');+ t.format('General', 1.234567891234e-11, '1.23457E-11');+ t.format('General', 1.234567891234e-10, '1.23457E-10');+ t.format('General', 1.234567891234e-9, '1.23457E-09');+ t.format('General', 1.234567891234e-8, '1.23457E-08');+ t.format('General', 1.234567891234e-7, '1.23457E-07');+ t.format('General', 0.000001234567891234, '1.23457E-06');+ t.format('General', 0.00001234567891234, '1.23457E-05');+ t.format('General', 0.0001234567891234, '0.000123457');+ t.format('General', 0.001234567891234, '0.001234568');+ t.format('General', 0.01234567891234, '0.012345679');+ t.format('General', 0.1234567891234, '0.123456789');+ t.format('General', 1.234567891234, '1.234567891');+ t.format('General', 12.34567891234, '12.34567891');+ t.format('General', 123.4567891234, '123.4567891');+ t.format('General', 1234.567891234, '1234.567891');+ t.format('General', 12345.67891234, '12345.67891');+ t.format('General', 123456.7891234, '123456.7891');+ t.format('General', 1234567.891234, '1234567.891');+ t.format('General', 12345678.91234, '12345678.91');+ t.format('General', 123456789.1234, '123456789.1');+ t.format('General', 1234567891.234, '1234567891');+ t.format('General', 12345678912.34, '12345678912');+ t.format('General', 123456789123.4, '1.23457E+11');+ t.format('General', 1234567891234, '1.23457E+12');+ t.format('General', 12345678912340, '1.23457E+13');+ t.format('General', 123456789123400, '1.23457E+14');+ t.format('General', 1.2345678912345e-14, '1.23457E-14');+ t.format('General', 1.2345678912345e-13, '1.23457E-13');+ t.format('General', 1.2345678912345e-12, '1.23457E-12');+ t.format('General', 1.2345678912345e-11, '1.23457E-11');+ t.format('General', 1.2345678912345e-10, '1.23457E-10');+ t.format('General', 1.2345678912345e-9, '1.23457E-09');+ t.format('General', 1.2345678912345e-8, '1.23457E-08');+ t.format('General', 1.2345678912345e-7, '1.23457E-07');+ t.format('General', 0.0000012345678912345, '1.23457E-06');+ t.format('General', 0.000012345678912345, '1.23457E-05');+ t.format('General', 0.00012345678912345, '0.000123457');+ t.format('General', 0.0012345678912345, '0.001234568');+ t.format('General', 0.012345678912345, '0.012345679');+ t.format('General', 0.12345678912345, '0.123456789');+ t.format('General', 1.2345678912345, '1.234567891');+ t.format('General', 12.345678912345, '12.34567891');+ t.format('General', 123.45678912345, '123.4567891');+ t.format('General', 1234.5678912345, '1234.567891');+ t.format('General', 12345.678912345, '12345.67891');+ t.format('General', 123456.78912345, '123456.7891');+ t.format('General', 1234567.8912345, '1234567.891');+ t.format('General', 12345678.912345, '12345678.91');+ t.format('General', 123456789.12345, '123456789.1');+ t.format('General', 1234567891.2345, '1234567891');+ t.format('General', 12345678912.345, '12345678912');+ t.format('General', 123456789123.45, '1.23457E+11');+ t.format('General', 1234567891234.5, '1.23457E+12');+ t.format('General', 12345678912345, '1.23457E+13');+ t.format('General', 123456789123450, '1.23457E+14');+ t.format('General', 1.23456789123456e-14, '1.23457E-14');+ t.format('General', 1.23456789123456e-13, '1.23457E-13');+ t.format('General', 1.23456789123456e-12, '1.23457E-12');+ t.format('General', 1.23456789123456e-11, '1.23457E-11');+ t.format('General', 1.23456789123456e-10, '1.23457E-10');+ t.format('General', 1.23456789123456e-9, '1.23457E-09');+ t.format('General', 1.23456789123456e-8, '1.23457E-08');+ t.format('General', 1.23456789123456e-7, '1.23457E-07');+ t.format('General', 0.00000123456789123456, '1.23457E-06');+ t.format('General', 0.0000123456789123456, '1.23457E-05');+ t.format('General', 0.000123456789123456, '0.000123457');+ t.format('General', 0.00123456789123456, '0.001234568');+ t.format('General', 0.0123456789123456, '0.012345679');+ t.format('General', 0.123456789123456, '0.123456789');+ t.format('General', 1.23456789123456, '1.234567891');+ t.format('General', 12.3456789123456, '12.34567891');+ t.format('General', 123.456789123456, '123.4567891');+ t.format('General', 1234.56789123456, '1234.567891');+ t.format('General', 12345.6789123456, '12345.67891');+ t.format('General', 123456.789123456, '123456.7891');+ t.format('General', 1234567.89123456, '1234567.891');+ t.format('General', 12345678.9123456, '12345678.91');+ t.format('General', 123456789.123456, '123456789.1');+ t.format('General', 1234567891.23456, '1234567891');+ t.format('General', 12345678912.3456, '12345678912');+ t.format('General', 123456789123.456, '1.23457E+11');+ t.format('General', 1234567891234.56, '1.23457E+12');+ t.format('General', 12345678912345.6, '1.23457E+13');+ t.format('General', 123456789123456, '1.23457E+14');+ t.format('General', -1.234567e-14, '-1.23457E-14');+ t.format('General', -1.234567e-13, '-1.23457E-13');+ t.format('General', -1.234567e-12, '-1.23457E-12');+ t.format('General', -1.234567e-11, '-1.23457E-11');+ t.format('General', -1.234567e-10, '-1.23457E-10');+ t.format('General', -1.234567e-9, '-1.23457E-09');+ t.format('General', -1.234567e-8, '-1.23457E-08');+ t.format('General', -1.234567e-7, '-1.23457E-07');+ t.format('General', -0.000001234567, '-1.23457E-06');+ t.format('General', -0.00001234567, '-1.23457E-05');+ t.format('General', -0.0001234567, '-0.000123457');+ t.format('General', -0.001234567, '-0.001234567');+ t.format('General', -0.01234567, '-0.01234567');+ t.format('General', -0.1234567, '-0.1234567');+ t.format('General', -1.234567, '-1.234567');+ t.format('General', -12.34567, '-12.34567');+ t.format('General', -123.4567, '-123.4567');+ t.format('General', -1234.567, '-1234.567');+ t.format('General', -12345.67, '-12345.67');+ t.format('General', -123456.7, '-123456.7');+ t.format('General', -1234567, '-1234567');+ t.format('General', -12345670, '-12345670');+ t.format('General', -123456700, '-123456700');+ t.format('General', -1234567000, '-1234567000');+ t.format('General', -12345670000, '-12345670000');+ t.format('General', -123456700000, '-1.23457E+11');+ t.format('General', -1234567000000, '-1.23457E+12');+ t.format('General', -12345670000000, '-1.23457E+13');+ t.format('General', -123456700000000, '-1.23457E+14');+ t.format('General', true, 'TRUE');+ t.format('General', false, 'FALSE');+ t.format('General', 'sheetjs', 'sheetjs');++ t.format('General', undefined, '');+ t.format('General', null, '');+});++numfmtTest('No decimal point', (t) => {+ t.format('General', 0.9999999999999999, '1');+ t.format('General', 0.999999999999999, '1');+ t.format('General', 0.99999999999999, '1');+ t.format('General', 0.9999999999999, '1');+ t.format('General', 0.999999999999, '1');+ t.format('General', 0.99999999999, '1');+ t.format('General', 0.9999999999, '1'); // Sheets emits "0.9999999999" here which is not by spec+ t.format('General', 0.999999999, '0.999999999'); // Excel yeilds a "1" here, but this is not by spec+ t.format('General', 0.99999999, '0.99999999');+ t.format('General', 0.9999999, '0.9999999');+ t.format('General', 0.999999, '0.999999');+});diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-oddities.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-oddities.spec.tsnew file mode 100644index 0000000000..21e6a13cfb--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-oddities.spec.ts@@ -0,0 +1,618 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { format } from '../api';+import { numfmtTest } from './test-utils';++// Tests originally converted from SSF but have been reviewed+// and corrected and conformed to Excel for Mac version 16.35++numfmtTest('Oddity: "foo";"bar";"baz";"qux"', (t) => {+ t.format('"foo";"bar";"baz";"qux"', 1, 'foo');+ t.format('"foo";"bar";"baz";"qux"', -1, 'bar');+ t.format('"foo";"bar";"baz";"qux"', 0, 'baz');+ t.format('"foo";"bar";"baz";"qux"', 'text', 'qux');+});++numfmtTest('Oddity: "foo";"bar";"baz"', (t) => {+ t.format('"foo";"bar";"baz"', 1, 'foo');+ t.format('"foo";"bar";"baz"', -1, 'bar');+ t.format('"foo";"bar";"baz"', 0, 'baz');+ t.format('"foo";"bar";"baz"', 'text', 'text');+});++numfmtTest('Oddity: "foo";"bar";@', (t) => {+ t.format('"foo";"bar";@', 1, 'foo');+ t.format('"foo";"bar";@', -1, 'bar');+ t.format('"foo";"bar";@', 0, 'foo');+ t.format('"foo";"bar";@', 'text', 'text');+});++numfmtTest('Oddity: "foo";"bar"', (t) => {+ t.format('"foo";"bar"', 1, 'foo');+ t.format('"foo";"bar"', -1, 'bar');+ t.format('"foo";"bar"', 0, 'foo');+ t.format('"foo";"bar"', 'text', 'text');+});++numfmtTest('Oddity: @@', (t) => {+ t.format('@@', 1, '1');+ t.format('@@', -1, '-1');+ t.format('@@', 0, '0');+ t.format('@@', 'text', 'texttext');+});++numfmtTest('Oddity: [Blue]General', (t) => {+ t.format('[Blue]General', 1, '1');+ t.format('[Blue]General', -1, '-1');+ t.format('[Blue]General', 0, '0');+ t.format('[Blue]General', 'text', 'text');+});++numfmtTest('Oddity: [Blue]G3neral', (t) => {+ t.formatInvalid('[Blue]G3neral', 0);+});++numfmtTest('Oddity: A"TODO"', (t) => {+ t.format('A"TODO"', 1, 'ATODO');+ t.format('A"TODO"', -1, '-ATODO');+ t.format('A"TODO"', 0, 'ATODO');+ t.format('A"TODO"', 'text', 'text');+});++numfmtTest('Oddity: r', (t) => {+ t.format('r', 1, 'r');+ t.format('r', -1, '-r');+ t.format('r', 0, 'r');+ t.format('r', 'text', 'text');+});++numfmtTest('Oddity: ((;@', (t) => {+ t.format('((;@', 1, '((');+ t.format('((;@', 0, '((');+ t.format('((;@', 'text', 'text');+});++numfmtTest('Oddity: \\r', (t) => {+ t.format('\\r', 1, 'r');+ t.format('\\r', -1, '-r');+ t.format('\\r', 0, 'r');+ t.format('\\r', 'text', 'text');+});++numfmtTest('Oddity: _($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', (t) => {+ t.format('_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', (1), ' $1 ');+ t.format('_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', (-1), ' $(1)');+ t.format('_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', (0), ' $- ');+ t.format('_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', ('text'), ' text ');+ // t.format('_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', (null), ' $- ');+ // t.format('_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)', (''), '');+});++numfmtTest('Oddity: #0.#', (t) => {+ t.format('#0.#', 0, '0.');+ t.format('#0.#', 1, '1.');+ t.format('#0.#', 12, '12.');+ t.format('#0.#', 12.34, '12.3');+ t.format('#0.#', -1.23, '-1.2');+});++numfmtTest('Oddity: #,##0.0', (t) => {+ t.format('#,##0.0', 1, '1.0');+ t.format('#,##0.0', -1, '-1.0');+ t.format('#,##0.0', 0, '0.0');+ t.format('#,##0.0', 'text', 'text');+});++numfmtTest('Oddity: #,##0.00', (t) => {+ t.format('#,##0.00', 1, '1.00');+ t.format('#,##0.00', -1, '-1.00');+ t.format('#,##0.00', 0, '0.00');+ t.format('#,##0.00', 'text', 'text');+});++numfmtTest('Oddity: #,##0.000', (t) => {+ t.format('#,##0.000', 1, '1.000');+ t.format('#,##0.000', -1, '-1.000');+ t.format('#,##0.000', 0, '0.000');+ t.format('#,##0.000', 'text', 'text');+});++numfmtTest('Oddity: #,##0.0000', (t) => {+ t.format('#,##0.0000', 1, '1.0000');+ t.format('#,##0.0000', -1, '-1.0000');+ t.format('#,##0.0000', 0, '0.0000');+ t.format('#,##0.0000', 'text', 'text');+});++numfmtTest('Oddity: #,##0.00000', (t) => {+ t.format('#,##0.00000', 1000000, '1,000,000.00000');+});++numfmtTest('Oddity: #,##0.000000', (t) => {+ t.format('#,##0.000000', 1000000, '1,000,000.000000');+});++numfmtTest('Oddity: #,##0.0000000', (t) => {+ t.format('#,##0.0000000', 1000000, '1,000,000.0000000');+});++numfmtTest('Oddity: #,##0.00000000', (t) => {+ t.format('#,##0.00000000', 1000000, '1,000,000.00000000');+});++numfmtTest('Oddity: #,##0.000000000', (t) => {+ t.format('#,##0.000000000', 1000000, '1,000,000.000000000');+});++numfmtTest('Oddity: #,###', (t) => {+ t.format('#,###', 1, '1');+ t.format('#,###', -1, '-1');+ t.format('#,###', 0, '');+ t.format('#,###', 12345.6789, '12,346');+ t.format('#,###', 'TODO', 'TODO');+});++numfmtTest('Oddity: #.##', (t) => {+ t.format('#.##', 1, '1.');+ t.format('#.##', -1, '-1.');+ t.format('#.##', 0, '.');+ t.format('#.##', 'text', 'text');+});++numfmtTest('Oddity: 0;0', (t) => {+ t.format('0;0', 1.1, '1');+ t.format('0;0', -1.1, '1');+ t.format('0;0', 0, '0');+ t.format('0;0', 'text', 'text');+});++numfmtTest('Oddity: 0.0', (t) => {+ t.format('0.0', 1, '1.0');+ t.format('0.0', -1, '-1.0');+ t.format('0.0', 0, '0.0');+ t.format('0.0', 'text', 'text');+});++numfmtTest('Oddity: 0.00', (t) => {+ t.format('0.00', 1.0001, '1.00');+ t.format('0.00', -1, '-1.00');+ t.format('0.00', 0, '0.00');+ t.format('0.00', 'text', 'text');+});++numfmtTest('Oddity: 0.000', (t) => {+ t.format('0.000', 1, '1.000');+ t.format('0.000', -1, '-1.000');+ t.format('0.000', 0, '0.000');+ t.format('0.000', 'text', 'text');+});++numfmtTest('Oddity: 0.0000', (t) => {+ t.format('0.0000', 1, '1.0000');+ t.format('0.0000', -1, '-1.0000');+ t.format('0.0000', 0, '0.0000');+ t.format('0.0000', 'text', 'text');+});++numfmtTest('Oddity: hh:mm AM/PM', (t) => {+ t.format('hh:mm AM/PM', 0.7, '04:48 PM');+});++numfmtTest('Oddity: hhh:mm AM/PM', (t) => {+ t.format('hhh:mm AM/PM', 0.7, '04:48 PM');+});++numfmtTest('Oddity: hhh:mmm:sss', (t) => {+ t.format('hhh:mmm:sss', 0.7, '16:Jan:00');+});++numfmtTest('Oddity: hh:mmm:sss', (t) => {+ t.format('hhh:mmm:sss', 0.7, '16:Jan:00');+});++numfmtTest('Oddity: hh:mm:sss', (t) => {+ t.format('hh:mm:sss', 0.7, '16:48:00');+});++numfmtTest('Oddity: hh:mm:ss.000', (t) => {+ t.format('hh:mm:ss.000', 0.7, '16:48:00.000');+ t.format('hh:mm:ss.000', 0.70707, '16:58:10.848');+});++numfmtTest('Oddity: hh.000', (t) => {+ t.format('hh.000', 0.70707, '16.848');+});++numfmtTest('Oddity: hh .00', (t) => {+ t.format('hh .00', 0.70707, '16 .85');+});++numfmtTest('Oddity: hh .0', (t) => {+ t.format('hh .0', 0.70707, '16 .8');+});++numfmtTest('Oddity: hh .00 .000', (t) => {+ t.format('hh .00 .000', 0.70707, '16 .84 .848');+});++numfmtTest('Oddity: [hhh]', (t) => {+ t.format('[hhh]', 1, '024');+ t.format('[hhh]', -1, '-024');+ t.format('[hhh]', 0, '000');+ t.format('[hhh]', 'text', 'text');+});++numfmtTest('Oddity: [', (t) => {+ t.throws(() => (format as (pattern: string) => string)('['), '[');+});++numfmtTest('Oddity: A/P', (t) => {+ t.format('A/P', 0.7, 'P');+});++numfmtTest('Oddity: e', (t) => {+ t.format('e', 0.7, '1900');+});++numfmtTest('Oddity: 123', (t) => {+ t.format('123', 0.7, '123');+ t.format('123', 0, '123');+ t.format('123', 'text', 'text');+});++numfmtTest('Oddity: 0.##', (t) => {+ t.format('0.##', 1, '1.');+ t.format('0.##', -1, '-1.');+ t.format('0.##', 0, '0.');+ t.format('0.##', 1.1, '1.1');+ t.format('0.##', -1.2, '-1.2');+ t.format('0.##', 1000000000000.01, '1000000000000.01');+ t.format('0.##', -1000.01, '-1000.01');+ t.format('0.##', 0.1, '0.1');+ t.format('0.##', 1.007, '1.01');+ t.format('0.##', -1.008, '-1.01');+});++numfmtTest('Oddity: ** #,###,#00,000.00,**', (t) => {+ t.format('** #,###,#00,000.00,**', 1.2345, ' 00,000.00');+ t.format('** #,###,#00,000.00,**', 12.345, ' 00,000.01');+ t.format('** #,###,#00,000.00,**', 123.45, ' 00,000.12');+ t.format('** #,###,#00,000.00,**', 1234.56, ' 00,001.23');+ t.format('** #,###,#00,000.00,**', 12345.67, ' 00,012.35');+ t.format('** #,###,#00,000.00,**', 123456.78, ' 00,123.46');+ t.format('** #,###,#00,000.00,**', 1234567.89, ' 01,234.57');+ t.format('** #,###,#00,000.00,**', 12345681.9, ' 12,345.68');+ t.format('** #,###,#00,000.00,**', 123456822, ' 123,456.82');+ t.format('** #,###,#00,000.00,**', 1234568223, ' 1,234,568.22');+ t.format('** #,###,#00,000.00,**', 12345682233, ' 12,345,682.23');+ t.format('** #,###,#00,000.00,**', 123456822333, ' 123,456,822.33');+ t.format('** #,###,#00,000.00,**', 1234568223333, ' 1,234,568,223.33');+ t.format('** #,###,#00,000.00,**', 12345682233333, ' 12,345,682,233.33');+ t.format('** #,###,#00,000.00,**', 123456822333333, ' 123,456,822,333.33');+ t.format('** #,###,#00,000.00,**', 1234568223333330, ' 1,234,568,223,333.33');+ t.format('** #,###,#00,000.00,**', 12345682233333300, ' 12,345,682,233,333.30');+ t.format('** #,###,#00,000.00,**', 123456822333333000, ' 123,456,822,333,333.00');+ t.format('** #,###,#00,000.00,**', 1234568223333330000, ' 1,234,568,223,333,330.00');+ t.format('** #,###,#00,000.00,**', 12345682233333300000, ' 12,345,682,233,333,300.00');+ t.format('** #,###,#00,000.00,**', 123456822333333000000, ' 123,456,822,333,333,000.00');+ t.format('** #,###,#00,000.00,**', 1.23456822333333e+21, ' 1,234,568,223,333,330,000.00');+});++numfmtTest('Oddity: 00,000.00,', (t) => {+ t.format('00,000.00,', 12345, '00,012.35');+});++numfmtTest('Oddity: 00,000.00', (t) => {+ t.format('00,000.00', 12345, '12,345.00');+});++numfmtTest('Oddity: ##0.0E+0', (t) => {+ t.format('##0.0E+0', 1, '1.0E+0');+ t.format('##0.0E+0', 12, '12.0E+0');+ t.format('##0.0E+0', 123, '123.0E+0');+ t.format('##0.0E+0', 1234, '1.2E+3');+ t.format('##0.0E+0', 12345, '12.3E+3');+ t.format('##0.0E+0', 123456, '123.5E+3');+ t.format('##0.0E+0', 1234567, '1.2E+6');+ t.format('##0.0E+0', 12345678, '12.3E+6');+ t.format('##0.0E+0', 123456789, '123.5E+6');+});++numfmtTest.skip('Oddity: 000#0#0#0##00##00##0#########', (t) => {+ // 000#0#0#0##00##00##0#########+ // 000 0 0 0 00 00 0 12345 (12345)+ // 000 0 0 0 00 00 0 1 (1)+ t.format('000#0#0#0##00##00##0#########', 12345, '0000000000012345');+});++numfmtTest.skip('Oddity: 0#######0.##0##0######00######0', (t) => {+ t.format('0#######0.##0##0######00######0', 12.3456789, '012.3456789000');+ t.format('0#######0.##0##0######00######0', 123456789, '123456789.00000');+});++numfmtTest('Oddity: ###\\###\\##0.00', (t) => {+ t.format('###\\###\\##0.00', 0.00101, '##0.00');+ t.format('###\\###\\##0.00', 0.0101, '##0.01');+ t.format('###\\###\\##0.00', 0.101, '##0.10');+ t.format('###\\###\\##0.00', 1.01, '##1.01');+ t.format('###\\###\\##0.00', 10.1, '##10.10');+ t.format('###\\###\\##0.00', 101, '#1#01.00');+ t.format('###\\###\\##0.00', 1010, '#10#10.00');+ t.format('###\\###\\##0.00', 10100, '1#01#00.00');+ t.format('###\\###\\##0.00', 101000, '10#10#00.00');+ t.format('###\\###\\##0.00', 1010000, '101#00#00.00');+ t.format('###\\###\\##0.00', 10100000, '1010#00#00.00');+ t.format('###\\###\\##0.00', 101000000, '10100#00#00.00');+ t.format('###\\###\\##0.00', 123456789.01, '12345#67#89.01');+});++numfmtTest('Oddity: ###\\\\###\\\\##\\0.00', (t) => {+ t.format('###\\\\###\\\\##\\0.00', 0.00101, '\\\\0.00');+ t.format('###\\\\###\\\\##\\0.00', 0.0101, '\\\\0.01');+ t.format('###\\\\###\\\\##\\0.00', 0.101, '\\\\0.10');+ t.format('###\\\\###\\\\##\\0.00', 1.01, '\\\\10.01');+ t.format('###\\\\###\\\\##\\0.00', 10.1, '\\\\100.10');+ t.format('###\\\\###\\\\##\\0.00', 101, '\\1\\010.00');+ t.format('###\\\\###\\\\##\\0.00', 1010, '\\10\\100.00');+ t.format('###\\\\###\\\\##\\0.00', 10100, '\\101\\000.00');+ t.format('###\\\\###\\\\##\\0.00', 101000, '1\\010\\000.00');+ t.format('###\\\\###\\\\##\\0.00', 1010000, '10\\100\\000.00');+ t.format('###\\\\###\\\\##\\0.00', 10100000, '101\\000\\000.00');+ t.format('###\\\\###\\\\##\\0.00', 101000000, '1010\\000\\000.00');+ t.format('###\\\\###\\\\##\\0.00', 123456789.01, '1234\\567\\890.01');+});++numfmtTest('Oddity: 0.0#', (t) => {+ t.format('0.0#', 12345, '12345.0');+ t.format('0.0#', 1234.5, '1234.5');+ t.format('0.0#', 123.45, '123.45');+ t.format('0.0#', 12.345, '12.35');+ t.format('0.0#', 1.2345, '1.23');+ t.format('0.0#', 0.12345, '0.12');+ t.format('0.0#', 0.012345, '0.01');+ t.format('0.0#', 0.0012345, '0.0');+ t.format('0.0#', 0.00012345, '0.0');+ t.format('0.0#', 15.04, '15.04');+ t.format('0.0#', 15.06, '15.06');+});++numfmtTest('Oddity: ###\\\\###\\\\##\\0', (t) => {+ t.format('###\\\\###\\\\##\\0', 12345.6789, '\\123\\460');+});++numfmtTest('Oddity: 00000-0000', (t) => {+ t.format('00000-0000', 941051630, '94105-1630');+ t.format('00000-0000', 12345.6789, '00001-2346');+});++numfmtTest('Oddity: 000-00-0000', (t) => {+ t.format('000-00-0000', 123456789, '123-45-6789');+});++numfmtTest('Oddity: 00000\\-0000', (t) => {+ t.format('00000\\-0000', 941051630, '94105-1630');+});++numfmtTest('Oddity: 000\\-00\\-0000', (t) => {+ t.format('000\\-00\\-0000', 123456789, '123-45-6789');+});++numfmtTest('Oddity: ??/??', (t) => {+ t.format('??/??', 12.3456789, '1000/81');+ t.format('??/??', 0.00001, ' 0/1 ');+});++numfmtTest('Oddity: # ??/??', (t) => {+ t.format('# ??/??', 12.3456789, '12 28/81');+});++numfmtTest('Oddity: #??/??', (t) => {+ t.format('#??/??', 12.3456789, '1000/81');+});++numfmtTest('Oddity: #0#00??/??', (t) => {+ t.format('#0#00??/??', 12.3456789, '01000/81');+});++numfmtTest('Oddity: [<=9999999]###-####;(###) ###-####', (t) => {+ t.format('[<=9999999]###-####;(###) ###-####', 8675309, '867-5309');+ t.format('[<=9999999]###-####;(###) ###-####', 2813308004, '(281) 330-8004');+ t.format('[<=9999999]###-####;(###) ###-####', 2018675309, '(201) 867-5309');+});++numfmtTest('Oddity: [<=9999999]###\\-####;(###) ###\\-####', (t) => {+ t.format('[<=9999999]###\\-####;(###) ###\\-####', 8675309, '867-5309');+ t.format('[<=9999999]###\\-####;(###) ###\\-####', 2813308004, '(281) 330-8004');+});++numfmtTest('Oddity: [Red][<-25]General;[Blue][>25]General;[Green]General;[Yellow]General', (t) => {+ const z = '[Red][<-25]General;[Blue][>25]General;[Green]General;[Yellow]General';+ t.format(z, 50, '50');+ t.format(z, 26, '26');+ t.format(z, 25, '25');+ t.format(z, 1, '1');+ t.format(z, 0, '0');+ t.format(z, -1, '-1');+ t.format(z, -25, '-25');+ t.format(z, -26, '26');+ t.format(z, -50.1, '50.1');+ t.format(z, 'foo', 'foo');+ t.format(z, 'bar', 'bar');+});++numfmtTest('Oddity: [Red][<=-25]General;[Blue][>=25]General;[Green]General;[Yellow]General', (t) => {+ const z = '[Red][<=-25]General;[Blue][>=25]General;[Green]General;[Yellow]General';+ t.format(z, 50, '50');+ t.format(z, 26, '26');+ t.format(z, 25, '25');+ t.format(z, 1, '1');+ t.format(z, 0, '0');+ t.format(z, -1, '-1');+ t.format(z, -25, '25');+ t.format(z, -26.1, '26.1');+ t.format(z, -50, '50');+ t.format(z, 'foo', 'foo');+ t.format(z, 'bar', 'bar');+});++numfmtTest("Oddity: [Red]General ;[Blue]General\\ ;[Green]Generalp;[Yellow]General'", (t) => {+ const z = "[Red]General ;[Blue]General\\ ;[Green]Generalp;[Yellow]General'";+ t.format(z, 50, '50 ');+ t.format(z, 0, '0p');+ t.format(z, -25, '25 ');+ t.format(z, 'foo', 'foo\'');+});++numfmtTest('Oddity: [Red][=50]General;[Blue]000', (t) => {+ t.format('[Red][=50]General;[Blue]000', 50, '50');+ t.format('[Red][=50]General;[Blue]000', 51, '051');+ t.format('[Red][=50]General;[Blue]000', 49, '049');+});++numfmtTest('Oddity: [Red][<>50]General;[Blue]000', (t) => {+ t.format('[Red][<>50]General;[Blue]000', 50, '050');+ t.format('[Red][<>50]General;[Blue]000', 51, '51');+ t.format('[Red][<>50]General;[Blue]000', 49, '49');+});++numfmtTest('Oddity: b', (t) => {+ t.format('b', 1, '43');+ t.format('b', 1000, '45');+ t.format('b', 10000, '70');+});++numfmtTest('Oddity: B2yyyy-mm-dd', (t) => {+ t.format('B2yyyy-mm-dd', 0, '1317-08-29');+ t.format('B2yyyy-mm-dd', 59, '1317-10-28');+ t.formatThrows('B2yyyy-mm-dd', 60);+ t.format('B2yyyy-mm-dd', 61, '1317-10-29');+ t.format('B2yyyy-mm-dd', 1000, '1320-06-23');+ t.format('B2yyyy-mm-dd', 10000, '1345-11-17');+});++numfmtTest('Oddity: ☃', (t) => {+ t.format('☃', 0, '☃');+ t.format('☃', 1, '☃');+ t.format('☃', -1, '-☃');+ t.format('☃', 'foo', 'foo');+});++numfmtTest.skip('Oddity: #0#######', (t) => {+ t.format('#0#######', 12345, '012345');+ t.format('#0#######', 12345.4321, '012345');+ t.format('#0#######', 12345.6789, '012346');+});++numfmtTest.skip('Oddity: ##,##', (t) => {+ t.format('##,##', 0, '');+ t.format('##,##', 1, '1');+ t.format('##,##', 1234, '1,234');+ t.format('##,##', 12345, '12,345');+ t.format('##,##', 1234567, '1,234,567');+});++numfmtTest('Oddity: 0', (t) => {+ t.format('0', 12345, '12345');+ t.format('0', 4294967296.5, '4294967297');+});++numfmtTest('Oddity: "Rs."#,##0.00', (t) => {+ t.format('"Rs."#,##0.00', -51968287, '-Rs.51,968,287.00');+ t.format('"Rs."#,##0.00', 2000000, 'Rs.2,000,000.00');+});++numfmtTest('Oddity: $#.00', (t) => {+ t.format('$#.00', 3.14159, '$3.14');+ t.format('$#.00', -3.14159, '-$3.14');+});++numfmtTest.skip('Oddity: "This is a ".00"test"000', (t) => {+ t.format('"This is a ".00"test"000', -3.14159, '-This is a 3.14test159');+ t.format('"This is a ".00"test"000', 3.14159, 'This is a 3.14test159');+});++numfmtTest('Oddity: [$INR]\\ #,##0.00', (t) => {+ t.format('[$INR]\\ #,##0.00', 3.14159, 'INR 3.14');+ t.format('[$INR]\\ #,##0.00', -3.14159, '-INR 3.14');+});++numfmtTest('Oddity: [$₹-4009]\\ #,##0.00', (t) => {+ t.format('[$₹-4009]\\ #,##0.00', 3.14159, '₹ 3.14');+ t.format('[$₹-4009]\\ #,##0.00', -3.14159, '-₹ 3.14');+});++numfmtTest('Oddity: [$£-809]#,##0.0000;\\-[$£-809]#,##0.0000', (t) => {+ t.format('[$£-809]#,##0.0000;\\-[$£-809]#,##0.0000', 3.14159, '£3.1416');+ t.format('[$£-809]#,##0.0000;\\-[$£-809]#,##0.0000', -3.14159, '-£3.1416');+});++numfmtTest('Oddity: "-"0.00', (t) => {+ t.format('"-"0.00', 3.14159, '-3.14');+ t.format('"-"0.00', -3.14159, '--3.14');+});++numfmtTest('Oddity: [$-409]mmm\\-yy', (t) => {+ t.format('[$-409]mmm\\-yy', 12345, 'Oct-33');+});++numfmtTest('Oddity: \\,##.??;\\(#,###.??\\);0', (t) => {+ t.format('\\,##.??;\\(#,###.??\\);0', 15, ',15. ');+ t.format('\\,##.??;\\(#,###.??\\);0', 14.3453453, ',14.35');+ t.format('\\,##.??;\\(#,###.??\\);0', 12.1, ',12.1 ');+ t.format('\\,##.??;\\(#,###.??\\);0', 0, '0');+ t.format('\\,##.??;\\(#,###.??\\);0', -15, '(15. )');+ t.format('\\,##.??;\\(#,###.??\\);0', -14.3453453, '(14.35)');+ t.format('\\,##.??;\\(#,###.??\\);0', -12.1, '(12.1 )');+ t.format('\\,##.??;\\(#,###.??\\);0', 1, ',1. ');+});++numfmtTest('Oddity: "£"#.####;-"£"#.####', (t) => {+ t.format('"£"#.####;-"£"#.####', 3.141592654, '£3.1416');+ t.format('"£"#.####;-"£"#.####', -3.141592654, '-£3.1416');+});++numfmtTest('Oddity: [h]:mm:ss;@', (t) => {+ t.format('[h]:mm:ss;@', 2.9999999999999996, '72:00:00');+});++numfmtTest('Oddity: hh:mm:ss AM/PM', (t) => {+ t.format('hh:mm:ss AM/PM', 0.5, '12:00:00 PM');+});++numfmtTest('Oddity: hh:mm:ss am/pm', (t) => {+ t.format('hh:mm:ss am/pm', 0.5, '12:00:00 PM');+});++numfmtTest('Oddity: hh:mm:ss AM/P', (t) => {+ t.format('hh:mm:ss AM/P', 0.5, '12:00:00 A1/P');+});++numfmtTest('Oddity: hh:mm:ss am/p', (t) => {+ t.format('hh:mm:ss am/p', 0.5, '12:00:00 a1/p');+});++numfmtTest('Oddity: "foo";"bar";"baz";"qux";"foobar"', (t) => {+ t.throws(+ () => (format as (pattern: string) => string)('"foo";"bar";"baz";"qux";"foobar"'),+ '"foo";"bar";"baz";"qux";"foobar"'+ );+});diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-times.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-times.spec.tsnew file mode 100644index 0000000000..b14591376e--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-times.spec.ts@@ -0,0 +1,27 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTableTest } from './test-utils';++const timeFixture = process.env.NUMFMT_FULL_TABLE_TESTS === '1'+ ? 'ssf-times-full.tsv.gz'+ : 'ssf-times.tsv.gz';+numfmtTableTest('SSF time table', timeFixture);diff --git a/packages/core/src/shared/numfmt/__tests__/ssf-valid.spec.ts b/packages/core/src/shared/numfmt/__tests__/ssf-valid.spec.tsnew file mode 100644index 0000000000..13847ffc98--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/ssf-valid.spec.ts@@ -0,0 +1,467 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { numfmtTest } from './test-utils';++numfmtTest('Validity tests', (t) => {+ t.validFormat('" Excellent"', '" Excellent"');+ t.validFormat('" Fair"', '" Fair"');+ t.validFormat('" Good"', '" Good"');+ t.validFormat('" Poor"', '" Poor"');+ t.validFormat('" Very Good"', '" Very Good"');+ t.validFormat('"$"#,##0', '"$"#,##0');+ t.validFormat('"$"#,##0.00', '"$"#,##0.00');+ t.validFormat('"$"#,##0.00_);[Red]\\("$"#,##0.00\\)', '"$"#,##0.00_);[Red]\\("$"#,##0.00\\)');+ t.validFormat('"$"#,##0.00_);\\("$"#,##0.00\\)', '"$"#,##0.00_);\\("$"#,##0.00\\)');+ t.validFormat('"$"#,##0;[Red]\\-"$"#,##0', '"$"#,##0;[Red]\\-"$"#,##0');+ t.validFormat('"$"#,##0_);[Red]\\("$"#,##0\\)', '"$"#,##0_);[Red]\\("$"#,##0\\)');+ t.validFormat('"$"#,##0_);\\("$"#,##0\\)', '"$"#,##0_);\\("$"#,##0\\)');+ t.validFormat('"Haha!"\\ @\\ "Yeah!"', '"Haha!"\\ @\\ "Yeah!"');+ t.validFormat('"TRUE";"TRUE";"FALSE"', '"TRUE";"TRUE";"FALSE"');+ t.validFormat('"True";"True";"False";@', '"True";"True";"False";@');+ t.validFormat('"Years: "0', '"Years: "0');+ t.validFormat('"Yes";"Yes";"No";@', '"Yes";"Yes";"No";@');+ t.validFormat('"kl "hh:mm:ss;@', '"kl "hh:mm:ss;@');+ t.validFormat('"£"#,##0.00', '"£"#,##0.00');+ t.validFormat('"£"#,##0;[Red]\\-"£"#,##0', '"£"#,##0;[Red]\\-"£"#,##0');+ t.validFormat('"€"#,##0.00', '"€"#,##0.00');+ t.validFormat('"€"\\ #,##0.00_-', '"€"\\ #,##0.00_-');+ t.validFormat('"上午/下午 "hh"時"mm"分"ss"秒 "', '"上午/下午 "hh"時"mm"分"ss"秒 "');+ t.validFormat('"¥"#,##0.00;"¥"\\-#,##0.00', '"¥"#,##0.00;"¥"\\-#,##0.00');+ t.validFormat('#', '#');+ t.validFormat('# ?/?', '# ?/?');+ t.validFormat('# ??/??', '# ??/??');+ t.validFormat('#" "?/?', '#" "?/?');+ t.validFormat('#" "??/??', '#" "??/??');+ t.validFormat('#"abded"\\ ??/??', '#"abded"\\ ??/??');+ t.validFormat('###0.00;-###0.00', '###0.00;-###0.00');+ t.validFormat('###0;-###0', '###0;-###0');+ t.validFormat('##0.0E+0', '##0.0E+0');+ t.validFormat('#,##0', '#,##0');+ t.validFormat('#,##0 ;(#,##0)', '#,##0 ;(#,##0)');+ t.validFormat('#,##0 ;[Red](#,##0)', '#,##0 ;[Red](#,##0)');+ t.validFormat('#,##0"р.";[Red]\\-#,##0"р."', '#,##0"р.";[Red]\\-#,##0"р."');+ t.validFormat('#,##0.0', '#,##0.0');+ t.validFormat('#,##0.00', '#,##0.00');+ t.validFormat('#,##0.00 "�"', '#,##0.00 "�"');+ t.validFormat('#,##0.00 €;-#,##0.00 €', '#,##0.00 €;-#,##0.00 €');+ t.validFormat('#,##0.00"р.";[Red]\\-#,##0.00"р."', '#,##0.00"р.";[Red]\\-#,##0.00"р."');+ t.validFormat('#,##0.000', '#,##0.000');+ t.validFormat('#,##0.0000', '#,##0.0000');+ t.validFormat('#,##0.00000', '#,##0.00000');+ t.validFormat('#,##0.000000', '#,##0.000000');+ t.validFormat('#,##0.0000000', '#,##0.0000000');+ t.validFormat('#,##0.00000000', '#,##0.00000000');+ t.validFormat('#,##0.000000000', '#,##0.000000000');+ t.validFormat('#,##0.00000000;[Red]#,##0.00000000', '#,##0.00000000;[Red]#,##0.00000000');+ t.validFormat('#,##0.0000_ ', '#,##0.0000_ ');+ t.validFormat('#,##0.000_ ', '#,##0.000_ ');+ t.validFormat('#,##0.000_);\\(#,##0.000\\)', '#,##0.000_);\\(#,##0.000\\)');+ t.validFormat('#,##0.00;(#,##0.00)', '#,##0.00;(#,##0.00)');+ t.validFormat('#,##0.00;(#,##0.00);0.00', '#,##0.00;(#,##0.00);0.00');+ t.validFormat('#,##0.00;[Red](#,##0.00)', '#,##0.00;[Red](#,##0.00)');+ t.validFormat('#,##0.00;[Red]\\(#,##0.00\\)', '#,##0.00;[Red]\\(#,##0.00\\)');+ t.validFormat('#,##0.00;\\(#,##0.00\\)', '#,##0.00;\\(#,##0.00\\)');+ t.validFormat('#,##0.00[$₹-449]_);\\(#,##0.00[$₹-449]\\)', '#,##0.00[$₹-449]_);\\(#,##0.00[$₹-449]\\)');+ t.validFormat('#,##0.00\\ "р."', '#,##0.00\\ "р."');+ t.validFormat('#,##0.00\\ "р.";[Red]\\-#,##0.00\\ "р."', '#,##0.00\\ "р.";[Red]\\-#,##0.00\\ "р."');+ t.validFormat('#,##0.00\\ [$€-407]', '#,##0.00\\ [$€-407]');+ t.validFormat('#,##0.00\\ [$€-40C]', '#,##0.00\\ [$€-40C]');+ t.validFormat('#,##0.00_);\\(#,##0.00\\)', '#,##0.00_);\\(#,##0.00\\)');+ t.validFormat('#,##0.00_р_.;[Red]\\-#,##0.00_р_.', '#,##0.00_р_.;[Red]\\-#,##0.00_р_.');+ t.validFormat('#,##0.00_р_.;\\-#,##0.00_р_.', '#,##0.00_р_.;\\-#,##0.00_р_.');+ t.validFormat('#,##0.0;[Red]#,##0.0', '#,##0.0;[Red]#,##0.0');+ t.validFormat('#,##0.0_ ;\\-#,##0.0\\ ', '#,##0.0_ ;\\-#,##0.0\\ ');+ t.validFormat('#,##0.0_);[Red]\\(#,##0.0\\)', '#,##0.0_);[Red]\\(#,##0.0\\)');+ t.validFormat('#,##0.0_);\\(#,##0.0\\)', '#,##0.0_);\\(#,##0.0\\)');+ t.validFormat('#,##0;\\-#,##0;0', '#,##0;\\-#,##0;0');+ t.validFormat('#,##0\\ "р.";[Red]\\-#,##0\\ "р."', '#,##0\\ "р.";[Red]\\-#,##0\\ "р."');+ t.validFormat('#,##0\\ "р.";\\-#,##0\\ "р."', '#,##0\\ "р.";\\-#,##0\\ "р."');+ t.validFormat('#,##0\\ ;[Red]\\(#,##0\\)', '#,##0\\ ;[Red]\\(#,##0\\)');+ t.validFormat('#,##0\\ ;\\(#,##0\\)', '#,##0\\ ;\\(#,##0\\)');+ t.validFormat('#,##0_ ', '#,##0_ ');+ t.validFormat('#,##0_ ;[Red]\\-#,##0\\ ', '#,##0_ ;[Red]\\-#,##0\\ ');+ t.validFormat('#,##0_);[Red]\\(#,##0\\)', '#,##0_);[Red]\\(#,##0\\)');+ t.validFormat('#,##0_р_.;[Red]\\-#,##0_р_.', '#,##0_р_.;[Red]\\-#,##0_р_.');+ t.validFormat('#,##0_р_.;\\-#,##0_р_.', '#,##0_р_.;\\-#,##0_р_.');+ t.validFormat('#.0000,,', '#.0000,,');+ t.validFormat('#0', '#0');+ t.validFormat('#0.00', '#0.00');+ t.validFormat('#0.0000', '#0.0000');+ t.validFormat('#\\ ?/10', '#\\ ?/10');+ t.validFormat('#\\ ?/2', '#\\ ?/2');+ t.validFormat('#\\ ?/4', '#\\ ?/4');+ t.validFormat('#\\ ?/8', '#\\ ?/8');+ t.validFormat('#\\ ?/?', '#\\ ?/?');+ t.validFormat('#\\ ??/100', '#\\ ??/100');+ t.validFormat('#\\ ??/100;[Red]\\(#\\ ??/16\\)', '#\\ ??/100;[Red]\\(#\\ ??/16\\)');+ t.validFormat('#\\ ??/16', '#\\ ??/16');+ t.validFormat('#\\ ??/??', '#\\ ??/??');+ t.validFormat('#\\ ??/?????????', '#\\ ??/?????????');+ t.validFormat('#\\ ???/???', '#\\ ???/???');+ t.validFormat('**\\ #,###,#00,000.00,**', '**\\ #,###,#00,000.00,**');+ t.validFormat('0', '0');+ t.validFormat('0"abde".0"??"000E+00', '0"abde".0"??"000E+00');+ t.validFormat('0%', '0%');+ t.validFormat('0.0', '0.0');+ t.validFormat('0.0%', '0.0%');+ t.validFormat('0.00', '0.00');+ t.validFormat('0.00"°"', '0.00"°"');+ t.validFormat('0.00%', '0.00%');+ t.validFormat('0.000', '0.000');+ t.validFormat('0.000%', '0.000%');+ t.validFormat('0.0000', '0.0000');+ t.validFormat('0.000000', '0.000000');+ t.validFormat('0.00000000', '0.00000000');+ t.validFormat('0.000000000', '0.000000000');+ t.validFormat('0.000000000%', '0.000000000%');+ t.validFormat('0.00000000000', '0.00000000000');+ t.validFormat('0.000000000000000', '0.000000000000000');+ t.validFormat('0.00000000E+00', '0.00000000E+00');+ t.validFormat('0.0000E+00', '0.0000E+00');+ t.validFormat('0.00;[Red]0.00', '0.00;[Red]0.00');+ t.validFormat('0.00E+00', '0.00E+00');+ t.validFormat('0.00_);[Red]\\(0.00\\)', '0.00_);[Red]\\(0.00\\)');+ t.validFormat('0.00_);\\(0.00\\)', '0.00_);\\(0.00\\)');+ t.validFormat('0.0_ ', '0.0_ ');+ t.validFormat('00.00.00.000', '00.00.00.000');+ t.validFormat('00.000%', '00.000%');+ t.validFormat('0000', '0000');+ t.validFormat('00000', '00000');+ t.validFormat('00000000', '00000000');+ t.validFormat('000000000', '000000000');+ t.validFormat('00000\\-0000', '00000\\-0000');+ t.validFormat('00000\\-00000', '00000\\-00000');+ t.validFormat('000\\-00\\-0000', '000\\-00\\-0000');+ t.validFormat('0;[Red]0', '0;[Red]0');+ t.validFormat('0\\-00000\\-00000\\-0', '0\\-00000\\-00000\\-0');+ t.validFormat('0_);[Red]\\(0\\)', '0_);[Red]\\(0\\)');+ t.validFormat('0_);\\(0\\)', '0_);\\(0\\)');+ t.validFormat('@', '@');+ t.validFormat('A/P', 'A/P');+ t.validFormat('AM/PM', 'AM/PM');+ t.validFormat('AM/PMh"時"mm"分"ss"秒";@', 'AM/PMh"時"mm"分"ss"秒";@');+ t.validFormat('D', 'D');+ t.validFormat('DD', 'DD');+ t.validFormat('DD/MM/YY;@', 'DD/MM/YY;@');+ t.validFormat('DD/MM/YYYY', 'DD/MM/YYYY');+ t.validFormat('DD/MM/YYYY;@', 'DD/MM/YYYY;@');+ t.validFormat('DDD', 'DDD');+ t.validFormat('DDDD', 'DDDD');+ t.validFormat('DDDD", "MMMM\\ DD", "YYYY', 'DDDD", "MMMM\\ DD", "YYYY');+ t.validFormat('GENERAL', 'GENERAL');+ t.validFormat('General', 'General');+ t.validFormat('H', 'H');+ t.validFormat('H:MM:SS\\ AM/PM', 'H:MM:SS\\ AM/PM');+ t.validFormat('HH:MM', 'HH:MM');+ t.validFormat('HH:MM:SS\\ AM/PM', 'HH:MM:SS\\ AM/PM');+ t.validFormat('HHM', 'HHM');+ t.validFormat('HHMM', 'HHMM');+ t.validFormat('HH[MM]', 'HH[MM]');+ t.validFormat('HH[M]', 'HH[M]');+ t.validFormat('M/D/YYYY', 'M/D/YYYY');+ t.validFormat('M/D/YYYY\\ H:MM', 'M/D/YYYY\\ H:MM');+ t.validFormat('MM/DD/YY', 'MM/DD/YY');+ t.validFormat('S', 'S');+ t.validFormat('SS', 'SS');+ t.validFormat('YY', 'YY');+ t.validFormat('YYM', 'YYM');+ t.validFormat('YYMM', 'YYMM');+ t.validFormat('YYMMM', 'YYMMM');+ t.validFormat('YYMMMM', 'YYMMMM');+ t.validFormat('YYMMMMM', 'YYMMMMM');+ t.validFormat('YYYY', 'YYYY');+ t.validFormat('YYYY-MM-DD HH:MM:SS', 'YYYY-MM-DD HH:MM:SS');+ t.validFormat('YYYY\\-MM\\-DD', 'YYYY\\-MM\\-DD');+ t.validFormat('[$$-409]#,##0', '[$$-409]#,##0');+ t.validFormat('[$$-409]#,##0.00', '[$$-409]#,##0.00');+ t.validFormat('[$$-409]#,##0.00_);[Red]\\([$$-409]#,##0.00\\)', '[$$-409]#,##0.00_);[Red]\\([$$-409]#,##0.00\\)');+ t.validFormat('[$$-C09]#,##0.00', '[$$-C09]#,##0.00');+ t.validFormat('[$-100042A]h:mm:ss\\ AM/PM;@', '[$-100042A]h:mm:ss\\ AM/PM;@');+ t.validFormat('[$-1010409]0.000%', '[$-1010409]0.000%');+ t.validFormat('[$-1010409]General', '[$-1010409]General');+ t.validFormat('[$-1010409]d/m/yyyy\\ h:mm\\ AM/PM;@', '[$-1010409]d/m/yyyy\\ h:mm\\ AM/PM;@');+ t.validFormat('[$-1010409]dddd, mmmm dd, yyyy', '[$-1010409]dddd, mmmm dd, yyyy');+ t.validFormat('[$-1010409]m/d/yyyy', '[$-1010409]m/d/yyyy');+ t.validFormat('[$-1409]h:mm:ss\\ AM/PM;@', '[$-1409]h:mm:ss\\ AM/PM;@');+ t.validFormat('[$-2000000]h:mm:ss;@', '[$-2000000]h:mm:ss;@');+ t.validFormat('[$-2010401]d/mm/yyyy\\ h:mm\\ AM/PM;@', '[$-2010401]d/mm/yyyy\\ h:mm\\ AM/PM;@');+ t.validFormat('[$-4000439]h:mm:ss\\ AM/PM;@', '[$-4000439]h:mm:ss\\ AM/PM;@');+ t.validFormat('[$-4010439]d/m/yyyy\\ h:mm\\ AM/PM;@', '[$-4010439]d/m/yyyy\\ h:mm\\ AM/PM;@');+ t.validFormat('[$-409]AM/PM\\ hh:mm:ss;@', '[$-409]AM/PM\\ hh:mm:ss;@');+ t.validFormat('[$-409]d/m/yyyy\\ hh:mm;@', '[$-409]d/m/yyyy\\ hh:mm;@');+ t.validFormat('[$-409]d\\-mmm;@', '[$-409]d\\-mmm;@');+ t.validFormat('[$-409]d\\-mmm\\-yy;@', '[$-409]d\\-mmm\\-yy;@');+ t.validFormat('[$-409]d\\-mmm\\-yyyy;@', '[$-409]d\\-mmm\\-yyyy;@');+ t.validFormat('[$-409]dd/mm/yyyy\\ hh:mm;@', '[$-409]dd/mm/yyyy\\ hh:mm;@');+ t.validFormat('[$-409]dd\\-mmm\\-yy;@', '[$-409]dd\\-mmm\\-yy;@');+ t.validFormat('[$-409]h:mm:ss\\ AM/PM;@', '[$-409]h:mm:ss\\ AM/PM;@');+ t.validFormat('[$-409]h:mm\\ AM/PM;@', '[$-409]h:mm\\ AM/PM;@');+ t.validFormat('[$-409]m/d/yy\\ h:mm\\ AM/PM;@', '[$-409]m/d/yy\\ h:mm\\ AM/PM;@');+ t.validFormat('[$-409]mmm\\-yy;@', '[$-409]mmm\\-yy;@');+ t.validFormat('[$-409]mmmm\\ d\\,\\ yyyy;@', '[$-409]mmmm\\ d\\,\\ yyyy;@');+ t.validFormat('[$-409]mmmm\\-yy;@', '[$-409]mmmm\\-yy;@');+ t.validFormat('[$-409]mmmmm;@', '[$-409]mmmmm;@');+ t.validFormat('[$-409]mmmmm\\-yy;@', '[$-409]mmmmm\\-yy;@');+ t.validFormat('[$-40E]h\\ "óra"\\ m\\ "perckor"\\ AM/PM;@', '[$-40E]h\\ "óra"\\ m\\ "perckor"\\ AM/PM;@');+ t.validFormat('[$-412]AM/PM\\ h"시"\\ mm"분"\\ ss"초";@', '[$-412]AM/PM\\ h"시"\\ mm"분"\\ ss"초";@');+ t.validFormat('[$-41C]h:mm:ss\\.AM/PM;@', '[$-41C]h:mm:ss\\.AM/PM;@');+ t.validFormat('[$-449]hh:mm:ss\\ AM/PM;@', '[$-449]hh:mm:ss\\ AM/PM;@');+ t.validFormat('[$-44E]hh:mm:ss\\ AM/PM;@', '[$-44E]hh:mm:ss\\ AM/PM;@');+ t.validFormat('[$-44F]hh:mm:ss\\ AM/PM;@', '[$-44F]hh:mm:ss\\ AM/PM;@');+ t.validFormat('[$-D000409]h:mm\\ AM/PM;@', '[$-D000409]h:mm\\ AM/PM;@');+ t.validFormat('[$-D010000]d/mm/yyyy\\ h:mm\\ "น.";@', '[$-D010000]d/mm/yyyy\\ h:mm\\ "น.";@');+ t.validFormat('[$-F400]h:mm:ss\\ AM/PM', '[$-F400]h:mm:ss\\ AM/PM');+ t.validFormat('[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy', '[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy');+ t.validFormat('[$AUD]\\ #,##0.00', '[$AUD]\\ #,##0.00');+ t.validFormat('[$RD$-1C0A]#,##0.00;[Red]\\-[$RD$-1C0A]#,##0.00', '[$RD$-1C0A]#,##0.00;[Red]\\-[$RD$-1C0A]#,##0.00');+ t.validFormat('[$SFr.-810]\\ #,##0.00_);[Red]\\([$SFr.-810]\\ #,##0.00\\)', '[$SFr.-810]\\ #,##0.00_);[Red]\\([$SFr.-810]\\ #,##0.00\\)');+ t.validFormat('[$£-809]#,##0.00;[Red][$£-809]#,##0.00', '[$£-809]#,##0.00;[Red][$£-809]#,##0.00');+ t.validFormat('[$¥-411]#,##0.00', '[$¥-411]#,##0.00');+ t.validFormat('[$¥-804]#,##0.00', '[$¥-804]#,##0.00');+ t.validFormat('[<0]"";0%', '[<0]"";0%');+ t.validFormat('[<=9999999]###\\-####;\\(###\\)\\ ###\\-####', '[<=9999999]###\\-####;\\(###\\)\\ ###\\-####');+ t.validFormat('[=0]?;#,##0.00', '[=0]?;#,##0.00');+ t.validFormat('[=0]?;0%', '[=0]?;0%');+ t.validFormat('[=0]?;[<4.16666666666667][hh]:mm:ss;[hh]:mm', '[=0]?;[<4.16666666666667][hh]:mm:ss;[hh]:mm');+ t.validFormat('[>999999]#,,"M";[>999]#,"K";#', '[>999999]#,,"M";[>999]#,"K";#');+ t.validFormat('[>999999]#.000,,"M";[>999]#.000,"K";#.000', '[>999999]#.000,,"M";[>999]#.000,"K";#.000');+ t.validFormat("[>=100000]0.000\\ \\\";[Red]0.000\\ \\<\\ \\>\\ \\\"\\ \\&\\ \\'\\ ", "[>=100000]0.000\\ \\\";[Red]0.000\\ \\<\\ \\>\\ \\\"\\ \\&\\ \\'\\ ");+ t.validFormat('[>=100000]0.000\\ \\<;[Red]0.000\\ \\>', '[>=100000]0.000\\ \\<;[Red]0.000\\ \\>');+ t.validFormat('[BLACK]@', '[BLACK]@');+ t.validFormat('[BLUE]GENERAL', '[BLUE]GENERAL');+ t.validFormat('[Black]@', '[Black]@');+ t.validFormat('[Blue]General', '[Blue]General');+ t.validFormat('[CYAN]@', '[CYAN]@');+ t.validFormat('[Cyan]@', '[Cyan]@');+ t.validFormat('[DBNum1][$-804]AM/PMh"时"mm"分";@', '[DBNum1][$-804]AM/PMh"时"mm"分";@');+ t.validFormat('[DBNum1][$-804]General', '[DBNum1][$-804]General');+ t.validFormat('[DBNum1][$-804]h"时"mm"分";@', '[DBNum1][$-804]h"时"mm"分";@');+ t.validFormat('[$-1004]dddd\\,\\ d\\ mmmm\\,\\ yyyy;@', '[$-1004]dddd\\,\\ d\\ mmmm\\,\\ yyyy;@');+ t.validFormat('[$-101040D]d\\ mmmm\\ yyyy;@', '[$-101040D]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-101042A]d\\ mmmm\\ yyyy;@', '[$-101042A]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-140C]dddd\\ "YeahWoo!"\\ ddd\\ mmmm\\ yyyy;@', '[$-140C]dddd\\ "YeahWoo!"\\ ddd\\ mmmm\\ yyyy;@');+ t.validFormat('[$-2C0A]dddd\\ d" de "mmmm" de "yyyy;@', '[$-2C0A]dddd\\ d" de "mmmm" de "yyyy;@');+ t.validFormat('[$-402]dd\\ mmmm\\ yyyy\\ "г.";@', '[$-402]dd\\ mmmm\\ yyyy\\ "г.";@');+ t.validFormat('[$-403]dddd\\,\\ d" / "mmmm" / "yyyy;@', '[$-403]dddd\\,\\ d" / "mmmm" / "yyyy;@');+ t.validFormat('[$-405]d\\.\\ mmmm\\ yyyy;@', '[$-405]d\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-408]d\\ mmmm\\ yyyy;@', '[$-408]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-409]d\\-mmm;@', '[$-409]d\\-mmm;@');+ t.validFormat('[$-409]d\\-mmm\\-yy;@', '[$-409]d\\-mmm\\-yy;@');+ t.validFormat('[$-409]d\\-mmm\\-yyyy;@', '[$-409]d\\-mmm\\-yyyy;@');+ t.validFormat('[$-409]dd\\-mmm\\-yy;@', '[$-409]dd\\-mmm\\-yy;@');+ t.validFormat('[$-409]mmm\\-yy;@', '[$-409]mmm\\-yy;@');+ t.validFormat('[$-409]mmmm\\ d\\,\\ yyyy;@', '[$-409]mmmm\\ d\\,\\ yyyy;@');+ t.validFormat('[$-409]mmmm\\-yy;@', '[$-409]mmmm\\-yy;@');+ t.validFormat('[$-40B]d\\.\\ mmmm\\t\\a\\ yyyy;@', '[$-40B]d\\.\\ mmmm\\t\\a\\ yyyy;@');+ t.validFormat('[$-40C]d/mmm/yyyy;@', '[$-40C]d/mmm/yyyy;@');+ t.validFormat('[$-40E]yyyy/\\ mmmm\\ d\\.;@', '[$-40E]yyyy/\\ mmmm\\ d\\.;@');+ t.validFormat('[$-40F]dd\\.\\ mmmm\\ yyyy;@', '[$-40F]dd\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-410]d\\ mmmm\\ yyyy;@', '[$-410]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-415]d\\ mmmm\\ yyyy;@', '[$-415]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-416]d\\ \\ mmmm\\,\\ yyyy;@', '[$-416]d\\ \\ mmmm\\,\\ yyyy;@');+ t.validFormat('[$-418]d\\ mmmm\\ yyyy;@', '[$-418]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-41A]d\\.\\ mmmm\\ yyyy\\.;@', '[$-41A]d\\.\\ mmmm\\ yyyy\\.;@');+ t.validFormat('[$-41B]d\\.\\ mmmm\\ yyyy;@', '[$-41B]d\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-41D]"den "\\ d\\ mmmm\\ yyyy;@', '[$-41D]"den "\\ d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-420]dddd\\,\\ dd\\ mmmm\\,\\ yyyy;@', '[$-420]dddd\\,\\ dd\\ mmmm\\,\\ yyyy;@');+ t.validFormat('[$-421]dd\\ mmmm\\ yyyy;@', '[$-421]dd\\ mmmm\\ yyyy;@');+ t.validFormat('[$-424]dddd\\,\\ d\\.\\ mmmm\\ yyyy;@', '[$-424]dddd\\,\\ d\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-425]dddd\\,\\ d\\.\\ mmmm\\ yyyy;@', '[$-425]dddd\\,\\ d\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-426]dddd\\,\\ yyyy". gada "d\\.\\ mmmm;@', '[$-426]dddd\\,\\ yyyy". gada "d\\.\\ mmmm;@');+ t.validFormat('[$-427]yyyy\\ "m."\\ mmmm\\ d\\ "d.";@', '[$-427]yyyy\\ "m."\\ mmmm\\ d\\ "d.";@');+ t.validFormat('[$-42B]dddd\\,\\ d\\ mmmm\\ yyyy;@', '[$-42B]dddd\\,\\ d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-42C]d\\ mmmm\\ yyyy;@', '[$-42C]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-42D]yyyy"(e)ko"\\ mmmm"ren"\\ d"a";@', '[$-42D]yyyy"(e)ko"\\ mmmm"ren"\\ d"a";@');+ t.validFormat('[$-42F]dddd\\,\\ dd\\ mmmm\\ yyyy;@', '[$-42F]dddd\\,\\ dd\\ mmmm\\ yyyy;@');+ t.validFormat('[$-437]yyyy\\ \\წ\\ლ\\ი\\ს\\ dd\\ mm\\,\\ dddd;@', '[$-437]yyyy\\ \\წ\\ლ\\ი\\ს\\ dd\\ mm\\,\\ dddd;@');+ t.validFormat('[$-438]d\\.\\ mmmm\\ yyyy;@', '[$-438]d\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-43F]d\\ mmmm\\ yyyy\\ "ж.";@', '[$-43F]d\\ mmmm\\ yyyy\\ "ж.";@');+ t.validFormat('[$-444]d\\ mmmm\\ yyyy;@', '[$-444]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-449]dd\\ mmmm\\ yyyy;@', '[$-449]dd\\ mmmm\\ yyyy;@');+ t.validFormat('[$-44E]d\\ mmmm\\ yyyy;@', '[$-44E]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-44F]dd\\ mmmm\\ yyyy\\ dddd;@', '[$-44F]dd\\ mmmm\\ yyyy\\ dddd;@');+ t.validFormat('[$-457]dd\\ mmmm\\ yyyy;@', '[$-457]dd\\ mmmm\\ yyyy;@');+ t.validFormat('[$-813]dddd\\ d\\ mmmm\\ yyyy;@', '[$-813]dddd\\ d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-81A]dddd\\,\\ d\\.\\ mmmm\\ yyyy;@', '[$-81A]dddd\\,\\ d\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-82C]d\\ mmmm\\ yyyy;@', '[$-82C]d\\ mmmm\\ yyyy;@');+ t.validFormat('[$-843]yyyy\\ "й""и""л"\\ d/mmmm;@', '[$-843]yyyy\\ "й""и""л"\\ d/mmmm;@');+ t.validFormat('[$-C07]dddd\\,\\ dd\\.\\ mmmm\\ yyyy;@', '[$-C07]dddd\\,\\ dd\\.\\ mmmm\\ yyyy;@');+ t.validFormat('[$-FC19]yyyy\\,\\ dd\\ mmmm;@', '[$-FC19]yyyy\\,\\ dd\\ mmmm;@');+ t.validFormat('[$-FC22]d\\ mmmm\\ yyyy" р.";@', '[$-FC22]d\\ mmmm\\ yyyy" р.";@');+ t.validFormat('[$-FC23]d\\ mmmm\\ yyyy;@', '[$-FC23]d\\ mmmm\\ yyyy;@');+ t.validFormat('[GREEN]#,###', '[GREEN]#,###');+ t.validFormat('[Green]#,###', '[Green]#,###');+ t.validFormat('[HH]', '[HH]');+ t.validFormat('[$-2060401]d/mm/yyyy\\ h:mm\\ AM/PM;@', '[$-2060401]d/mm/yyyy\\ h:mm\\ AM/PM;@');+ t.validFormat('[$-2060401]d\\ mmmm\\ yyyy;@', '[$-2060401]d\\ mmmm\\ yyyy;@');+ t.validFormat('[H]', '[H]');+ t.validFormat('[$-411]gggyy"年"m"月"d"日"\\ dddd;@', '[$-411]gggyy"年"m"月"d"日"\\ dddd;@');+ t.validFormat('[MAGENTA]0.00', '[MAGENTA]0.00');+ t.validFormat('[Magenta]0.00', '[Magenta]0.00');+ t.validFormat('[RED]#.##', '[RED]#.##');+ t.validFormat('[Red]#.##', '[Red]#.##');+ t.validFormat('[Red][<-25]General;[Blue][>25]General;[Green]General;[Yellow]General\\ ', '[Red][<-25]General;[Blue][>25]General;[Green]General;[Yellow]General\\ ');+ t.validFormat('[Red][<=-25]General;[Blue][>=25]General;[Green]General;[Yellow]General', '[Red][<=-25]General;[Blue][>=25]General;[Green]General;[Yellow]General');+ t.validFormat('[Red][<>50]General;[Blue]000', '[Red][<>50]General;[Blue]000');+ t.validFormat('[Red][=50]General;[Blue]000', '[Red][=50]General;[Blue]000');+ t.validFormat('[SS]', '[SS]');+ t.validFormat('[S]', '[S]');+ t.validFormat('[DBNum1][$-404]y"年"m"月"d"日";@', '[DBNum1][$-404]y"年"m"月"d"日";@');+ t.validFormat('[WHITE]0.0', '[WHITE]0.0');+ t.validFormat('[White]0.0', '[White]0.0');+ t.validFormat('[YELLOW]@', '[YELLOW]@');+ t.validFormat('[Yellow]@', '[Yellow]@');+ t.validFormat('[h]', '[h]');+ t.validFormat('[h]:mm:ss', '[h]:mm:ss');+ t.validFormat('[h]:mm:ss;@', '[h]:mm:ss;@');+ t.validFormat('[h]\\.mm" Uhr ";@', '[h]\\.mm" Uhr ";@');+ t.validFormat('[hh]', '[hh]');+ t.validFormat('[s]', '[s]');+ t.validFormat('[ss]', '[ss]');+ t.validFormat('\\#\\r\\e\\c', '\\#\\r\\e\\c');+ t.validFormat('\\$#,##0_);[Red]"($"#,##0\\)', '\\$#,##0_);[Red]"($"#,##0\\)');+ t.validFormat('\\$0.00', '\\$0.00');+ t.validFormat('\\C\\O\\B\\ \\o\\n\\ @', '\\C\\O\\B\\ \\o\\n\\ @');+ t.validFormat('\\C\\R\\O\\N\\T\\A\\B\\ \\o\\n\\ @', '\\C\\R\\O\\N\\T\\A\\B\\ \\o\\n\\ @');+ t.validFormat('\\R\\e\\s\\u\\l\\t\\ \\o\\n\\ @', '\\R\\e\\s\\u\\l\\t\\ \\o\\n\\ @');+ t.validFormat('\\S\\Q\\L\\ \\:\\ @', '\\S\\Q\\L\\ \\:\\ @');+ t.validFormat('\\S\\Q\\L\\ \\R\\e\\q\\u\\e\\s\\t\\ \\f\\o\\r\\ @', '\\S\\Q\\L\\ \\R\\e\\q\\u\\e\\s\\t\\ \\f\\o\\r\\ @');+ t.validFormat('\\c\\c\\c?????0"aaaa"0"bbbb"000000.00%', '\\c\\c\\c?????0"aaaa"0"bbbb"000000.00%');+ t.validFormat('\\u\\n\\t\\i\\l\\ h:mm;@', '\\u\\n\\t\\i\\l\\ h:mm;@');+ t.validFormat('_ "¥"* #,##0.00_ "Positive";_ "¥"* \\-#,##0.00_ ;_ "¥"* "-"??_ "Negtive";_ @_ \\ "Zero"', '_ "¥"* #,##0.00_ "Positive";_ "¥"* \\-#,##0.00_ ;_ "¥"* "-"??_ "Negtive";_ @_ \\ "Zero"');+ t.validFormat('_ * #,##0.00_)[$﷼-429]_ ;_ * \\(#,##0.00\\)[$﷼-429]_ ;_ * "-"??_)[$﷼-429]_ ;_ @_ ', '_ * #,##0.00_)[$﷼-429]_ ;_ * \\(#,##0.00\\)[$﷼-429]_ ;_ * "-"??_)[$﷼-429]_ ;_ @_ ');+ t.validFormat('_ * #,##0_ ;_ * \\-#,##0_ ;[Red]_ * "-"_ ;_ @_ ', '_ * #,##0_ ;_ * \\-#,##0_ ;[Red]_ * "-"_ ;_ @_ ');+ t.validFormat('_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)', '_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)');+ t.validFormat('_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"??_);_(@_)', '_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"??_);_(@_)');+ t.validFormat('_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)', '_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)');+ t.validFormat('_(* #,##0.0000_);_(* \\(#,##0.0000\\);_(* "-"??_);_(@_)', '_(* #,##0.0000_);_(* \\(#,##0.0000\\);_(* "-"??_);_(@_)');+ t.validFormat('_(* #,##0.000_);_(* \\(#,##0.000\\);_(* "-"??_);_(@_)', '_(* #,##0.000_);_(* \\(#,##0.000\\);_(* "-"??_);_(@_)');+ t.validFormat('_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)', '_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)');+ t.validFormat('_(* #,##0.0_);_(* \\(#,##0.0\\);_(* "-"??_);_(@_)', '_(* #,##0.0_);_(* \\(#,##0.0\\);_(* "-"??_);_(@_)');+ t.validFormat('_(* #,##0_);_(* \\(#,##0\\);_(* "-"??_);_(@_)', '_(* #,##0_);_(* \\(#,##0\\);_(* "-"??_);_(@_)');+ t.validFormat('_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)', '_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)');+ t.validFormat('_([$ANG]\\ * #,##0.0_);_([$ANG]\\ * \\(#,##0.0\\);_([$ANG]\\ * "-"?_);_(@_)', '_([$ANG]\\ * #,##0.0_);_([$ANG]\\ * \\(#,##0.0\\);_([$ANG]\\ * "-"?_);_(@_)');+ t.validFormat('_-"€"\\ * #,##0.00_-;_-"€"\\ * #,##0.00\\-;_-"€"\\ * "-"??_-;_-@_-', '_-"€"\\ * #,##0.00_-;_-"€"\\ * #,##0.00\\-;_-"€"\\ * "-"??_-;_-@_-');+ t.validFormat('_-* #,##0.00" TL"_-;\\-* #,##0.00" TL"_-;_-* \\-??" TL"_-;_-@_-', '_-* #,##0.00" TL"_-;\\-* #,##0.00" TL"_-;_-* \\-??" TL"_-;_-@_-');+ t.validFormat('_-* #,##0.00" €"_-;\\-* #,##0.00" €"_-;_-* \\-??" €"_-;_-@_-', '_-* #,##0.00" €"_-;\\-* #,##0.00" €"_-;_-* \\-??" €"_-;_-@_-');+ t.validFormat('_-* #,##0.00\\ "р."_-;\\-* #,##0.00\\ "р."_-;_-* "-"??\\ "р."_-;_-@_-', '_-* #,##0.00\\ "р."_-;\\-* #,##0.00\\ "р."_-;_-* "-"??\\ "р."_-;_-@_-');+ t.validFormat('_-* #,##0.00\\ "€"_-;\\-* #,##0.00\\ "€"_-;_-* "-"??\\ "€"_-;_-@_-', '_-* #,##0.00\\ "€"_-;\\-* #,##0.00\\ "€"_-;_-* "-"??\\ "€"_-;_-@_-');+ t.validFormat('_-* #,##0.00\\ [$€-407]_-;\\-* #,##0.00\\ [$€-407]_-;_-* \\-??\\ [$€-407]_-;_-@_-', '_-* #,##0.00\\ [$€-407]_-;\\-* #,##0.00\\ [$€-407]_-;_-* \\-??\\ [$€-407]_-;_-@_-');+ t.validFormat('_-* #,##0.0\\ _F_-;\\-* #,##0.0\\ _F_-;_-* "-"??\\ _F_-;_-@_-', '_-* #,##0.0\\ _F_-;\\-* #,##0.0\\ _F_-;_-* "-"??\\ _F_-;_-@_-');+ t.validFormat('_-* #,##0\\ "€"_-;\\-* #,##0\\ "€"_-;_-* "-"\\ "€"_-;_-@_-', '_-* #,##0\\ "€"_-;\\-* #,##0\\ "€"_-;_-* "-"\\ "€"_-;_-@_-');+ t.validFormat('_-* #,##0_-;\\-* #,##0_-;_-* "-"??_-;_-@_-', '_-* #,##0_-;\\-* #,##0_-;_-* "-"??_-;_-@_-');+ t.validFormat('_-\\$* #,##0.0_ ;_-\\$* \\-#,##0.0\\ ;_-\\$* "-"?_ ;_-@_ ', '_-\\$* #,##0.0_ ;_-\\$* \\-#,##0.0\\ ;_-\\$* "-"?_ ;_-@_ ');+ t.validFormat('d', 'd');+ t.validFormat('d-mmm', 'd-mmm');+ t.validFormat('d-mmm-yy', 'd-mmm-yy');+ t.validFormat('d/m', 'd/m');+ t.validFormat('d/m/yy;@', 'd/m/yy;@');+ t.validFormat('d/m/yyyy;@', 'd/m/yyyy;@');+ t.validFormat('d/mm/yy;@', 'd/mm/yy;@');+ t.validFormat('d/mm/yyyy;@', 'd/mm/yyyy;@');+ t.validFormat('d\\-mmm', 'd\\-mmm');+ t.validFormat('d\\-mmm\\-yyyy', 'd\\-mmm\\-yyyy');+ t.validFormat('dd', 'dd');+ t.validFormat('dd"-"mmm"-"yyyy', 'dd"-"mmm"-"yyyy');+ t.validFormat('dd/m/yyyy', 'dd/m/yyyy');+ t.validFormat('dd/mm/yy', 'dd/mm/yy');+ t.validFormat('dd/mm/yy;@', 'dd/mm/yy;@');+ t.validFormat('dd/mm/yy\\ hh:mm', 'dd/mm/yy\\ hh:mm');+ t.validFormat('dd/mm/yyyy', 'dd/mm/yyyy');+ t.validFormat('dd/mm/yyyy\\ hh:mm:ss', 'dd/mm/yyyy\\ hh:mm:ss');+ t.validFormat('dd/mmm', 'dd/mmm');+ t.validFormat('dd\\-mm\\-yy', 'dd\\-mm\\-yy');+ t.validFormat('dd\\-mmm\\-yy', 'dd\\-mmm\\-yy');+ t.validFormat('dd\\-mmm\\-yyyy\\ hh:mm:ss.000', 'dd\\-mmm\\-yyyy\\ hh:mm:ss.000');+ t.validFormat('dd\\/mm\\/yy', 'dd\\/mm\\/yy');+ t.validFormat('dd\\/mm\\/yyyy', 'dd\\/mm\\/yyyy');+ t.validFormat('ddd', 'ddd');+ t.validFormat('dddd', 'dddd');+ t.validFormat('dddd, mmmm dd, yyyy', 'dddd, mmmm dd, yyyy');+ t.validFormat('h', 'h');+ t.validFormat('h"时"mm"分"ss"秒";@', 'h"时"mm"分"ss"秒";@');+ t.validFormat('h"時"mm"分"ss"秒";@', 'h"時"mm"分"ss"秒";@');+ t.validFormat('h:mm', 'h:mm');+ t.validFormat('h:mm AM/PM', 'h:mm AM/PM');+ t.validFormat('h:mm:ss', 'h:mm:ss');+ t.validFormat('h:mm:ss AM/PM', 'h:mm:ss AM/PM');+ t.validFormat('h:mm:ss;@', 'h:mm:ss;@');+ t.validFormat('h:mm;@', 'h:mm;@');+ t.validFormat('h\\.mm" Uhr ";@', 'h\\.mm" Uhr ";@');+ t.validFormat('h\\.mm" h";@', 'h\\.mm" h";@');+ t.validFormat('h\\.mm" u.";@', 'h\\.mm" u.";@');+ t.validFormat('hh":"mm AM/PM', 'hh":"mm AM/PM');+ t.validFormat('hh:mm:ss', 'hh:mm:ss');+ t.validFormat('hh:mm:ss\\ AM/PM', 'hh:mm:ss\\ AM/PM');+ t.validFormat('hh\\.mm" h";@', 'hh\\.mm" h";@');+ t.validFormat('hhm', 'hhm');+ t.validFormat('hhmm', 'hhmm');+ t.validFormat('m"月"d"日"', 'm"月"d"日"');+ t.validFormat('m/d/yy', 'm/d/yy');+ t.validFormat('m/d/yy h:mm', 'm/d/yy h:mm');+ t.validFormat('m/d/yy;@', 'm/d/yy;@');+ t.validFormat('m/d/yy\\ h:mm', 'm/d/yy\\ h:mm');+ t.validFormat('m/d/yy\\ h:mm;@', 'm/d/yy\\ h:mm;@');+ t.validFormat('m/d/yyyy', 'm/d/yyyy');+ t.validFormat('m/d/yyyy;@', 'm/d/yyyy;@');+ t.validFormat('m/d/yyyy\\ h:mm:ss;@', 'm/d/yyyy\\ h:mm:ss;@');+ t.validFormat('m/d;@', 'm/d;@');+ t.validFormat('m\\/d\\/yyyy', 'm\\/d\\/yyyy');+ t.validFormat('mm/dd', 'mm/dd');+ t.validFormat('mm/dd/yy', 'mm/dd/yy');+ t.validFormat('mm/dd/yy;@', 'mm/dd/yy;@');+ t.validFormat('mm/dd/yyyy', 'mm/dd/yyyy');+ t.validFormat('mm:ss', 'mm:ss');+ t.validFormat('mm:ss.0;@', 'mm:ss.0;@');+ t.validFormat('mmm d, yyyy', 'mmm d, yyyy');+ t.validFormat('mmm" "d", "yyyy', 'mmm" "d", "yyyy');+ t.validFormat('mmm-yy', 'mmm-yy');+ t.validFormat('mmm-yy;@', 'mmm-yy;@');+ t.validFormat('mmm/yy', 'mmm/yy');+ t.validFormat('mmm\\-yy', 'mmm\\-yy');+ t.validFormat('mmm\\-yy;@', 'mmm\\-yy;@');+ t.validFormat('mmm\\-yyyy', 'mmm\\-yyyy');+ t.validFormat('mmmm\\ d\\,\\ yyyy', 'mmmm\\ d\\,\\ yyyy');+ t.validFormat('mmmm\\ yyyy', 'mmmm\\ yyyy');+ t.validFormat('mmss.0', 'mmss.0');+ t.validFormat('s', 's');+ t.validFormat('ss', 'ss');+ t.validFormat('yy', 'yy');+ t.validFormat('yy/mm/dd', 'yy/mm/dd');+ t.validFormat('yy\\.mm\\.dd', 'yy\\.mm\\.dd');+ t.validFormat('yym', 'yym');+ t.validFormat('yymm', 'yymm');+ t.validFormat('yymmm', 'yymmm');+ t.validFormat('yymmmm', 'yymmmm');+ t.validFormat('yymmmmm', 'yymmmmm');+ t.validFormat('yyyy', 'yyyy');+ t.validFormat('yyyy"년"\\ m"월"\\ d"일";@', 'yyyy"년"\\ m"월"\\ d"일";@');+ t.validFormat('yyyy-m-d h:mm AM/PM', 'yyyy-m-d h:mm AM/PM');+ t.validFormat('yyyy-mm-dd', 'yyyy-mm-dd');+ t.validFormat('yyyy/mm/dd', 'yyyy/mm/dd');+ t.validFormat('yyyy\\-m\\-d\\ hh:mm:ss', 'yyyy\\-m\\-d\\ hh:mm:ss');+ t.validFormat('yyyy\\-mm\\-dd', 'yyyy\\-mm\\-dd');+ t.validFormat('yyyy\\-mm\\-dd;@', 'yyyy\\-mm\\-dd;@');+ t.validFormat('yyyy\\-mm\\-dd\\ h:mm', 'yyyy\\-mm\\-dd\\ h:mm');+ t.validFormat('yyyy\\-mm\\-dd\\Thh:mm', 'yyyy\\-mm\\-dd\\Thh:mm');+ t.validFormat('yyyy\\-mm\\-dd\\Thhmmss.000', 'yyyy\\-mm\\-dd\\Thhmmss.000');+});diff --git a/packages/core/src/shared/numfmt/__tests__/test-utils.ts b/packages/core/src/shared/numfmt/__tests__/test-utils.tsnew file mode 100644index 0000000000..88d7143813--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/test-utils.ts@@ -0,0 +1,250 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import type { FormatColor, FormatDateInfo, FormatInfo, FormatOptions } from '../types';+import { readFileSync } from 'node:fs';+import { fileURLToPath } from 'node:url';+import { gunzipSync } from 'node:zlib';+import { expect, it } from 'vitest';+import { format, formatColor, getFormatDateInfo, getFormatInfo } from '../api';++export interface INumfmtTestContext {+ equal(actual: unknown, expected: unknown, message?: string): void;+ deepEqual(actual: unknown, expected: unknown, message?: string): void;+ deepLooseEqual(actual: unknown, expected: unknown, message?: string): void;+ ok(actual: unknown, message?: string): void;+ throws(action: () => unknown, message?: string): void;+ format(+ pattern: string,+ value: unknown,+ expected: string,+ options?: FormatOptions+ ): void;+ validFormat(pattern: string, details?: unknown): void;+ formatColor(+ pattern: string,+ value: unknown,+ expected: FormatColor,+ options?: FormatOptions+ ): void;+ formatInvalid(pattern: string, options?: unknown): void;+ formatThrows(+ pattern: string,+ value: unknown,+ expected?: string | RegExp,+ options?: FormatOptions+ ): void;+ assertInfo(pattern: string, expected: Partial<FormatInfo>): void;+ assertDateInfo(pattern: string, expected: Partial<FormatDateInfo>): void;+}++const COMMON_INFO: Omit<FormatInfo, 'type' | 'code'> & {+ type?: FormatInfo['type'];+ code?: string;+} = {+ isDate: false,+ isText: false,+ isPercent: false,+ maxDecimals: 0,+ grouped: 0,+ parentheses: 0,+ color: 0,+ scale: 1,+ level: 0,+};++const COMMON_DATE_INFO: FormatDateInfo = {+ year: false,+ month: false,+ day: false,+ hours: false,+ minutes: false,+ seconds: false,+ clockType: 24,+};++function createContext(): INumfmtTestContext {+ return {+ equal(actual, expected, message) {+ expect(actual, message).toBe(expected);+ },+ deepEqual(actual, expected, message) {+ expect(actual, message).toEqual(expected);+ },+ deepLooseEqual(actual, expected, message) {+ expect(actual, message).toEqual(expected);+ },+ ok(actual, message) {+ expect(actual, message).toBeTruthy();+ },+ throws(action, message) {+ expect(action, message).toThrow();+ },+ format(pattern, value, expected, options = {}) {+ expect(format(pattern, value, options), pattern).toBe(expected);+ },+ validFormat(pattern) {+ expect(() => format(pattern, 1), pattern).not.toThrow();+ },+ formatColor(pattern, value, expected, options = {}) {+ expect(formatColor(pattern, value, options), pattern).toBe(expected);+ },+ formatInvalid(pattern, options) {+ expect(+ () => format(pattern, '', options as FormatOptions),+ pattern+ ).toThrow();+ },+ formatThrows(pattern, value, expected, options = {}) {+ const assertion = expect(+ () => format(pattern, value, options),+ typeof expected === 'string' ? expected : pattern+ );+ if (expected instanceof RegExp) {+ assertion.toThrow(expected);+ } else {+ assertion.toThrow();+ }+ },+ assertInfo(pattern, expected) {+ expect(getFormatInfo(pattern), pattern).toEqual({+ ...COMMON_INFO,+ ...expected,+ });+ },+ assertDateInfo(pattern, expected) {+ expect(getFormatDateInfo(pattern), pattern).toEqual({+ ...COMMON_DATE_INFO,+ ...expected,+ });+ },+ };+}++function runNumfmtTestBody(body: (context: INumfmtTestContext) => void): void {+ const previousTimezone = process.env.TZ;+ try {+ body(createContext());+ } finally {+ if (previousTimezone === undefined) {+ delete process.env.TZ;+ } else {+ process.env.TZ = previousTimezone;+ }+ }+}++interface INumfmtTest {+ (name: string, body: (context: INumfmtTestContext) => void): void;+ skip(name: string, body: (context: INumfmtTestContext) => void): void;+}++export const numfmtTest: INumfmtTest = Object.assign(+ (name: string, body: (context: INumfmtTestContext) => void): void => {+ it(name, () => runNumfmtTestBody(body));+ },+ {+ skip(name: string, body: (context: INumfmtTestContext) => void): void {+ it.skip(name, () => runNumfmtTestBody(body));+ },+ }+);++export type TableFixture =+ | 'cal-updated.tsv.gz'+ | 'ssf-dates.tsv.gz'+ | 'ssf-times.tsv.gz'+ | 'ssf-times-full.tsv.gz';++export function numfmtTableTest(title: string, fixture: TableFixture): void {+ const enabled =+ process.env.NUMFMT_TABLE_TESTS === '1' ||+ process.env.NUMFMT_FULL_TABLE_TESTS === '1';++ it.skipIf(!enabled)(title, () => {+ const filename = fileURLToPath(new URL(`./fixtures/${fixture}`, import.meta.url));+ const table = gunzipSync(readFileSync(filename))+ .toString('utf8')+ .replace(/\r/g, '')+ .split('\n')+ .map((row) => row.replace(/#{255}/g, '').split('\t'));+ const headers = table[0].slice(1);+ let failureCount = 0;+ const diagnostics: string[] = [];++ headers.forEach((pattern, patternIndex) => {+ for (let rowIndex = 1; rowIndex < table.length; rowIndex++) {+ const row = table[rowIndex];+ if (!row[0]) {+ break;+ }++ const expected = row[patternIndex + 1] === '######'+ ? '#VALUE!'+ : row[patternIndex + 1];+ let actual: string;++ try {+ actual = format(pattern, Number.parseFloat(row[0]), {+ dateSpanLarge: false,+ dateErrorNumber: false,+ dateErrorThrows: true,+ });+ } catch {+ actual = '#VALUE!';+ }++ if (actual !== expected) {+ failureCount++;+ if (diagnostics.length < 50) {+ diagnostics.push(+ `${String(rowIndex - 1)}: numfmt(${pattern}, ${+ row[0]}) => ${actual} !== ${expected}`+ );+ }+ }+ }+ });++ expect(failureCount, diagnostics.join('\n')).toBe(0);+ });+}++export function getTimeZoneName(): string {+ const dateString = new Date().toString();+ return dateString.replace(/^.*GMT\+\d{4} \((.*?)\)$/, '$1');+}++export function getTimeZoneOffset(date: Date): number {+ const utc = new Date();+ utc.setUTCFullYear(date.getFullYear(), date.getMonth(), date.getDate());+ utc.setUTCHours(+ date.getHours(),+ date.getMinutes(),+ date.getSeconds(),+ date.getMilliseconds()+ );+ return (date.getTime() - utc.getTime()) / 60000;+}++export function isLeapYear(year: number): boolean {+ return Boolean((!(year % 4) && year % 100) || !(year % 400));+}diff --git a/packages/core/src/shared/numfmt/__tests__/text.spec.ts b/packages/core/src/shared/numfmt/__tests__/text.spec.tsnew file mode 100644index 0000000000..5ba95758d7--- /dev/null+++ b/packages/core/src/shared/numfmt/__tests__/text.spec.ts@@ -0,0 +1,47 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// @vitest-environment node++import { format } from '../api';+import { numfmtTest } from './test-utils';++numfmtTest('Errors', (t) => {+ // no more than a single text section+ t.throws(() => format('@;@', undefined), '@;@');+});++numfmtTest('Repeated @ in same pattern', (t) => {+ t.format('@@', 1, '1');+ t.format('@@', -1, '-1');+ t.format('@@', 0, '0');+ t.format('@@', 'text', 'texttext');+});++numfmtTest('Text in combination with other things', (t) => {+ t.format('@ "foo"', 1, '1');+ t.format('@ "foo"', -1, '-1');+ t.format('@ "foo"', 0, '0');+ t.format('@ "foo"', 'text', 'text foo');++ t.format('"bar" @ "foo"', 1, '1');+ t.format('"bar" @ "foo"', -1, '-1');+ t.format('"bar" @ "foo"', 0, '0');+ t.format('"bar" @ "foo"', 'text', 'bar text foo');+});diff --git a/packages/core/src/shared/numfmt/api.ts b/packages/core/src/shared/numfmt/api.tsnew file mode 100644index 0000000000..c4731133d1--- /dev/null+++ b/packages/core/src/shared/numfmt/api.ts@@ -0,0 +1,231 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type {+ FormatColor,+ FormatDateInfo,+ FormatInfo,+ FormatOptions,+ ParsedPattern,+ ResolvedFormatOptions,+} from './types';+import {+ TOKEN_AMPM,+ TOKEN_BREAK,+ TOKEN_CALENDAR,+ TOKEN_CHAR,+ TOKEN_COLOR,+ TOKEN_COMMA,+ TOKEN_CONDITION,+ TOKEN_DATETIME,+ TOKEN_DBNUM,+ TOKEN_DIGIT,+ TOKEN_DURATION,+ TOKEN_ERROR,+ TOKEN_ESCAPED,+ TOKEN_EXP,+ TOKEN_FILL,+ TOKEN_GENERAL,+ TOKEN_GROUP,+ TOKEN_HASH,+ TOKEN_LOCALE,+ TOKEN_MINUS,+ TOKEN_MODIFIER,+ TOKEN_NATNUM,+ TOKEN_PAREN,+ TOKEN_PERCENT,+ TOKEN_PLUS,+ TOKEN_POINT,+ TOKEN_QMARK,+ TOKEN_SCALE,+ TOKEN_SKIP,+ TOKEN_SLASH,+ TOKEN_SPACE,+ TOKEN_STRING,+ TOKEN_TEXT,+ TOKEN_ZERO,+} from './constants';+import { dateInfo, info, isDate, isPercent, isText } from './format-info';+import { formatValue, formatColor as formatValueColor } from './format-number';+import { defaultOptions } from './options';+import { parsePattern } from './parse-pattern';+import { dateToSerial as handleDates } from './serial-date';++export { dec2frac } from './dec-to-frac';+export { addLocale, getLocale, parseLocale } from './locale';+export { parseBool, parseDate, parseNumber, parseTime, parseValue } from './parse-value';+export { round } from './round';+export { dateFromSerial, dateToSerial } from './serial-date';+export { tokenize } from './tokenize';++export type {+ FormatDateInfo,+ FormatInfo,+ FormatToken,+ LocaleData,+ LocaleToken,+ ParseData,+} from './types';++const parseDataCache: Record<string, ParsedPattern> = Object.create({});++function prepareFormatterData(pattern: string, shouldThrow: boolean = false): ParsedPattern {+ const normalizedPattern = pattern || 'General';++ let parseData = parseDataCache[normalizedPattern];+ if (!parseData) {+ try {+ parseData = parsePattern(normalizedPattern);+ parseDataCache[normalizedPattern] = parseData;+ } catch (error: unknown) {+ // if the options say to throw errors, then do so+ if (shouldThrow) {+ throw error;+ }+ // else we set the parse data to error+ const message = error instanceof Error ? error.message : String(error);+ const errorPart = {+ tokens: [{ type: 'error' }],+ error: message,+ };+ parseData = {+ pattern: normalizedPattern,+ partitions: [errorPart, errorPart, errorPart, errorPart],+ error: message,+ locale: null,+ };+ }+ }+ return parseData;+}++/**+ * Formats a value as a string and returns the result.+ */+export function format(+ pattern: string,+ value: unknown,+ options: FormatOptions = {}+): string {+ const resolvedOptions = Object.assign({}, defaultOptions, options) as ResolvedFormatOptions;+ const data = prepareFormatterData(pattern, resolvedOptions.throws);+ const normalizedValue = handleDates(value, resolvedOptions) ?? value;+ return formatValue(normalizedValue, data, resolvedOptions);+}++/**+ * Find the color appropriate to a value as dictated by a format pattern.+ */+export function formatColor(+ pattern: string,+ value: unknown,+ options?: FormatOptions+): FormatColor {+ const resolvedOptions = Object.assign({}, defaultOptions, options) as ResolvedFormatOptions;+ const data = prepareFormatterData(pattern, resolvedOptions.throws);+ const normalizedValue = handleDates(value, resolvedOptions) ?? value;+ return formatValueColor(normalizedValue, data, resolvedOptions);+}++/** Determine if a given format pattern is a date pattern. */+export function isDateFormat(pattern: string): boolean {+ const data = prepareFormatterData(pattern, false);+ return isDate(data.partitions);+}++/** Determine if a given format pattern is a percentage pattern. */+export function isPercentFormat(pattern: string): boolean {+ const data = prepareFormatterData(pattern, false);+ return isPercent(data.partitions);+}++/** Determine if a given format pattern is a text only pattern. */+export function isTextFormat(pattern: string): boolean {+ const data = prepareFormatterData(pattern, false);+ return isText(data.partitions);+}++/** Determine if a given format pattern is valid. */+export function isValidFormat(pattern: string): boolean {+ try {+ prepareFormatterData(pattern, true);+ return true;+ } catch {+ return false;+ }+}++/** Returns metadata describing a parsed format pattern. */+export function getFormatInfo(+ pattern: string,+ options: { currency?: string } = {}+): FormatInfo {+ const data = prepareFormatterData(pattern, false);+ if (!data.info) {+ data.info = info(data.partitions, options?.currency);+ }+ return data.info;+}++/** Gets information about date codes used in a format string. */+export function getFormatDateInfo(pattern: string): FormatDateInfo {+ const data = prepareFormatterData(pattern, false);+ if (!data.dateInfo) {+ data.dateInfo = dateInfo(data.partitions);+ }+ return data.dateInfo;+}++/** A dictionary of the types used to identify token variants. */+export const tokenTypes = Object.freeze({+ AMPM: TOKEN_AMPM,+ BREAK: TOKEN_BREAK,+ CALENDAR: TOKEN_CALENDAR,+ CHAR: TOKEN_CHAR,+ COLOR: TOKEN_COLOR,+ COMMA: TOKEN_COMMA,+ CONDITION: TOKEN_CONDITION,+ DATETIME: TOKEN_DATETIME,+ DBNUM: TOKEN_DBNUM,+ DIGIT: TOKEN_DIGIT,+ DURATION: TOKEN_DURATION,+ ERROR: TOKEN_ERROR,+ ESCAPED: TOKEN_ESCAPED,+ EXP: TOKEN_EXP,+ FILL: TOKEN_FILL,+ GENERAL: TOKEN_GENERAL,+ GROUP: TOKEN_GROUP,+ HASH: TOKEN_HASH,+ LOCALE: TOKEN_LOCALE,+ MINUS: TOKEN_MINUS,+ MODIFIER: TOKEN_MODIFIER,+ NATNUM: TOKEN_NATNUM,+ PAREN: TOKEN_PAREN,+ PERCENT: TOKEN_PERCENT,+ PLUS: TOKEN_PLUS,+ POINT: TOKEN_POINT,+ QMARK: TOKEN_QMARK,+ SCALE: TOKEN_SCALE,+ SKIP: TOKEN_SKIP,+ SLASH: TOKEN_SLASH,+ SPACE: TOKEN_SPACE,+ STRING: TOKEN_STRING,+ TEXT: TOKEN_TEXT,+ ZERO: TOKEN_ZERO,+});diff --git a/packages/core/src/shared/numfmt/clamp.ts b/packages/core/src/shared/numfmt/clamp.tsnew file mode 100644index 0000000000..f619522a2b--- /dev/null+++ b/packages/core/src/shared/numfmt/clamp.ts@@ -0,0 +1,27 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++export function clamp(number: number): number {+ if (number === 0) {+ return number;+ }+ const d = Math.ceil(Math.log10(number < 0 ? -number : number));+ const mag = 10 ** (16 - Math.floor(d));+ return isFinite(mag) ? Math.round(number * mag) / mag : 0;+}diff --git a/packages/core/src/shared/numfmt/code-to-locale.ts b/packages/core/src/shared/numfmt/code-to-locale.tsnew file mode 100644index 0000000000..736d6e264a--- /dev/null+++ b/packages/core/src/shared/numfmt/code-to-locale.ts@@ -0,0 +1,208 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// https://docs.microsoft.com/en-us/office/vba/api/office.msolanguageid+export const codeToLocale = Object.freeze<Record<number, string>>({+ 1078: 'af', // Afrikaans+ 1052: 'sq', // Albanian+ 1118: 'am', // Amharic+ 5121: 'ar_DZ', // Arabic - Algeria+ 15361: 'ar_BH', // Arabic - Bahrain+ 3073: 'ar_EG', // Arabic - Egypt+ 2049: 'ar_IQ', // Arabic - Iraq+ 11265: 'ar_JO', // Arabic - Jordan+ 13313: 'ar_KW', // Arabic - Kuwait+ 12289: 'ar_LB', // Arabic - Lebanon+ 4097: 'ar_LY', // Arabic - Libya+ 6145: 'ar_MA', // Arabic - Morocco+ 8193: 'ar_OM', // Arabic - Oman+ 16385: 'ar_QA', // Arabic - Qatar+ 1025: 'ar_SA', // Arabic - Saudi Arabia+ 10241: 'ar_SY', // Arabic - Syria+ 7169: 'ar_TN', // Arabic - Tunisia+ 14337: 'ar_AE', // Arabic - United Arab Emirates+ 9217: 'ar_YE', // Arabic - Yemen+ 1067: 'hy', // Armenian+ 1101: 'as', // Assamese+ 2092: 'az_AZ', // Azeri - Cyrillic+ 1068: 'az_AZ', // Azeri - Latin+ 1069: 'eu', // Basque+ 1059: 'be', // Belarusian+ 2117: 'bn', // Bengali - Bangladesh+ 1093: 'bn_IN', // Bengali - India+ 5146: 'bs', // Bosnian+ 1026: 'bg', // Bulgarian+ 1109: 'my', // Burmese+ 1027: 'ca', // Catalan+ 2052: 'zh_CN', // Chinese - China+ 3076: 'zh_HK', // Chinese - Hong Kong SAR+ 5124: 'zh_MO', // Chinese - Macau SAR+ 4100: 'zh_SG', // Chinese - Singapore+ 1028: 'zh_TW', // Chinese - Taiwan+ 1050: 'hr', // Croatian+ 1029: 'cs', // Czech+ 1030: 'da', // Danish+ 1125: 'dv', // Divehi; Dhivehi; Maldivian+ 2067: 'nl_BE', // Dutch - Belgium+ 1043: 'nl_NL', // Dutch - Netherlands+ 1126: 'bin', // Edo+ 3081: 'en_AU', // English - Australia+ 10249: 'en_BZ', // English - Belize+ 4105: 'en_CA', // English - Canada+ 9225: 'en_CB', // English - Caribbean+ 2057: 'en_GB', // English - Great Britain+ 16393: 'en_IN', // English - India+ 6153: 'en_IE', // English - Ireland+ 8201: 'en_JM', // English - Jamaica+ 5129: 'en_NZ', // English - New Zealand+ 13321: 'en_PH', // English - Phillippines+ 7177: 'en_ZA', // English - Southern Africa+ 11273: 'en_TT', // English - Trinidad+ 1033: 'en_US', // English - United States+ 12297: 'en_ZW', // English - Zimbabwe+ 1061: 'et', // Estonian+ 1071: 'mk', // FYRO Macedonia+ 1080: 'fo', // Faroese+ 1065: 'fa', // Farsi - Persian+ 1124: 'fil', // Filipino+ 1035: 'fi', // Finnish+ 2060: 'fr_BE', // French - Belgium+ 11276: 'fr_CM', // French - Cameroon+ 3084: 'fr_CA', // French - Canada+ 9228: 'fr_CG', // French - Congo+ 12300: 'fr_CI', // French - Cote d'Ivoire+ 1036: 'fr_FR', // French - France+ 5132: 'fr_LU', // French - Luxembourg+ 13324: 'fr_ML', // French - Mali+ 6156: 'fr_MC', // French - Monaco+ 14348: 'fr_MA', // French - Morocco+ 10252: 'fr_SN', // French - Senegal+ 4108: 'fr_CH', // French - Switzerland+ 7180: 'fr', // French - West Indies+ 1122: 'fy_NL', // Frisian - Netherlands+ 2108: 'gd_IE', // Gaelic - Ireland+ 1084: 'gd', // Gaelic - Scotland+ 1110: 'gl', // Galician+ 1079: 'ka', // Georgian+ 3079: 'de_AT', // German - Austria+ 1031: 'de_DE', // German - Germany+ 5127: 'de_LI', // German - Liechtenstein+ 4103: 'de_LU', // German - Luxembourg+ 2055: 'de_CH', // German - Switzerland+ 1032: 'el', // Greek+ 1140: 'gn', // Guarani - Paraguay+ 1095: 'gu', // Gujarati+ 1279: 'en', // HID (Human Interface Device)+ 1037: 'he', // Hebrew+ 1081: 'hi', // Hindi+ 1038: 'hu', // Hungarian+ 1039: 'is', // Icelandic+ 1136: 'ig_NG', // Igbo - Nigeria+ 1057: 'id', // Indonesian+ 1040: 'it_IT', // Italian - Italy+ 2064: 'it_CH', // Italian - Switzerland+ 1041: 'ja', // Japanese+ 1099: 'kn', // Kannada+ 1120: 'ks', // Kashmiri+ 1087: 'kk', // Kazakh+ 1107: 'km', // Khmer+ 1111: 'kok', // Konkani+ 1042: 'ko', // Korean+ 1088: 'ky', // Kyrgyz - Cyrillic+ 1108: 'lo', // Lao+ 1142: 'la', // Latin+ 1062: 'lv', // Latvian+ 1063: 'lt', // Lithuanian+ 2110: 'ms_BN', // Malay - Brunei+ 1086: 'ms_MY', // Malay - Malaysia+ 1100: 'ml', // Malayalam+ 1082: 'mt', // Maltese+ 1112: 'mni', // Manipuri+ 1153: 'mi', // Maori+ 1102: 'mr', // Marathi+ 1104: 'mn', // Mongolian+ 2128: 'mn', // Mongolian+ 1121: 'ne', // Nepali+ 1044: 'no_NO', // Norwegian - Bokml+ 2068: 'no_NO', // Norwegian - Nynorsk+ 1096: 'or', // Oriya+ 1045: 'pl', // Polish+ 1046: 'pt_BR', // Portuguese - Brazil+ 2070: 'pt_PT', // Portuguese - Portugal+ 1094: 'pa', // Punjabi+ 1047: 'rm', // Raeto-Romance+ 2072: 'ro_MO', // Romanian - Moldova+ 1048: 'ro_RO', // Romanian - Romania+ 1049: 'ru', // Russian+ 2073: 'ru_MO', // Russian - Moldova+ 1083: 'se', // Sami Lappish+ 1103: 'sa', // Sanskrit+ 3098: 'sr_SP', // Serbian - Cyrillic+ 2074: 'sr_SP', // Serbian - Latin+ 1072: 'st', // Sesotho (Sutu)+ 1074: 'tn', // Setsuana+ 1113: 'sd', // Sindhi+ 1115: 'si', // Sinhala; Sinhalese+ 1051: 'sk', // Slovak+ 1060: 'sl', // Slovenian+ 1143: 'so', // Somali+ 1070: 'sb', // Sorbian+ 11274: 'es_AR', // Spanish - Argentina+ 16394: 'es_BO', // Spanish - Bolivia+ 13322: 'es_CL', // Spanish - Chile+ 9226: 'es_CO', // Spanish - Colombia+ 5130: 'es_CR', // Spanish - Costa Rica+ 7178: 'es_DO', // Spanish - Dominican Republic+ 12298: 'es_EC', // Spanish - Ecuador+ 17418: 'es_SV', // Spanish - El Salvador+ 4106: 'es_GT', // Spanish - Guatemala+ 18442: 'es_HN', // Spanish - Honduras+ 2058: 'es_MX', // Spanish - Mexico+ 19466: 'es_NI', // Spanish - Nicaragua+ 6154: 'es_PA', // Spanish - Panama+ 15370: 'es_PY', // Spanish - Paraguay+ 10250: 'es_PE', // Spanish - Peru+ 20490: 'es_PR', // Spanish - Puerto Rico+ 1034: 'es_ES', // Spanish - Spain (Traditional)+ 14346: 'es_UY', // Spanish - Uruguay+ 8202: 'es_VE', // Spanish - Venezuela+ 1089: 'sw', // Swahili+ 2077: 'sv_FI', // Swedish - Finland+ 1053: 'sv_SE', // Swedish - Sweden+ 1114: 'syc', // Syriac+ 1064: 'tg', // Tajik+ 1097: 'ta', // Tamil+ 1092: 'tt', // Tatar+ 1098: 'te', // Telugu+ 1054: 'th', // Thai+ 1105: 'bo', // Tibetan+ 1073: 'ts', // Tsonga+ 1055: 'tr', // Turkish+ 1090: 'tk', // Turkmen+ 1058: 'uk', // Ukrainian+ 1056: 'ur', // Urdu+ 2115: 'uz_UZ', // Uzbek - Cyrillic+ 1091: 'uz_UZ', // Uzbek - Latin+ 1075: 've', // Venda+ 1066: 'vi', // Vietnamese+ 1106: 'cy', // Welsh+ 1076: 'xh', // Xhosa+ 1085: 'yi', // Yiddish+ 1077: 'zu', // Zulu+});diff --git a/packages/core/src/shared/numfmt/constants.ts b/packages/core/src/shared/numfmt/constants.tsnew file mode 100644index 0000000000..c66bc51b6d--- /dev/null+++ b/packages/core/src/shared/numfmt/constants.ts@@ -0,0 +1,167 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++export const u_YEAR = 2;+export const u_MONTH = 2 ** 2;+export const u_DAY = 2 ** 3;+export const u_HOUR = 2 ** 4;+export const u_MIN = 2 ** 5;+export const u_SEC = 2 ** 6;+export const u_DSEC = 2 ** 7; // decisecond+export const u_CSEC = 2 ** 8; // centisecond+export const u_MSEC = 2 ** 9; // millisecond++// Excel date boundaries+export const MIN_S_DATE = 0;+export const MAX_S_DATE = 2958466;+// Google date boundaries+export const MIN_L_DATE = -694324;+export const MAX_L_DATE = 35830291;++// if more calendars are added, they should conform to MS CALID identifiers+// https://docs.microsoft.com/en-us/windows/win32/intl/calendar-identifiers+export const EPOCH_1904 = -1;+export const EPOCH_1900 = 1;+export const EPOCH_1317 = 6;++export const TOKEN_GENERAL = 'general';+export const TOKEN_HASH = 'hash';+export const TOKEN_ZERO = 'zero';+export const TOKEN_QMARK = 'qmark';+export const TOKEN_SLASH = 'slash';+export const TOKEN_GROUP = 'group';+export const TOKEN_SCALE = 'scale';+export const TOKEN_COMMA = 'comma';+export const TOKEN_BREAK = 'break';+export const TOKEN_TEXT = 'text';+export const TOKEN_PLUS = 'plus';+export const TOKEN_MINUS = 'minus';+export const TOKEN_POINT = 'point';+export const TOKEN_SPACE = 'space';+export const TOKEN_PERCENT = 'percent';+export const TOKEN_DIGIT = 'digit';+export const TOKEN_CALENDAR = 'calendar';+export const TOKEN_ERROR = 'error';+export const TOKEN_DATETIME = 'datetime';+export const TOKEN_DURATION = 'duration';+export const TOKEN_CONDITION = 'condition';+export const TOKEN_DBNUM = 'dbnum';+export const TOKEN_NATNUM = 'natnum';+export const TOKEN_LOCALE = 'locale';+export const TOKEN_COLOR = 'color';+export const TOKEN_MODIFIER = 'modifier';+export const TOKEN_AMPM = 'ampm';+export const TOKEN_ESCAPED = 'escaped';+export const TOKEN_STRING = 'string';+export const TOKEN_SKIP = 'skip';+export const TOKEN_EXP = 'exp';+export const TOKEN_FILL = 'fill';+export const TOKEN_PAREN = 'paren';+export const TOKEN_CHAR = 'char';++export const indexColors = [+ '#000000',+ '#FFFFFF',+ '#FF0000',+ '#00FF00',+ '#0000FF',+ '#FFFF00',+ '#FF00FF',+ '#00FFFF',+ '#800000',+ '#008000',+ '#000080',+ '#808000',+ '#800080',+ '#008080',+ '#C0C0C0',+ '#808080',+ '#9999FF',+ '#993366',+ '#FFFFCC',+ '#CCFFFF',+ '#660066',+ '#FF8080',+ '#0066CC',+ '#CCCCFF',+ '#000080',+ '#FF00FF',+ '#FFFF00',+ '#00FFFF',+ '#800080',+ '#800000',+ '#008080',+ '#0000FF',+ '#00CCFF',+ '#CCFFFF',+ '#CCFFCC',+ '#FFFF99',+ '#99CCFF',+ '#FF99CC',+ '#CC99FF',+ '#FFCC99',+ '#3366FF',+ '#33CCCC',+ '#99CC00',+ '#FFCC00',+ '#FF9900',+ '#FF6600',+ '#666699',+ '#969696',+ '#003366',+ '#339966',+ '#003300',+ '#333300',+ '#993300',+ '#993366',+ '#333399',+ '#333333',+];++export const currencySymbols = [+ '¤',+ '$',+ '£',+ '¥',+ '֏',+ '؋',+ '৳',+ '฿',+ '៛',+ '₡',+ '₦',+ '₩',+ '₪',+ '₫',+ '€',+ '₭',+ '₮',+ '₱',+ '₲',+ '₴',+ '₸',+ '₹',+ '₺',+ '₼',+ '₽',+ '₾',+ '₿',+];++export const reCurrencySymbols = new RegExp(`[${currencySymbols.join('')}]`);diff --git a/packages/core/src/shared/numfmt/dec-to-frac.ts b/packages/core/src/shared/numfmt/dec-to-frac.tsnew file mode 100644index 0000000000..c5584b5f1e--- /dev/null+++ b/packages/core/src/shared/numfmt/dec-to-frac.ts@@ -0,0 +1,71 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++// https://web.archive.org/web/20110813042636/http://homepage.smc.edu/kennedy_john/DEC2FRAC.PDF+const PRECISION = 1e-13;++/**+ * Split a fractional number into a numerator and denominator for display as+ * vulgar fractions.+ *+ * @ignore+ * @param {number} number The value to split+ * @param {number} [numeratorMaxDigits] The maxdigits number+ * @param {number} [denominatorMaxDigits] The maxdigits de+ * @returns {Array<number>} Array of two numbers, numerator and denominator.+ */+export function dec2frac(+ number: number,+ numeratorMaxDigits: number = 2,+ denominatorMaxDigits: number = 2+): [number, number] {+ const sign = number < 0 ? -1 : 1;+ const maxdigits_n = 10 ** (numeratorMaxDigits || 2);+ const maxdigits_d = 10 ** (denominatorMaxDigits || 2);+ let z = Math.abs(number);+ let last_d = 0;+ let last_n = 0;+ let curr_n = 0;+ let curr_d = 1;+ let tmp;+ let r: [number, number];+ number = z;+ if (number % 1 === 0) {+ // handles exact integers including 0+ r = [number * sign, 1];+ } else if (number < 1e-19) {+ r = [sign, 1e+19];+ } else if (number > 1e+19) {+ r = [1e+19 * sign, 1];+ } else {+ do {+ z = 1 / (z - Math.floor(z));+ tmp = curr_d;+ curr_d = curr_d * Math.floor(z) + last_d;+ last_d = tmp;+ last_n = curr_n;+ curr_n = Math.floor(number * curr_d + 0.5); // round+ if (curr_n >= maxdigits_n || curr_d >= maxdigits_d) {+ return [sign * last_n, last_d];+ }+ } while (Math.abs(number - curr_n / curr_d) >= PRECISION && z !== Math.floor(z));+ r = [sign * curr_n, curr_d];+ }+ return r;+}diff --git a/packages/core/src/shared/numfmt/decimal.ts b/packages/core/src/shared/numfmt/decimal.tsnew file mode 100644index 0000000000..7ae5e59e1c--- /dev/null+++ b/packages/core/src/shared/numfmt/decimal.ts@@ -0,0 +1,151 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++export const SPREADSHEET_SIGNIFICANT_DIGITS = 15;++export interface IDecimalValue {+ readonly negative: boolean;+ readonly digits: string;+ readonly exponent: number;+}++export interface IRoundedDecimalParts {+ readonly negative: boolean;+ readonly integer: string;+ readonly fraction: string;+ readonly zero: boolean;+}++export interface IScientificDecimalParts {+ readonly exponent: number;+ readonly rounded: IRoundedDecimalParts;+}++export function decimalFromNumber(value: number): IDecimalValue {+ if (!Number.isFinite(value)) {+ throw new RangeError('decimalFromNumber requires a finite number');+ }++ const negative = value < 0 || Object.is(value, -0);+ if (value === 0) {+ return { negative, digits: '0', exponent: 0 };+ }++ const [mantissa, exponentText] = Math.abs(value)+ .toExponential(SPREADSHEET_SIGNIFICANT_DIGITS - 1)+ .split('e');+ const digits = mantissa.replace('.', '').replace(/0+$/, '') || '0';++ return {+ negative,+ digits,+ exponent: Number(exponentText),+ };+}++export function shiftDecimal(value: IDecimalValue, power: number): IDecimalValue {+ return {+ ...value,+ exponent: value.digits === '0' ? 0 : value.exponent + Math.trunc(power),+ };+}++function incrementDigits(value: string): string {+ const characters = [...value];+ for (let index = characters.length - 1; index >= 0; index--) {+ if (characters[index] !== '9') {+ characters[index] = String(Number(characters[index]) + 1);+ return characters.join('');+ }+ characters[index] = '0';+ }+ return `1${characters.join('')}`;+}++export function roundDecimal(value: IDecimalValue, places = 0): IRoundedDecimalParts {+ const normalizedPlaces = Math.trunc(places);+ const keep = value.exponent + 1 + normalizedPlaces;+ let units: string;++ if (keep < 0) {+ units = '0';+ } else if (keep === 0) {+ units = value.digits[0] >= '5' ? '1' : '0';+ } else {+ units = value.digits.slice(0, keep).padEnd(keep, '0') || '0';+ if (keep < value.digits.length && value.digits[keep] >= '5') {+ units = incrementDigits(units);+ }+ }++ const zero = /^0+$/.test(units);+ if (zero) {+ return { negative: value.negative, integer: '0', fraction: '', zero: true };+ }++ if (normalizedPlaces <= 0) {+ return {+ negative: value.negative,+ integer: units + '0'.repeat(-normalizedPlaces),+ fraction: '',+ zero: false,+ };+ }++ const fixed = units.padStart(normalizedPlaces + 1, '0');+ return {+ negative: value.negative,+ integer: fixed.slice(0, -normalizedPlaces),+ fraction: fixed.slice(-normalizedPlaces).replace(/0+$/, ''),+ zero: false,+ };+}++export function decimalPartsToNumber(value: IRoundedDecimalParts): number {+ const magnitude = Number(value.fraction ? `${value.integer}.${value.fraction}` : value.integer);+ return value.negative && !value.zero ? -magnitude : magnitude;+}++export function decimalPartsToPlainString(value: IRoundedDecimalParts): string {+ const sign = value.negative && !value.zero ? '-' : '';+ return `${sign}${value.integer}${value.fraction ? `.${value.fraction}` : ''}`;+}++export function roundScientificDecimal(+ value: IDecimalValue,+ integerDigits: number,+ hasIntegerPattern: boolean,+ fractionDigits: number+): IScientificDecimalParts {+ if (value.digits === '0') {+ return { exponent: 0, rounded: roundDecimal(value, fractionDigits) };+ }++ let exponent = integerDigits > 1+ ? Math.floor(value.exponent / integerDigits) * integerDigits+ : value.exponent;+ if (!hasIntegerPattern) {+ exponent++;+ }++ let rounded = roundDecimal(shiftDecimal(value, -exponent), fractionDigits);+ if (integerDigits === 1 && rounded.integer.length > 1) {+ exponent++;+ rounded = roundDecimal(shiftDecimal(value, -exponent), fractionDigits);+ }++ return { exponent, rounded };+}diff --git a/packages/core/src/shared/numfmt/format-info.ts b/packages/core/src/shared/numfmt/format-info.tsnew file mode 100644index 0000000000..0c3ee68bf0--- /dev/null+++ b/packages/core/src/shared/numfmt/format-info.ts@@ -0,0 +1,234 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type {+ FormatDateInfo,+ FormatInfo,+ FormatInfoType,+ FormatSection,+ ParsedFormatSection,+} from './types';+import {+ reCurrencySymbols,+ u_DAY,+ u_HOUR,+ u_MIN,+ u_MONTH,+ u_SEC,+ u_YEAR,+} from './constants';++function isParsedSection(part: FormatSection | undefined): part is ParsedFormatSection {+ return !!part && 'scale' in part;+}++function isGenerated(part: FormatSection | undefined): boolean {+ return !!part && 'generated' in part && Boolean(part.generated);+}++export function isPercent(partitions: Array<FormatSection | undefined>): boolean {+ return !!(+ (isParsedSection(partitions[0]) && partitions[0].percent) ||+ (isParsedSection(partitions[1]) && partitions[1].percent) ||+ (isParsedSection(partitions[2]) && partitions[2].percent) ||+ (isParsedSection(partitions[3]) && partitions[3].percent)+ );+}++export function isDate(partitions: Array<FormatSection | undefined>): boolean {+ return !!(+ (isParsedSection(partitions[0]) && partitions[0].date) ||+ (isParsedSection(partitions[1]) && partitions[1].date) ||+ (isParsedSection(partitions[2]) && partitions[2].date) ||+ (isParsedSection(partitions[3]) && partitions[3].date)+ );+}++export function isText(partitions: Array<FormatSection | undefined>): boolean {+ const [part1, part2, part3, part4] = partitions;+ return !!(+ (!part1 || isGenerated(part1)) &&+ (!part2 || isGenerated(part2)) &&+ (!part3 || isGenerated(part3)) &&+ isParsedSection(part4) && part4.text && !isGenerated(part4)+ );+}++const level: Record<FormatInfoType, number> = {+ text: 15,+ datetime: 10.8,+ date: 10.8,+ time: 10.8,+ percent: 10.6,+ currency: 10.4,+ grouped: 10.2,+ scientific: 6,+ number: 4,+ fraction: 2,+ general: 0,+ error: 0,+};++const dateCodes: ReadonlyArray<readonly [prefix: string, code: number]> = [+ ['DMY', 1],+ ['DM', 2],+ ['MY', 3],+ ['MDY', 4],+ ['MD', 5],+ ['hmsa', 6],+ ['hma', 7],+ ['hms', 8],+ ['hm', 9],+];++// eslint-disable-next-line max-lines-per-function, complexity+export function info(+ partitions: Array<FormatSection | undefined>,+ currencyId: string | null = null+): FormatInfo {+ const [partPositive, partNegative] = partitions;+ if (!partPositive) {+ throw new TypeError('Cannot read properties of undefined (reading \'frac_max\')');+ }++ const positive = isParsedSection(partPositive) ? partPositive : undefined;+ const negative = isParsedSection(partNegative) ? partNegative : undefined;+ const isError = 'error' in partPositive;+ const fracMax = positive?.frac_max;+ const output: FormatInfo = {+ type: 'general',+ isDate: isDate(partitions),+ isText: isText(partitions),+ isPercent: isPercent(partitions),+ maxDecimals: positive?.general ? 9 : (fracMax ?? 0),+ scale: positive?.scale ?? 1,+ color: 0,+ parentheses: 0,+ grouped: positive?.grouping ? 1 : 0,+ code: '',+ level: 0,+ };++ // Currency identifier may be passed in, but otherwise report known glyphs.+ const isCurrency = !output.isDate && !output.isText && !isError && partPositive.tokens.some((token) => (+ token.type === 'string' &&+ typeof token.value === 'string' &&+ (currencyId ? token.value === currencyId : reCurrencySymbols.test(token.value))+ ));++ let codeType = 'G';+ let codeNumber: number | '' = fracMax !== undefined && fracMax >= 0 ? Math.min(15, fracMax) : '';+ let codeParentheses = '';+ let codeDash = '';++ if (negative?.color) {+ codeDash = '-';+ output.color = 1;+ }+ if (positive?.parens) {+ codeParentheses = '()';+ output.parentheses = 1;+ }++ if (isCurrency) {+ codeType = 'C';+ output.type = 'currency';+ } else if (isError) {+ output.type = 'error';+ output.maxDecimals = 0;+ } else if (output.isDate) {+ let haveTime = 0;+ let haveDate = 0;+ let order = '';+ // Excel checks order and then ignores trailing tokens.+ partPositive.tokens.forEach((token) => {+ const type = token.type;+ if (/^(b-)?year/.test(type)) {+ order += 'Y';+ haveDate++;+ } else if (type.startsWith('month')) {+ order += 'M';+ haveDate++;+ } else if (/^(week)?day/.test(type)) {+ order += 'D';+ haveDate++;+ } else if (type === 'hour' || type === 'min' || type === 'sec' || type === 'ampm') {+ order += type[0];+ haveTime++;+ }+ });+ output.type = 'date';+ if (haveDate && haveTime) {+ output.type = 'datetime';+ } else if (!haveDate && haveTime) {+ output.type = 'time';+ }+ const code = dateCodes.find(([prefix]) => order.startsWith(prefix));+ codeType = code ? 'D' : 'G';+ codeNumber = code ? code[1] : '';+ } else if (output.isText) {+ codeType = 'G';+ output.type = 'text';+ codeNumber = '';+ output.maxDecimals = 0;+ } else if (positive?.general) {+ codeType = 'G';+ output.type = 'general';+ codeNumber = '';+ } else if (positive?.fractions) {+ codeType = 'G';+ output.type = 'fraction';+ codeNumber = '';+ } else if (positive?.exponential) {+ codeType = 'S';+ output.type = 'scientific';+ } else if (output.isPercent) {+ codeType = 'P';+ output.type = 'percent';+ } else if (positive?.grouping) {+ codeType = ',';+ output.type = 'grouped';+ } else if (positive && (positive.int_max || fracMax)) {+ codeType = 'F';+ output.type = 'number';+ }++ output.code = codeType + codeNumber + codeDash + codeParentheses;+ output.level = level[output.type];++ return Object.freeze(output);+}++export function dateInfo(partitions: Array<FormatSection | undefined>): FormatDateInfo {+ const [partPositive] = partitions;+ if (!partPositive) {+ throw new TypeError('Cannot read properties of undefined (reading \'date\')');+ }+ const positive = isParsedSection(partPositive) ? partPositive : undefined;+ const date = positive?.date ?? 0;+ return {+ year: !!(date & u_YEAR),+ month: !!(date & u_MONTH),+ day: !!(date & u_DAY),+ hours: !!(date & u_HOUR),+ minutes: !!(date & u_MIN),+ seconds: !!(date & u_SEC),+ clockType: positive?.clock === 12 ? 12 : 24,+ };+}diff --git a/packages/core/src/shared/numfmt/format-number.ts b/packages/core/src/shared/numfmt/format-number.tsnew file mode 100644index 0000000000..db22cf7c56--- /dev/null+++ b/packages/core/src/shared/numfmt/format-number.ts@@ -0,0 +1,142 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type {+ FormatColor,+ FormatSection,+ ParsedFormatSection,+ ParsedPattern,+ ResolvedFormatOptions,+} from './types';+import { indexColors, TOKEN_TEXT } from './constants';+import { decimalFromNumber } from './decimal';+import { defaultLocale, getLocale } from './locale';+import { parseFormatSection } from './parse-format-section';+import { runPart } from './run-part';++const defaultText = parseFormatSection([+ { type: TOKEN_TEXT, value: '@', raw: '@' },+]);++function isParsedSection(part: FormatSection | undefined): part is ParsedFormatSection {+ return !!part && 'scale' in part;+}++function getPart(+ value: number | bigint,+ parts: Array<FormatSection | undefined>+): FormatSection | undefined {+ for (let partIndex = 0; partIndex < 3; partIndex++) {+ const part = parts[partIndex];+ if (isParsedSection(part)) {+ let condition: boolean | undefined;+ if (part.condition) {+ const operator = part.condition[0];+ const operand = part.condition[1];+ if (operator === '=') {+ condition = value === operand;+ } else if (operator === '>') {+ condition = value > operand;+ } else if (operator === '<') {+ condition = value < operand;+ } else if (operator === '>=') {+ condition = value >= operand;+ } else if (operator === '<=') {+ condition = value <= operand;+ } else if (operator === '<>') {+ condition = value !== operand;+ }+ } else {+ condition = true;+ }+ if (condition) {+ return part;+ }+ } else if (part) {+ return part;+ }+ }+ return undefined;+}++export function formatColor(+ value: unknown,+ pattern: ParsedPattern,+ options: ResolvedFormatOptions+): FormatColor {+ const parts = pattern.partitions;+ let part = parts[3];+ let color: FormatColor = null;+ if (+ (typeof value === 'number' || typeof value === 'bigint') &&+ // Preserve numfmt 3.2.6, including its BigInt coercion behavior here.+ // eslint-disable-next-line unicorn/prefer-number-properties+ isFinite(value as number)+ ) {+ part = getPart(value, parts);+ }+ if (isParsedSection(part) && part.color) {+ color = part.color;+ }+ if (color && typeof color === 'number' && options.indexColors) {+ color = indexColors[color - 1] || '#000';+ }+ return color;+}++export function formatValue(+ value: unknown,+ pattern: ParsedPattern,+ options: ResolvedFormatOptions+): string {+ const parts = pattern.partitions;+ const locale = getLocale(pattern.locale || options.locale);+ let renderValue = value;+ // not a number?+ const textPart = parts[3] ? parts[3] : defaultText;+ if (typeof renderValue === 'boolean') {+ const resolvedLocale = locale || defaultLocale;+ renderValue = resolvedLocale.bool[renderValue ? 0 : 1];+ }+ if (renderValue == null) {+ return '';+ }+ const isBigInt = typeof renderValue === 'bigint';+ if (typeof renderValue !== 'number' && !isBigInt) {+ return runPart(renderValue, textPart, options, locale);+ }+ // guard against non-finite numbers:+ if (!isBigInt && !Number.isFinite(renderValue)) {+ const resolvedLocale = locale || defaultLocale;+ if (Number.isNaN(renderValue)) {+ return resolvedLocale.nan;+ }+ return ((renderValue as number) < 0 ? resolvedLocale.negative : '') + resolvedLocale.infinity;+ }+ // find and run the pattern part that applies to this number+ const part = getPart(value as number | bigint, parts);+ const decimalValue =+ part && typeof value === 'number' && Number.isFinite(value)+ ? decimalFromNumber(value)+ : null;++ return part+ ? runPart(value, part, options, locale, decimalValue)+ : options.overflow;+}diff --git a/packages/core/src/shared/numfmt/general.ts b/packages/core/src/shared/numfmt/general.tsnew file mode 100644index 0000000000..83d84953c7--- /dev/null+++ b/packages/core/src/shared/numfmt/general.ts@@ -0,0 +1,139 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { IDecimalValue } from './decimal';+import type { LocaleData, ParsedFormatSection } from './types';+import {+ decimalPartsToPlainString,+ roundScientificDecimal,+} from './decimal';+import { numDec } from './num-dec';+import { getExponent, getSignificand } from './number-props';+import { round } from './round';++function fixLocale(value: string, locale: LocaleData): string {+ return value.replace(/\./, locale.decimal);+}++function getAbsoluteDecimal(value: IDecimalValue | null): IDecimalValue | null {+ if (!value) {+ return null;+ }+ return value.negative ? { ...value, negative: false } : value;+}++function getDecimalExponent(value: IDecimalValue | null): number {+ return value?.exponent ?? 0;+}++function usesShortestSignificand(value: IDecimalValue | null): boolean {+ return !value || value.exponent < -308;+}++function getExp(value: IDecimalValue, locale: LocaleData): Array<string | number> {+ const scientific = roundScientificDecimal(value, 1, true, 5);+ const exponent = scientific.exponent;+ const absoluteExponent = Math.abs(exponent);+ const mantissa = decimalPartsToPlainString(scientific.rounded);+ return [+ fixLocale(mantissa, locale),+ locale.exponent,+ exponent < 0 ? locale.negative : locale.positive,+ absoluteExponent < 10 ? '0' : '',+ absoluteExponent,+ ];+}++function getShortestExp(number: number, exponent: number, locale: LocaleData): Array<string | number> {+ const absoluteExponent = Math.abs(exponent);+ const mantissa = number === 1 ? number : Math.round(number * 100000) / 100000;+ return [+ fixLocale(String(mantissa), locale),+ locale.exponent,+ exponent < 0 ? locale.negative : locale.positive,+ absoluteExponent < 10 ? '0' : '',+ absoluteExponent,+ ];+}++export function general(+ output: Array<string | number>,+ part: Partial<ParsedFormatSection>,+ value: number | string,+ locale: LocaleData,+ decimalValue: IDecimalValue | null = null+): Array<string | number> {+ const integer = typeof value === 'number' ? value | 0 : 0;++ if (typeof value === 'string') {+ // special case for: [<-25]General;[>25]General;General;General+ output.push(value);+ } else if (value === integer) {+ output.push(Math.abs(integer));+ } else {+ const absoluteValue = Math.abs(value);+ const absoluteDecimal = getAbsoluteDecimal(decimalValue);+ let exponent = getDecimalExponent(absoluteDecimal);+ let shortestSignificand: number | null = null;+ if (usesShortestSignificand(absoluteDecimal)) {+ // Preserve pinned numfmt behavior for extreme subnormals, whose+ // shortest round-trip decimal differs from their 15-digit value,+ // and for converted BigInts without canonical decimal provenance.+ exponent = getExponent(absoluteValue);+ shortestSignificand = getSignificand(absoluteValue, exponent);+ if (shortestSignificand === 10) {+ shortestSignificand = 1;+ exponent++;+ }+ }++ // The application shall attempt to display the full number+ // up to 11 digits (inc. decimal point).+ const digits = numDec(absoluteValue);+ if (exponent >= -4 && exponent <= -1) {+ const formatted = absoluteValue.toPrecision(10 + exponent).replace(/\.?0+$/, '');+ output.push(fixLocale(formatted, locale));+ } else if (exponent === 10) {+ const formatted = absoluteValue.toFixed(10)+ .slice(0, 12)+ .replace(/\.$/, '');+ output.push(fixLocale(formatted, locale));+ } else if (Math.abs(exponent) <= 9) {+ if (digits.total <= 11) {+ const formatted = round(absoluteValue, 9).toFixed(digits.frac);+ output.push(fixLocale(formatted, locale));+ } else if (exponent === 9) {+ output.push(Math.floor(absoluteValue));+ } else if (exponent >= 0 && exponent < 9) {+ output.push(fixLocale(String(round(absoluteValue, 9 - exponent)), locale));+ } else {+ output.push(...(shortestSignificand === null+ ? getExp(absoluteDecimal!, locale)+ : getShortestExp(shortestSignificand, exponent, locale)));+ }+ } else if (digits.total >= 12) {+ output.push(...(shortestSignificand === null+ ? getExp(absoluteDecimal!, locale)+ : getShortestExp(shortestSignificand, exponent, locale)));+ } else {+ output.push(fixLocale(round(absoluteValue, 9).toFixed(digits.frac), locale));+ }+ }+ return output;+}diff --git a/packages/core/src/shared/numfmt/index.ts b/packages/core/src/shared/numfmt/index.tsnew file mode 100644index 0000000000..9a57b2d2f7--- /dev/null+++ b/packages/core/src/shared/numfmt/index.ts@@ -0,0 +1,28 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++export * as numfmt from './api';+export type { INumfmtLocaleTag } from './utils';+export {+ currencySymbols,+ DEFAULT_NUMBER_FORMAT,+ DEFAULT_TEXT_FORMAT,+ DEFAULT_TEXT_FORMAT_EXCEL,+ getNumfmtParseValueFilter,+ isDefaultFormat,+ isPatternEqualWithoutDecimal,+ isTextFormat,+} from './utils';diff --git a/packages/core/src/shared/numfmt/locale.ts b/packages/core/src/shared/numfmt/locale.tsnew file mode 100644index 0000000000..493a9e5cfa--- /dev/null+++ b/packages/core/src/shared/numfmt/locale.ts@@ -0,0 +1,768 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { LocaleData, LocaleSettings, LocaleToken } from './types';+import { codeToLocale } from './code-to-locale';++// Locale: [language[_territory][.codeset][@modifier]]+const re_locale = /^([a-z\d]+)(?:[_-]([a-z\d]+))?(?:\.([a-z\d]+))?(?:@([a-z\d]+))?$/i;+const locales: Record<string, LocaleData> = {};++/**+ * Split a semicolon delimited string and replace instances of characters+ * @ignore+ * @param {string} str Semicolon delimited string+ * @param {string} [tilde] String to be inserted on every instance of ~+ * @returns {string[]} Array of strings+ */+const _ = (str: string, tilde: string = ''): string[] => str.replace(/~/g, tilde).split(';');++/**+ * Generate mmm and ddd properties as needed for locales. Many of them+ * are straightforward abreviations of mmmm and dddd so we can save some+ * bytes by auto-generating them.+ *+ * Both rule parameters use the same system. If shortform prop is missing:+ *+ * - 0 - use long form array unchanged+ * - 1...9 - shorten to N many characters+ * - 11...19 - shorten to 1...9 characters and add periods+ *+ * @ignore+ * @param {object} o Locale object+ * @param {number} [ml=0] Month list rule+ * @param {number} [dl=0] Day list rule+ * @returns {object} The same input object, but with ddd and mmm filled in.+ */+type ExpandableLocaleSettings = LocaleSettings & Pick<LocaleData, 'mmmm' | 'dddd'>;++const xm = (o: ExpandableLocaleSettings, ml: number = 0, dl: number = 0): LocaleSettings => {+ if (!o.mmm) {+ o.mmm = ml < 1+ ? o.mmmm.concat()+ : o.mmmm.map((d) => {+ const s = d.slice(0, ml % 10);+ return s + (ml < 10 || d === s ? '' : '.');+ });+ }+ if (!o.ddd) {+ o.ddd = dl < 1+ ? o.dddd.concat()+ : o.dddd.map((d) => {+ const s = d.slice(0, dl % 10);+ return s + (dl < 10 || d === s ? '' : '.');+ });+ }+ if (!o.mmm6 && o.mmmm6) {+ o.mmm6 = o.mmmm6;+ }+ return o;+};++/**+ * @typedef {object} LocaleData+ * An object of properties used by a formatter when printing a number in a certain locale.+ * @property {string} group - Symbol used as a grouping separator (`1,000,000` uses `,`)+ * @property {string} decimal - Symbol used to separate integers from fractions (usually `.`)+ * @property {string} positive - Symbol used to indicate positive numbers (usually `+`)+ * @property {string} negative - Symbol used to indicate positive numbers (usually `-`)+ * @property {string} percent - Symbol used to indicate a percentage (usually `%`)+ * @property {string} exponent - Symbol used to indicate an exponent (usually `E`)+ * @property {string} nan - Symbol used to indicate NaN values (`NaN`)+ * @property {string} infinity - Symbol used to indicate infinite values (`∞`)+ * @property {Array<string>} ampm - How AM and PM should be presented+ * @property {Array<string>} mmmm6 - Long month names for the Islamic calendar (`Rajab`)+ * @property {Array<string>} mmm6 - Short month names for the Islamic calendar (`Raj.`)+ * @property {Array<string>} mmmm - Long month names for the Gregorian calendar (`November`)+ * @property {Array<string>} mmm - Short month names for the Gregorian calendar (`Nov`)+ * @property {Array<string>} dddd - Long day names (`Wednesday`)+ * @property {Array<string>} ddd - Shortened day names (`Wed`)+ * @property {Array<string>} bool - How TRUE and FALSE should be presented+ * @property {boolean} preferMDY - Is the prefered date format month first (12/31/2025) or day first (31/12/2025)+ */++/**+ * @ignore+ * @type {LocaleData}+ */+const baseLocaleData: LocaleData = {+ group: '\u00A0',+ decimal: '.',+ positive: '+',+ negative: '-',+ percent: '%',+ exponent: 'E',+ nan: 'NaN',+ infinity: '∞',+ ampm: _('AM;PM'),+ mmmm6: _('Muharram;Safar;Rabiʻ I;Rabiʻ II;Jumada I;Jumada II;Rajab;Shaʻban;Ramadan;Shawwal;Dhuʻl-Qiʻdah;Dhuʻl-Hijjah'),+ mmm6: _('Muh.;Saf.;Rab. I;Rab. II;Jum. I;Jum. II;Raj.;Sha.;Ram.;Shaw.;Dhuʻl-Q.;Dhuʻl-H.'),+ mmmm: _('January;February;March;April;May;June;July;August;September;October;November;December'),+ mmm: _('Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec'),+ dddd: _('Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday'),+ ddd: _('Sun;Mon;Tue;Wed;Thu;Fri;Sat'),+ bool: _('TRUE;FALSE'),+ preferMDY: false,+};++/**+ * @typedef {object} LocaleToken - An object of properties for a locale tag.+ * @property {string} lang - The basic tag such as `zh_CN` or `fi`+ * @property {string} language - The language section (`zh` for `zh_CN`)+ * @property {string} territory - The territory section (`CN` for `zh_CN`)+ */++/**+ * Parse a regular IETF BCP 47 locale tag and emit an object of its parts.+ * Irregular tags and subtags are not supported.+ *+ * @param {string} locale - A BCP 47 string tag of the locale.+ * @returns {LocaleToken} - An object describing the locale.+ */+export function parseLocale(locale: string): LocaleToken {+ const lm = re_locale.exec(locale);+ if (!lm) {+ throw new SyntaxError(`Malformed locale: ${locale}`);+ }+ return {+ lang: lm[1] + (lm[2] ? `_${lm[2]}` : ''),+ language: lm[1],+ territory: lm[2] || '',+ };+}++// MS code format is: aabbcccc [$-aabbcccc]+// aa = numerical style (optional, 00 if absent)+// bb = calendar format (optional, 00 if absent)+// cc = language code+export function resolveLocale(locale: string | number): string | null {+ if (typeof locale === 'number') {+ return codeToLocale[locale & 0xFFFF] || null;+ }+ const wincode = Number.parseInt(locale, 16);+ if (Number.isFinite(wincode) && codeToLocale[wincode & 0xFFFF]) {+ return codeToLocale[wincode & 0xFFFF] || null;+ }+ if (re_locale.test(locale)) {+ return locale;+ }+ return null;+}++/**+ * Used by the formatter to pull a locate from its registered locales. If+ * subtag isn't available but the base language is, the base language is used.+ * So if `en-CA` is not found, the formatter tries to find `en` else it+ * returns a `null`.+ *+ * @param {string} locale - A BCP 47 string tag of the locale, or an Excel locale code.+ * @returns {LocaleData | null} - An object of format date properties.+ */+export function getLocale(locale: string | number): LocaleData | null {+ const tag = resolveLocale(locale);+ let obj: LocaleData | null = null;+ if (tag) {+ const c = parseLocale(tag);+ obj = locales[c.lang] || locales[c.language] || null;+ }+ return obj;+}++// creates a new locale options object+export function createLocale(settings: LocaleSettings): LocaleData {+ return Object.assign({}, baseLocaleData, settings);+}++/**+ * Register locale data for a language so for use when formatting.+ *+ * Any partial set of properties may be returned to have the defaults used where properties are missing.+ *+ * @see {LocaleData}+ * @param {object} settings - A collection of settings for a locale.+ * @param {string} [settings.group]+ * Symbol used as a grouping separator (`1,000,000` uses `,`)+ * @param {string} [settings.decimal]+ * Symbol used to separate integers from fractions (usually `.`)+ * @param {string} [settings.positive]+ * Symbol used to indicate positive numbers (usually `+`)+ * @param {string} [settings.negative]+ * Symbol used to indicate positive numbers (usually `-`)+ * @param {string} [settings.percent]+ * Symbol used to indicate a percentage (usually `%`)+ * @param {string} [settings.exponent]+ * Symbol used to indicate an exponent (usually `E`)+ * @param {string} [settings.nan]+ * Symbol used to indicate NaN values (`NaN`)+ * @param {string} [settings.infinity]+ * Symbol used to indicate infinite values (`∞`)+ * @param {Array<string>} [settings.ampm]+ * How AM and PM should be presented.+ * @param {Array<string>} [settings.mmmm6]+ * Long month names for the Islamic calendar (e.g. `Rajab`)+ * @param {Array<string>} [settings.mmm6]+ * Short month names for the Islamic calendar (e.g. `Raj.`)+ * @param {Array<string>} [settings.mmmm]+ * Long month names for the Gregorian calendar (e.g. `November`)+ * @param {Array<string>} [settings.mmm]+ * Short month names for the Gregorian calendar (e.g. `Nov`)+ * @param {Array<string>} [settings.dddd]+ * Long day names (e.g. `Wednesday`)+ * @param {Array<string>} [settings.ddd]+ * Shortened day names (e.g. `Wed`)+ * @param {Array<string>} [settings.bool]+ * How TRUE and FALSE should be presented.+ * @param {boolean} [settings.preferMDY]+ * Is the prefered date format month first (12/31/2025) or day first (31/12/2025)+ * @param {string | LocaleToken} locale - A string BCP 47 tag or parsed locale token.+ * @returns {LocaleData} - A full collection of settings for a locale+ */+export function addLocale(settings: LocaleSettings, locale: string | LocaleToken): LocaleData {+ // parse language tag+ const c = typeof locale === 'object' ? locale : parseLocale(locale);+ // add the language+ locales[c.lang] = createLocale(settings);+ // if "xx_YY" is added also create "xx" if it is missing+ if (c.language !== c.lang && !locales[c.language]) {+ locales[c.language] = createLocale(settings);+ }+ return locales[c.lang];+}++export function listLocales(): string[] {+ return Object.keys(locales);+}++export const defaultLocale = createLocale({ group: ',', preferMDY: true });+defaultLocale.isDefault = true;++addLocale({+ group: ',',+ ampm: _('上午;下午'),+ mmmm: _('一月;二月;三月;四月;五月;六月;七月;八月;九月;十月;十一月;十二月'),+ mmm: _('1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月'),+ dddd: _('~日;~一;~二;~三;~四;~五;~六', '星期'),+ ddd: _('周日;周一;周二;周三;周四;周五;周六'),+}, 'zh_CN');+const _zh = {+ group: ',',+ ampm: _('上午;下午'),+ mmmm: _('1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月'),+ mmm: _('1月;2月;3月;4月;5月;6月;7月;8月;9月;10月;11月;12月'),+ dddd: _('~日;~一;~二;~三;~四;~五;~六', '星期'),+ ddd: _('周日;周一;周二;周三;周四;周五;周六'),+};+addLocale({+ ..._zh,+ nan: '非數值',+ dddd: _('~日;~一;~二;~三;~四;~五;~六', '星期'),+}, 'zh_TW');+addLocale({+ ..._zh,+ dddd: _('~日;~一;~二;~三;~四;~五;~六', '星期'),+}, 'zh_HK');++addLocale({+ ..._zh,+ ampm: _('午前;午後'),+ dddd: _('日~;月~;火~;水~;木~;金~;土~', '曜日'),+ ddd: _('日;月;火;水;木;金;土'),+}, 'ja');++addLocale({+ group: ',',+ ampm: _('오전;오후'),+ mmmm: _('1월;2월;3월;4월;5월;6월;7월;8월;9월;10월;11월;12월'),+ mmm: _('1월;2월;3월;4월;5월;6월;7월;8월;9월;10월;11월;12월'),+ dddd: _('일요일;월요일;화요일;수요일;목요일;금요일;토요일'),+ ddd: _('일;월;화;수;목;금;토'),+}, 'ko');++addLocale({+ group: ',',+ ampm: _('ก่อนเที่ยง;หลังเที่ยง'),+ mmmm: _('มกร~;กุมภาพันธ์;มีน~;เมษายน;พฤษภ~;มิถุนายน;กรกฎ~;สิงห~;กันยายน;ตุล~;พฤศจิกายน;ธันว~', 'าคม'),+ mmm: _('ม.ค.;ก.พ.;มี.ค.;เม.ย.;พ.ค.;มิ.ย.;ก.ค.;ส.ค.;ก.ย.;ต.ค.;พ.ย.;ธ.ค.'),+ dddd: _('วันอาทิตย์;วันจันทร์;วันอังคาร;วันพุธ;วันพฤหัสบดี;วันศุกร์;วันเสาร์'),+ ddd: _('อา.;จ.;อ.;พ.;พฤ.;ศ.;ส.'),+}, 'th');++addLocale(xm({+ decimal: ',',+ ampm: _('dop.;odp.'),+ mmmm: _('ledna;února;března;dubna;května;června;července;srpna;září;října;listopadu;prosince'),+ mmm: _('I;II;III;IV;V;VI;VII;VIII;IX;X;XI;XII'),+ dddd: _('neděle;pondělí;úterý;středa;čtvrtek;pátek;sobota'),+ bool: _('PRAVDA;NEPRAVDA'),+}, -1, 2), 'cs');++addLocale(xm({+ group: '.',+ decimal: ',',+ mmmm: _('januar;februar;marts;april;maj;juni;juli;august;september;oktober;november;december'),+ dddd: _('søn~;man~;tirs~;ons~;tors~;fre~;lør~', 'dag'),+ bool: _('SAND;FALSK'),+}, 13, 13), 'da');++addLocale(xm({+ group: '.',+ decimal: ',',+ ampm: _('a.m.;p.m.'),+ mmmm: _('januari;februari;maart;april;mei;juni;juli;augustus;september;oktober;november;december'),+ mmm: _('jan.;feb.;mrt.;apr.;mei;jun.;jul.;aug.;sep.;okt.;nov.;dec.'),+ dddd: _('zondag;maandag;dinsdag;woensdag;donderdag;vrijdag;zaterdag'),+ bool: _('WAAR;ONWAAR'),+}, -1, 2), 'nl');++addLocale({ group: ',', preferMDY: true }, 'en');+addLocale({ group: ',', preferMDY: true }, 'en_US');+addLocale({ group: ',' }, 'en_AU');+addLocale({ group: ',' }, 'en_CA');+addLocale({ group: ',' }, 'en_GB');+addLocale({ group: ',', mmm: _('Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sept;Oct;Nov;Dec') }, 'en_IE');++addLocale(xm({+ decimal: ',',+ nan: 'epäluku',+ ampm: _('ap.;ip.'),+ mmmm: _('tammi~;helmi~;maalis~;huhti~;touko~;kesä~;heinä~;elo~;syys~;loka~;marras~;joulu~', 'kuuta'),+ mmm: _('tammik.;helmik.;maalisk.;huhtik.;toukok.;kesäk.;heinäk.;elok.;syysk.;lokak.;marrask.;jouluk.'),+ dddd: _('sunnun~;maanan~;tiis~;keskiviikkona;tors~;perjan~;lauan~', 'taina'),+ bool: _('TOSI;EPÄTOSI'),+}, -1, 2), 'fi');++const _fr = xm({+ group: '\u202F',+ decimal: ',',+ mmmm: _('janvier;février;mars;avril;mai;juin;juillet;août;septembre;octobre;novembre;décembre'),+ mmm: _('janv.;févr.;mars;avr.;mai;juin;juil.;août;sept.;oct.;nov.;déc.'),+ dddd: _('~manche;lun~;mar~;mercre~;jeu~;vendre~;same~', 'di'),+ bool: _('VRAI;FAUX'),+}, -1, 13);+addLocale({ ..._fr }, 'fr');+addLocale({ ..._fr, mmm: _('janv.;févr.;mars;avr.;mai;juin;juill.;août;sept.;oct.;nov.;déc.') }, 'fr_CA');+addLocale({ group: "'", decimal: '.', ..._fr }, 'fr_CH');++const _de = xm({+ mmmm: _('Januar;Februar;März;April;Mai;Juni;Juli;August;September;Oktober;November;Dezember'),+ mmm: _('Jan.;Feb.;März;Apr.;Mai;Juni;Juli;Aug.;Sept.;Okt.;Nov.;Dez.'),+ dddd: _('Sonn~;Mon~;Diens~;Mittwoch;Donners~;Frei~;Sams~', 'tag'),+ bool: _('WAHR;FALSCH'),+}, -1, 12);+addLocale({ group: '.', decimal: ',', ..._de }, 'de');+addLocale({ group: "'", decimal: '.', ..._de }, 'de_CH');++addLocale(xm({+ group: '.',+ decimal: ',',+ ampm: _('π.μ.;μ.μ.'),+ mmmm: _('Ιανουαρ~;Φεβρουαρ~;Μαρτ~;Απριλ~;Μαΐου;Ιουν~;Ιουλ~;Αυγούστου;Σεπτεμβρ~;Οκτωβρ~;Νοεμβρ~;Δεκεμβρ~', 'ίου'),+ mmm: _('Ιαν;Φεβ;Μαρ;Απρ;Μαΐ;Ιουν;Ιουλ;Αυγ;Σεπ;Οκτ;Νοε;Δεκ'),+ dddd: _('Κυριακή;Δευτέρα;Τρίτη;Τετάρτη;Πέμπτη;Παρασκευή;Σάββατο'),+}, -1, 3), 'el');++addLocale({+ decimal: ',',+ ampm: _('de.;du.'),+ mmmm: _('január;február;március;április;május;június;július;augusztus;szeptember;október;november;december'),+ mmm: _('jan.;febr.;márc.;ápr.;máj.;jún.;júl.;aug.;szept.;okt.;nov.;dec.'),+ dddd: _('vasárnap;hétfő;kedd;szerda;csütörtök;péntek;szombat'),+ ddd: _('V;H;K;Sze;Cs;P;Szo'),+ bool: _('IGAZ;HAMIS'),+}, 'hu');++addLocale(xm({+ group: '.',+ decimal: ',',+ ampm: _('f.h.;e.h.'),+ mmmm: _('janúar;febrúar;mars;apríl;maí;júní;júlí;ágúst;september;október;nóvember;desember'),+ dddd: _('sunnu~;mánu~;þriðju~;miðviku~;fimmtu~;föstu~;laugar~', 'dagur'),+}, 13, 13), 'is');++addLocale(xm({+ group: '.',+ decimal: ',',+ mmmm: _('Januari;Februari;Maret;April;Mei;Juni;Juli;Agustus;September;Oktober;November;Desember'),+ dddd: _('Minggu;Senin;Selasa;Rabu;Kamis;Jumat;Sabtu'),+}, 3, 3), 'id');++const _it = xm({+ mmmm: _('gennaio;febbraio;marzo;aprile;maggio;giugno;luglio;agosto;settembre;ottobre;novembre;dicembre'),+ dddd: _('domenica;lunedì;martedì;mercoledì;giovedì;venerdì;sabato'),+ bool: _('VERO;FALSO'),+}, 3, 3);+addLocale({ group: '.', decimal: ',', ..._it }, 'it');+addLocale({ group: "'", decimal: '.', ..._it }, 'it_CH');++const _no = {+ decimal: ',',+ ampm: _('a.m.;p.m.'),+ mmmm: _('januar;februar;mars;april;mai;juni;juli;august;september;oktober;november;desember'),+ mmm: _('jan.;feb.;mar.;apr.;mai;jun.;jul.;aug.;sep.;okt.;nov.;des.'),+ dddd: _('søn~;man~;tirs~;ons~;tors~;fre~;lør~', 'dag'),+ bool: _('SANN;USANN'),+};+addLocale(xm({ ..._no }, -1, 13), 'nb');+addLocale(xm({ ..._no }, -1, 13), 'no');++addLocale(xm({+ decimal: ',',+ mmmm: _('stycznia;lutego;marca;kwietnia;maja;czerwca;lipca;sierpnia;września;października;listopada;grudnia'),+ dddd: _('niedziela;poniedziałek;wtorek;środa;czwartek;piątek;sobota'),+ ddd: _('niedz.;pon.;wt.;śr.;czw.;pt.;sob.'),+ bool: _('PRAWDA;FAŁSZ'),+}, 3, -1), 'pl');++const _pt = {+ group: '.',+ decimal: ',',+ mmmm: _('janeiro;fevereiro;março;abril;maio;junho;julho;agosto;setembro;outubro;novembro;dezembro'),+ dddd: _('domingo;segunda-feira;terça-feira;quarta-feira;quinta-feira;sexta-feira;sábado'),+ bool: _('VERDADEIRO;FALSO'),+};+addLocale(xm(_pt, 13, 13), 'pt');+addLocale(xm(_pt, 13, 13), 'pt_BR');++addLocale({+ decimal: ',',+ nan: 'не\u00A0число',+ mmmm: _('января;февраля;марта;апреля;мая;июня;июля;августа;сентября;октября;ноября;декабря'),+ mmm: _('янв.;февр.;мар.;апр.;мая;июн.;июл.;авг.;сент.;окт.;нояб.;дек.'),+ dddd: _('воскресенье;понедельник;вторник;среда;четверг;пятница;суббота'),+ ddd: _('вс;пн;вт;ср;чт;пт;сб'),+ mmmm6: _('рамадан;шавваль;зуль-каада;зуль-хиджжа;мухаррам;раби-уль-авваль;раби-уль-ахир;джумад-уль-авваль;джумад-уль-ахир;раджаб;шаабан;рамадан'),+ mmm6: _('рам.;шав.;зуль-к.;зуль-х.;мух.;раб. I;раб. II;джум. I;джум. II;радж.;шааб.;рам.'),+ bool: _('ИСТИНА;ЛОЖЬ'),+}, 'ru');++addLocale(xm({+ decimal: ',',+ mmmm: _('januára;februára;marca;apríla;mája;júna;júla;augusta;septembra;októbra;novembra;decembra'),+ dddd: _('nedeľa;pondelok;utorok;streda;štvrtok;piatok;sobota'),+}, 3, 2), 'sk');++const _es = {+ group: '.',+ decimal: ',',+ ampm: _('a.\u00A0m.;p.\u00A0m.'),+ mmmm: _('enero;febrero;marzo;abril;mayo;junio;julio;agosto;septiem~;octu~;noviem~;diciem~', 'bre'),+ mmm: _('ene;feb;mar;abr;may;jun;jul;ago;sept;oct;nov;dic'),+ dddd: _('domingo;lunes;martes;miércoles;jueves;viernes;sábado'),+ ddd: _('dom;lun;mar;mié;jue;vie;sáb'),+ bool: _('VERDADERO;FALSO'),+};+const _esM3 = _('ene;feb;mar;abr;may;jun;jul;ago;sep;oct;nov;dic');+const _esM13 = _('ene.;feb.;mar.;abr.;may.;jun.;jul.;ago.;sept.;oct.;nov.;dic.');+addLocale({ ..._es }, 'es');+addLocale({ ..._es }, 'es_AR');+addLocale({ ..._es }, 'es_BO');+addLocale({ ..._es }, 'es_CL');+addLocale({ ..._es }, 'es_CO');+addLocale({ ..._es }, 'es_EC');+addLocale({ ..._es, mmm: _esM3, ampm: _('a.m.;p.m.') }, 'es_MX');+addLocale({ ..._es, mmm: _esM13 }, 'es_PY');+addLocale({ ..._es, mmm: _esM13 }, 'es_UY');+addLocale({ ..._es, mmm: _esM13, mmmm: _('enero;febrero;marzo;abril;mayo;junio;julio;agosto;setiembre;octubre;noviembre;diciembre') }, 'es_VE');++addLocale({+ decimal: ',',+ ampm: _('fm;em'),+ mmmm: _('januari;februari;mars;april;maj;juni;juli;augusti;september;oktober;november;december'),+ mmm: _('jan.;feb.;mars;apr.;maj;juni;juli;aug.;sep.;okt.;nov.;dec.'),+ dddd: _('sön~;mån~;tis~;ons~;tors~;fre~;lör~', 'dag'),+ ddd: _('sön;mån;tis;ons;tors;fre;lör'),+}, 'sv');++addLocale(xm({+ group: '.',+ decimal: ',',+ ampm: _('ÖÖ;ÖS'),+ mmmm: _('Ocak;Şubat;Mart;Nisan;Mayıs;Haziran;Temmuz;Ağustos;Eylül;Ekim;Kasım;Aralık'),+ mmm: _('Oca;Şub;Mar;Nis;May;Haz;Tem;Ağu;Eyl;Eki;Kas;Ara'),+ dddd: _('Pazar;Pazartesi;Salı;Çarşamba;Perşembe;Cuma;Cumartesi'),+ ddd: _('Paz;Pzt;Sal;Çar;Per;Cum;Cmt'),+ bool: _('DOĞRU;YANLIŞ'),+}, 3, -1), 'tr');++addLocale({+ group: ',',+ ampm: _('yb;yh'),+ mmmm: _('Ionawr;Chwefror;Mawrth;Ebrill;Mai;Mehefin;Gorffennaf;Awst;Medi;Hydref;Tachwedd;Rhagfyr'),+ mmm: _('Ion;Chwef;Maw;Ebr;Mai;Meh;Gorff;Awst;Medi;Hyd;Tach;Rhag'),+ dddd: _('Dydd Sul;Dydd Llun;Dydd Mawrth;Dydd Mercher;Dydd Iau;Dydd Gwener;Dydd Sadwrn'),+ ddd: _('Sul;Llun;Maw;Mer;Iau;Gwen;Sad'),+}, 'cy');++addLocale({+ group: '.',+ decimal: ',',+ mmmm: _('yanvar;fevral;mart;aprel;may;iyun;iyul;avqust;sentyabr;oktyabr;noyabr;dekabr'),+ mmm: _('yan;fev;mar;apr;may;iyn;iyl;avq;sen;okt;noy;dek'),+ dddd: _('bazar;bazar ertəsi;çərşənbə axşamı;çərşənbə;cümə axşamı;cümə;şənbə'),+ ddd: _('B.;B.e.;Ç.a.;Ç.;C.a.;C.;Ş.'),+}, 'az');++addLocale(xm({+ decimal: ',',+ mmmm: _('студзеня;лютага;сакавіка;красавіка;мая;чэрвеня;ліпеня;жніўня;верасня;кастрычніка;лістапада;снежня'),+ dddd: _('нядзеля;панядзелак;аўторак;серада;чацвер;пятніца;субота'),+ ddd: _('нд;пн;аў;ср;чц;пт;сб'),+}, 3, -1), 'be');++addLocale({+ decimal: ',',+ ampm: _('пр.об.;сл.об.'),+ mmmm: _('януари;февруари;март;април;май;юни;юли;август;септември;октомври;ноември;декември'),+ mmm: _('яну;фев;март;апр;май;юни;юли;авг;сеп;окт;ное;дек'),+ dddd: _('неделя;понеделник;вторник;сряда;четвъртък;петък;събота'),+ ddd: _('нд;пн;вт;ср;чт;пт;сб'),+ bool: _('ИСТИНА;ЛОЖЬ'),+}, 'bg');++addLocale({+ group: '.',+ decimal: ',',+ mmmm: _('de gener;de febrer;de març;d’abril;de maig;de juny;de juliol;d’agost;de setembre;d’octubre;de novembre;de desembre'),+ mmm: _('de gen.;de febr.;de març;d’abr.;de maig;de juny;de jul.;d’ag.;de set.;d’oct.;de nov.;de des.'),+ dddd: _('diumenge;dilluns;dimarts;dimecres;dijous;divendres;dissabte'),+ ddd: _('dg.;dl.;dt.;dc.;dj.;dv.;ds.'),+ ampm: _('a.\u00A0m.;p.\u00A0m.'),+}, 'ca');++addLocale(xm({+ group: ',',+ decimal: '.',+ mmmm: _('Enero;Pebrero;Marso;Abril;Mayo;Hunyo;Hulyo;Agosto;Setyembre;Oktubre;Nobyembre;Disyembre'),+ dddd: _('Linggo;Lunes;Martes;Miyerkules;Huwebes;Biyernes;Sabado'),+}, 3, 3), 'fil');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('જાન્યુઆરી;ફેબ્રુઆરી;માર્ચ;એપ્રિલ;મે;જૂન;જુલાઈ;ઑગસ્ટ;સપ્ટેમ્બર;ઑક્ટોબર;નવેમ્બર;ડિસેમ્બર'),+ mmm: _('જાન્યુ;ફેબ્રુ;માર્ચ;એપ્રિલ;મે;જૂન;જુલાઈ;ઑગસ્ટ;સપ્ટે;ઑક્ટો;નવે;ડિસે'),+ dddd: _('રવિ~;સોમ~;મંગળ~;બુધ~;ગુરુ~;શુક્ર~;શનિ~', 'વાર'),+ ddd: _('રવિ;સોમ;મંગળ;બુધ;ગુરુ;શુક્ર;શનિ'),+}, 'gu');++addLocale({+ group: ',',+ decimal: '.',+ ampm: _('לפנה״צ;אחה״צ'),+ dddd: _('~ראשון;~שני;~שלישי;~רביעי;~חמישי;~שישי;~שבת', 'יום '),+ ddd: _('~א׳;~ב׳;~ג׳;~ד׳;~ה׳;~ו׳;שבת', 'יום '),+ mmmm: _('ינואר;פברואר;מרץ;אפריל;מאי;יוני;יולי;אוגוסט;ספטמבר;אוקטובר;נובמבר;דצמבר'),+ mmm: _('ינו׳;פבר׳;מרץ;אפר׳;מאי;יוני;יולי;אוג׳;ספט׳;אוק׳;נוב׳;דצמ׳'),+ mmmm6: _('רמדאן;שוואל;ד׳ו אל־קעדה;ד׳ו אל־חיג׳ה;מוחרם;רביע אל־אוול;רביע א־ת׳אני;ג׳ומאדא אל־אולא;ג׳ומאדא א־ת׳אניה;רג׳ב;שעבאן;רמדאן'),+ mmm6: _('רמדאן;שוואל;ד׳ו אל־קעדה;ד׳ו אל־חיג׳ה;מוחרם;רביע א׳;רביע ב׳;ג׳ומאדא א׳;ג׳ומאדא ב׳;רג׳ב;שעבאן;רמדאן'),+}, 'he');++addLocale(xm({+ group: '.',+ decimal: ',',+ mmmm: _('siječnja;veljače;ožujka;travnja;svibnja;lipnja;srpnja;kolovoza;rujna;listopada;studenoga;prosinca'),+ mmm: _('sij;velj;ožu;tra;svi;lip;srp;kol;ruj;lis;stu;pro'),+ dddd: _('nedjelja;ponedjeljak;utorak;srijeda;četvrtak;petak;subota'),+}, -1, 3), 'hr');++addLocale({+ decimal: ',',+ mmmm: _('հունվարի;փետրվարի;մարտի;ապրիլի;մայիսի;հունիսի;հուլիսի;օգոստոսի;սեպտեմբերի;հոկտեմբերի;նոյեմբերի;դեկտեմբերի'),+ mmm: _('հնվ;փտվ;մրտ;ապր;մյս;հնս;հլս;օգս;սեպ;հոկ;նոյ;դեկ'),+ dddd: _('կիրակի;երկուշաբթի;երեքշաբթի;չորեքշաբթի;հինգշաբթի;ուրբաթ;շաբաթ'),+ ddd: _('կիր;երկ;երք;չրք;հնգ;ուր;շբթ'),+}, 'hy');++addLocale(xm({+ decimal: ',',+ mmmm: _('იანვარი;თებერვალი;მარტი;აპრილი;მაისი;ივნისი;ივლისი;აგვისტო;სექტემბერი;ოქტომბერი;ნოემბერი;დეკემბერი'),+ dddd: _('კვირა;ორშაბათი;სამშაბათი;ოთხშაბათი;ხუთშაბათი;პარასკევი;შაბათი'),+}, 3, 3), 'ka');++addLocale(xm({+ decimal: ',',+ mmmm: _('қаңтар;ақпан;наурыз;сәуір;мамыр;маусым;шілде;тамыз;қыркүйек;қазан;қараша;желтоқсан'),+ dddd: _('жексенбі;дүйсенбі;сейсенбі;сәрсенбі;бейсенбі;жұма;сенбі'),+ ddd: _('жс;дс;сс;ср;бс;жм;сб'),+}, 13, -1), 'kk');++addLocale({+ group: ',',+ mmmm: _('ಜನವರಿ;ಫೆಬ್ರವರಿ;ಮಾರ್ಚ್;ಏಪ್ರಿಲ್;ಮೇ;ಜೂನ್;ಜುಲೈ;ಆಗಸ್ಟ್;ಸೆಪ್ಟೆಂಬರ್;ಅಕ್ಟೋಬರ್;ನವೆಂಬರ್;ಡಿಸೆಂಬರ್'),+ mmm: _('ಜನವರಿ;ಫೆಬ್ರವರಿ;ಮಾರ್ಚ್;ಏಪ್ರಿ;ಮೇ;ಜೂನ್;ಜುಲೈ;ಆಗಸ್ಟ್;ಸೆಪ್ಟೆಂ;ಅಕ್ಟೋ;ನವೆಂ;ಡಿಸೆಂ'),+ dddd: _('ಭಾನು~;ಸೋಮ~;ಮಂಗಳ~;ಬುಧ~;ಗುರು~;ಶುಕ್ರ~;ಶನಿ~', 'ವಾರ'),+ ddd: _('ಭಾನು;ಸೋಮ;ಮಂಗಳ;ಬುಧ;ಗುರು;ಶುಕ್ರ;ಶನಿ'),+ ampm: _('ಪೂರ್ವಾಹ್ನ;ಅಪರಾಹ್ನ'),+}, 'kn');++addLocale({+ decimal: ',',+ mmmm: _('sausio;vasario;kovo;balandžio;gegužės;birželio;liepos;rugpjūčio;rugsėjo;spalio;lapkričio;gruodžio'),+ mmm: _('saus.;vas.;kov.;bal.;geg.;birž.;liep.;rugp.;rugs.;spal.;lapkr.;gruod.'),+ dddd: _('sekmadienis;pirmadienis;antradienis;trečiadienis;ketvirtadienis;penktadienis;šeštadienis'),+ ddd: _('sk;pr;an;tr;kt;pn;št'),+ ampm: _('priešpiet;popiet'),+}, 'lt');++addLocale({+ decimal: ',',+ mmmm: _('janvāris;februāris;marts;aprīlis;maijs;jūnijs;jūlijs;augusts;septembris;oktobris;novembris;decembris'),+ mmm: _('janv.;febr.;marts;apr.;maijs;jūn.;jūl.;aug.;sept.;okt.;nov.;dec.'),+ dddd: _('svētdiena;pirmdiena;otrdiena;trešdiena;ceturtdiena;piektdiena;sestdiena'),+ ddd: _('svētd.;pirmd.;otrd.;trešd.;ceturtd.;piektd.;sestd.'),+ ampm: _('priekšpusdienā;pēcpusdienā'),+}, 'lv');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('ജനുവരി;ഫെബ്രുവരി;മാർച്ച്;ഏപ്രിൽ;മേയ്;ജൂൺ;ജൂലൈ;ഓഗസ്റ്റ്;സെപ്റ്റംബർ;ഒക്ടോബർ;നവംബർ;ഡിസംബർ'),+ mmm: _('ജനു;ഫെബ്രു;മാർ;ഏപ്രി;മേയ്;ജൂൺ;ജൂലൈ;ഓഗ;സെപ്റ്റം;ഒക്ടോ;നവം;ഡിസം'),+ dddd: _('ഞായറാഴ്ച;തിങ്കളാഴ്ച;ചൊവ്വാഴ്ച;ബുധനാഴ്ച;വ്യാഴാഴ്ച;വെള്ളിയാഴ്ച;ശനിയാഴ്ച'),+ ddd: _('ഞായർ;തിങ്കൾ;ചൊവ്വ;ബുധൻ;വ്യാഴം;വെള്ളി;ശനി'),+}, 'ml');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('нэгдүгээ~;хоёрдугаа~;гуравдугаа~;дөрөвдүгээ~;тавдугаа~;зургаадугаа~;долоодугаа~;наймдугаа~;есдүгээ~;аравдугаа~;арван нэгдүгээ~;арван хоёрдугаа~', 'р сар'),+ mmm: _('1~;2~;3~;4~;5~;6~;7~;8~;9~;10~;11~;12~', '-р сар'),+ dddd: _('ням;даваа;мягмар;лхагва;пүрэв;баасан;бямба'),+ ddd: _('Ня;Да;Мя;Лх;Пү;Ба;Бя'),+ ampm: _('ү.ө.;ү.х.'),+}, 'mn');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('जानेवारी;फेब्रुवारी;मार्च;एप्रिल;मे;जून;जुलै;ऑगस्ट;सप्टेंबर;ऑक्टोबर;नोव्हेंबर;डिसेंबर'),+ mmm: _('जाने;फेब्रु;मार्च;एप्रि;मे;जून;जुलै;ऑग;सप्टें;ऑक्टो;नोव्हें;डिसें'),+ dddd: _('रविवार;सोमवार;मंगळवार;बुधवार;गुरुवार;शुक्रवार;शनिवार'),+ ddd: _('रवि;सोम;मंगळ;बुध;गुरु;शुक्र;शनि'),+}, 'mr');++addLocale(xm({+ group: ',',+ decimal: '.',+ mmmm: _('ဇန်နဝါရီ;ဖေဖော်ဝါရီ;မတ်;ဧပြီ;မေ;ဇွန်;ဇူလိုင်;ဩဂုတ်;စက်တင်ဘာ;အောက်တိုဘာ;နိုဝင်ဘာ;ဒီဇင်ဘာ'),+ mmm: _('ဇန်;ဖေ;မတ်;ဧ;မေ;ဇွန်;ဇူ;ဩ;စက်;အောက်;နို;ဒီ'),+ dddd: _('တနင်္ဂနွေ;တနင်္လာ;အင်္ဂါ;ဗုဒ္ဓဟူး;ကြာသပတေး;သောကြာ;စနေ'),+ ampm: _('နံနက်;ညနေ'),+}, -1, 0), 'my');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('ਜਨਵਰੀ;ਫ਼ਰਵਰੀ;ਮਾਰਚ;ਅਪ੍ਰੈਲ;ਮਈ;ਜੂਨ;ਜੁਲਾਈ;ਅਗਸਤ;ਸਤੰਬਰ;ਅਕਤੂਬਰ;ਨਵੰਬਰ;ਦਸੰਬਰ'),+ mmm: _('ਜਨ;ਫ਼ਰ;ਮਾਰਚ;ਅਪ੍ਰੈ;ਮਈ;ਜੂਨ;ਜੁਲਾ;ਅਗ;ਸਤੰ;ਅਕਤੂ;ਨਵੰ;ਦਸੰ'),+ dddd: _('ਐਤਵਾਰ;ਸੋਮਵਾਰ;ਮੰਗਲਵਾਰ;ਬੁੱਧਵਾਰ;ਵੀਰਵਾਰ;ਸ਼ੁੱਕਰਵਾਰ;ਸ਼ਨਿੱਚਰਵਾਰ'),+ ddd: _('ਐਤ;ਸੋਮ;ਮੰਗਲ;ਬੁੱਧ;ਵੀਰ;ਸ਼ੁੱਕਰ;ਸ਼ਨਿੱਚਰ'),+ ampm: _('ਪੂ.ਦੁ.;ਬਾ.ਦੁ.'),+}, 'pa');++addLocale({+ group: '.',+ decimal: ',',+ mmmm: _('ianuarie;februarie;martie;aprilie;mai;iunie;iulie;august;septem~;octom~;noiem~;decem~', 'brie'),+ mmm: _('ian.;feb.;mar.;apr.;mai;iun.;iul.;aug.;sept.;oct.;nov.;dec.'),+ dddd: _('duminică;luni;marți;miercuri;joi;vineri;sâmbătă'),+ ddd: _('dum.;lun.;mar.;mie.;joi;vin.;sâm.'),+ ampm: _('a.m.;p.m.'),+}, 'ro');++addLocale(xm({+ group: '.',+ decimal: ',',+ mmmm: _('januar;februar;marec;april;maj;junij;julij;avgust;september;oktober;november;december'),+ mmm: _('jan.;feb.;mar.;apr.;maj;jun.;jul.;avg.;sep.;okt.;nov.;dec.'),+ dddd: _('nedelja;ponedeljek;torek;sreda;četrtek;petek;sobota'),+ ampm: _('dop.;pop.'),+}, -1, 13), 'sl');++addLocale(xm({+ group: '.',+ decimal: ',',+ mmmm: _('јануар;фебруар;март;април;мај;јун;јул;август;септембар;октобар;новембар;децембар'),+ dddd: _('недеља;понедељак;уторак;среда;четвртак;петак;субота'),+}, 3, 3), 'sr');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('ஜனவரி;பிப்ரவரி;மார்ச்;ஏப்ரல்;மே;ஜூன்;ஜூலை;ஆகஸ்ட்;செப்டம்பர்;அக்டோபர்;நவம்பர்;டிசம்பர்'),+ mmm: _('ஜன.;பிப்.;மார்.;ஏப்.;மே;ஜூன்;ஜூலை;ஆக.;செப்.;அக்.;நவ.;டிச.'),+ dddd: _('ஞாயிறு;திங்கள்;செவ்வாய்;புதன்;வியாழன்;வெள்ளி;சனி'),+ ddd: _('ஞாயி.;திங்.;செவ்.;புத.;வியா.;வெள்.;சனி'),+}, 'ta');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('జనవరి;ఫిబ్రవరి;మార్చి;ఏప్రిల్;మే;జూన్;జులై;ఆగస్టు;సెప్టెంబర్;అక్టోబర్;నవంబర్;డిసెంబర్'),+ mmm: _('జన;ఫిబ్ర;మార్చి;ఏప్రి;మే;జూన్;జులై;ఆగ;సెప్టెం;అక్టో;నవం;డిసెం'),+ dddd: _('ఆదివారం;సోమవారం;మంగళవారం;బుధవారం;గురువారం;శుక్రవారం;శనివారం'),+ ddd: _('ఆది;సోమ;మంగళ;బుధ;గురు;శుక్ర;శని'),+}, 'te');++addLocale({+ decimal: ',',+ mmmm: _('січня;лютого;березня;квітня;травня;червня;липня;серпня;вересня;жовтня;листопада;грудня'),+ mmm: _('січ.;лют.;бер.;квіт.;трав.;черв.;лип.;серп.;вер.;жовт.;лист.;груд.'),+ dddd: _('неділю;понеділок;вівторок;середу;четвер;пʼятницю;суботу'),+ ddd: _('нд;пн;вт;ср;чт;пт;сб'),+ ampm: _('дп;пп'),+}, 'uk');++addLocale({+ group: '.',+ decimal: ',',+ mmmm: _('~1;~2;~3;~4;~5;~6;~7;~8;~9;~10;~11;~12', 'tháng '),+ mmm: _('~1;~2;~3;~4;~5;~6;~7;~8;~9;~10;~11;~12', 'thg '),+ dddd: _('Chủ Nhật;Thứ Hai;Thứ Ba;Thứ Tư;Thứ Năm;Thứ Sáu;Thứ Bảy'),+ ddd: _('CN;Th 2;Th 3;Th 4;Th 5;Th 6;Th 7'),+ ampm: _('SA;CH'),+}, 'vi');++addLocale(xm({+ group: '٬',+ decimal: '٫',+ ampm: _('ص;م'),+ mmmm: _('يناير;فبراير;مارس;أبريل;مايو;يونيو;يوليو;أغسطس;سبتمبر;أكتوبر;نوفمبر;ديسمبر'),+ dddd: _('الأحد;الاثنين;الثلاثاء;الأربعاء;الخميس;الجمعة;السبت'),+ mmmm6: _('رمضان;شوال;ذو القعدة;ذو الحجة;محرم;ربيع الأول;ربيع الآخرة;جمادى الأولى;جمادى الآخرة;رجب;شعبان;رمضان'),+}, 0, 0), 'ar');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('জানুয়ারী;ফেব্রুয়ারী;মার্চ;এপ্রিল;মে;জুন;জুলাই;আগস্ট;সেপ্টেম্বর;অক্টোবর;নভেম্বর;ডিসেম্বর'),+ mmm: _('জানু;ফেব;মার্চ;এপ্রি;মে;জুন;জুল;আগ;সেপ্টেঃ;অক্টোঃ;নভেঃ;ডিসেঃ'),+ dddd: _('রবিবার;সোমবার;মঙ্গলবার;বুধবার;বৃহস্পতিবার;শুক্রবার;শনিবার'),+ ddd: _('রবি;সোম;মঙ্গল;বুধ;বৃহস্পতি;শুক্র;শনি'),+}, 'bn');++addLocale({+ group: ',',+ decimal: '.',+ mmmm: _('जनवरी;फ़रवरी;मार्च;अप्रैल;मई;जून;जुलाई;अगस्त;सितंबर;अक्तूबर;नवंबर;दिसंबर'),+ mmm: _('जन॰;फ़र॰;मार्च;अप्रैल;मई;जून;जुल॰;अग॰;सित॰;अक्तू॰;नव॰;दिस॰'),+ dddd: _('रविवार;सोमवार;मंगलवार;बुधवार;गुरुवार;शुक्रवार;शनिवार'),+ ddd: _('रवि;सोम;मंगल;बुध;गुरु;शुक्र;शनि'),+ ampm: _('am;pm'),+}, 'hi');diff --git a/packages/core/src/shared/numfmt/num-dec.ts b/packages/core/src/shared/numfmt/num-dec.tsnew file mode 100644index 0000000000..ba00d85f9a--- /dev/null+++ b/packages/core/src/shared/numfmt/num-dec.ts@@ -0,0 +1,52 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { NumberDigits } from './types';+import { decimalFromNumber } from './decimal';++const ZERO_DIGITS: NumberDigits = {+ total: 1,+ sign: 0,+ period: 0,+ int: 1,+ frac: 0,+};++// returns the count of digits (including - and .) need to represent the number+export function numDec(value: number, includeSign = true): NumberDigits {+ const decimal = decimalFromNumber(value);+ if (decimal.digits === '0') {+ return ZERO_DIGITS;+ }++ const decimalPoint = decimal.exponent + 1;+ const intSize = Math.max(decimalPoint, 1);+ const fracSize = Math.max(0, decimal.digits.length - decimalPoint);+ const signSize = includeSign && decimal.negative ? 1 : 0;+ const periodSize = fracSize > 0 ? 1 : 0;++ return {+ total: signSize + intSize + periodSize + fracSize,+ digits: Math.max(decimalPoint, 0) + fracSize,+ sign: signSize,+ period: periodSize,+ int: intSize,+ frac: fracSize,+ };+}diff --git a/packages/core/src/shared/numfmt/number-props.ts b/packages/core/src/shared/numfmt/number-props.tsnew file mode 100644index 0000000000..42867d4ae1--- /dev/null+++ b/packages/core/src/shared/numfmt/number-props.ts@@ -0,0 +1,32 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++export function getExponent(number: number, intMax: number = 0): number {+ const exponent = Math.floor(Math.log10(number));+ return intMax > 1+ ? Math.floor(exponent / intMax) * intMax+ : exponent;+}++export function getSignificand(number: number, exponent: number = 1): number {+ if (exponent < -300) {+ return Number.parseFloat(number.toExponential().split('e')[0]);+ }+ return number * (10 ** -exponent);+}diff --git a/packages/core/src/shared/numfmt/options.ts b/packages/core/src/shared/numfmt/options.tsnew file mode 100644index 0000000000..158ef95825--- /dev/null+++ b/packages/core/src/shared/numfmt/options.ts@@ -0,0 +1,53 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { ResolvedFormatOptions } from './types';++export const defaultOptions: Readonly<ResolvedFormatOptions> = {+ // Overflow error string+ overflow: '######', // dateErrorThrow needs to be off! [prev in locale]+ // Should it throw when there is an overflow error?+ dateErrorThrows: false,+ // Should it emit a number when date has an overflow error? (Sheets does this)+ dateErrorNumber: true, // dateErrorThrow needs to be off!+ // Should it emit a number when bigint has an is an overflow error?+ bigintErrorNumber: false,+ // Sheets mode (see #3)+ dateSpanLarge: true,+ // Simulate the Lotus 1-2-3 leap year bug+ leap1900: true,+ // Emit regular vs. non-breaking spaces+ nbsp: false,+ // Robust/throw mode+ throws: true,+ // What is emitted when robust mode fails to parse (###### currently)+ invalid: '######',+ // Locale+ locale: '',+ // Don't adjust dates to UTC when converting them to serial time+ ignoreTimezone: false,+ // Integer digit grouping+ grouping: [3, 3],+ // resolve indexed colors to hex+ indexColors: true,+ // Skip-next signifier character+ skipChar: '',+ // Repear-next signifier character+ fillChar: '',+};diff --git a/packages/core/src/shared/numfmt/pad.ts b/packages/core/src/shared/numfmt/pad.tsnew file mode 100644index 0000000000..70bcc325e0--- /dev/null+++ b/packages/core/src/shared/numfmt/pad.ts@@ -0,0 +1,34 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++/**+ * @ignore+ * @param {string} char Instruction character (['#', '?', '0'])+ * @param {boolean} [nbsp] Use nonbreaking space or not?+ * @returns {string} Padding character+ */+export function pad(char: string, nbsp: boolean = false): string {+ if (char === '0') {+ return '0';+ } else if (char === '?') {+ return nbsp ? '\u00A0' : ' ';+ }+ // if (char === '#')+ return '';+}diff --git a/packages/core/src/shared/numfmt/parse-format-section.ts b/packages/core/src/shared/numfmt/parse-format-section.tsnew file mode 100644index 0000000000..a765e8a02f--- /dev/null+++ b/packages/core/src/shared/numfmt/parse-format-section.ts@@ -0,0 +1,575 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { FormatToken, ParsedFormatSection, RenderToken } from './types';+import {+ EPOCH_1317,+ EPOCH_1900,+ TOKEN_AMPM,+ TOKEN_BREAK,+ TOKEN_CALENDAR,+ TOKEN_CHAR,+ TOKEN_COLOR,+ TOKEN_COMMA,+ TOKEN_CONDITION,+ TOKEN_DATETIME,+ TOKEN_DBNUM,+ TOKEN_DIGIT,+ TOKEN_DURATION,+ TOKEN_ERROR,+ TOKEN_ESCAPED,+ TOKEN_EXP,+ TOKEN_FILL,+ TOKEN_GENERAL,+ TOKEN_GROUP,+ TOKEN_HASH,+ TOKEN_LOCALE,+ TOKEN_MINUS,+ TOKEN_NATNUM,+ TOKEN_PAREN,+ TOKEN_PERCENT,+ TOKEN_PLUS,+ TOKEN_POINT,+ TOKEN_QMARK,+ TOKEN_SCALE,+ TOKEN_SKIP,+ TOKEN_SLASH,+ TOKEN_SPACE,+ TOKEN_STRING,+ TOKEN_TEXT,+ TOKEN_ZERO,+ u_CSEC,+ u_DAY,+ u_DSEC,+ u_HOUR,+ u_MIN,+ u_MONTH,+ u_MSEC,+ u_SEC,+ u_YEAR,+} from './constants';+import { resolveLocale } from './locale';++type NumberPatternName = 'int' | 'frac' | 'man' | 'den' | 'num';++interface INumberChunkToken extends RenderToken {+ type: NumberPatternName;+ num: string;+}++interface IDateChunkToken extends RenderToken {+ type: string;+ size: number;+ date: 1;+ pad?: boolean | number;+ used?: boolean;+ indeterminate?: boolean;+}++function getNumberPattern(part: ParsedFormatSection, prefix: NumberPatternName): string[] {+ switch (prefix) {+ case 'int':+ return part.int_pattern;+ case 'frac':+ return part.frac_pattern;+ case 'man':+ return part.man_pattern;+ case 'den':+ return part.den_pattern;+ case 'num':+ return part.num_pattern;+ }+}++function minMaxPad(str: string, part: ParsedFormatSection, prefix: NumberPatternName): ParsedFormatSection {+ const max = str.length;+ const min = str.replace(/#/g, '').length;+ switch (prefix) {+ case 'int':+ part.int_max = max;+ part.int_min = min;+ break;+ case 'frac':+ part.frac_max = max;+ part.frac_min = min;+ break;+ case 'man':+ part.man_max = max;+ part.man_min = min;+ break;+ case 'den':+ part.den_max = max;+ part.den_min = min;+ break;+ case 'num':+ part.num_max = max;+ part.num_min = min;+ break;+ }+ return part;+}++function add(token: string | RenderToken, tokens: RenderToken[]): void {+ // allow adding string tokens without wrapping+ if (typeof token === 'string') {+ tokens.push({ type: 'string', value: token });+ } else {+ tokens.push(token);+ }+}++function isNumOp(token: FormatToken | undefined, activePattern: NumberPatternName): boolean {+ const type = token?.type;+ return (+ type === TOKEN_HASH ||+ type === TOKEN_ZERO ||+ type === TOKEN_QMARK ||+ (type === TOKEN_DIGIT && activePattern === 'den')+ );+}++function assertNumberChunk(token: INumberChunkToken | null): asserts token is INumberChunkToken {+ if (token === null) {+ throw new TypeError('Cannot read properties of null (reading \'num\')');+ }+}++// eslint-disable-next-line max-lines-per-function, complexity+export function parseFormatSection(inputTokens: FormatToken[]): ParsedFormatSection {+ const outputTokens: RenderToken[] = [];++ const part: ParsedFormatSection = {+ scale: 1,+ scaleExponent: 0,+ percent: false,+ text: false,+ date: 0,+ date_eval: false,+ date_system: EPOCH_1900,+ sec_decimals: 0,+ general: false,+ clock: 24,+ int_pattern: [],+ frac_pattern: [],+ man_pattern: [],+ den_pattern: [],+ num_pattern: [],+ tokens: outputTokens,+ tokensUsed: 0,+ pattern: '',+ int_max: 0,+ int_min: 0,+ frac_max: 0,+ frac_min: 0,+ man_max: 0,+ man_min: 0,+ num_max: 0,+ num_min: 0,+ den_max: 0,+ den_min: 0,+ int_p: '',+ man_p: '',+ num_p: '',+ den_p: '',+ integer: false,+ };++ let currentPattern: NumberPatternName = 'int';+ let lastNumberChunk: INumberChunkToken | null = null;+ const dateChunks: IDateChunkToken[] = [];+ let last: FormatToken | undefined;+ let haveLocale = false;++ let index = -1;+ let partOver = false;+ let patternSource = '';+ let haveSlash = false;++ while (++index < inputTokens.length && !partOver) {+ const token = inputTokens[index];+ const type = token.type || TOKEN_ERROR;+ patternSource += token.raw;++ if (type === TOKEN_GENERAL) {+ part.general = true;+ add(token, outputTokens);+ } else if (isNumOp(token, currentPattern)) {+ const pattern = getNumberPattern(part, currentPattern);+ if (isNumOp(last, currentPattern) || last?.type === TOKEN_GROUP) {+ pattern.push((pattern.pop() || '') + token.value);+ assertNumberChunk(lastNumberChunk);+ lastNumberChunk.num += token.value;+ } else {+ pattern.push(token.value);+ lastNumberChunk = { type: currentPattern, num: token.value };+ add(lastNumberChunk, outputTokens);+ }+ } else if (type === TOKEN_PAREN) {+ if (token.value === '(') {+ part.parens = true;+ }+ add(token.value, outputTokens);+ } else if (type === TOKEN_DIGIT) {+ // just print it+ add(token.value, outputTokens);+ } else if (type === TOKEN_SLASH) {+ // vulgar fractions+ haveSlash = true;+ const pattern = getNumberPattern(part, currentPattern);+ if (pattern.length) {+ if (!lastNumberChunk) { // need to have a numerator present+ throw new SyntaxError('Format pattern is missing a numerator');+ }+ part.fractions = true;+ // ... we just passed the numerator - correct that item+ const numerator = pattern.pop();+ if (numerator === undefined) {+ throw new SyntaxError('Format pattern is missing a numerator');+ }+ part.num_pattern.push(numerator);+ lastNumberChunk.type = 'num';+ // next up... the denominator+ currentPattern = 'den';+ add({ type: 'div' }, outputTokens);+ } else {+ add(token.value, outputTokens);+ }+ } else if (type === TOKEN_COMMA) {+ add(',', outputTokens);+ } else if (type === TOKEN_SCALE) {+ part.scale = 0.001 ** token.raw.length;+ part.scaleExponent = -3 * token.raw.length;+ } else if (type === TOKEN_GROUP) {+ if (currentPattern === 'int') {+ part.grouping = true;+ }+ if (currentPattern === 'den') {+ throw new SyntaxError('Cannot group denominator digits');+ }+ // else we just ignore it!+ } else if (type === TOKEN_SPACE) {+ add(token, outputTokens);+ } else if (type === TOKEN_BREAK) {+ partOver = true;+ break; // leave the ";" hanging+ } else if (type === TOKEN_TEXT) {+ part.text = true;+ add(token, outputTokens);+ } else if (type === TOKEN_PLUS || type === TOKEN_MINUS) {+ add(token, outputTokens);+ } else if (type === TOKEN_DURATION) {+ // [h] [m] [s]+ const tokenValue = token.value.toLowerCase();+ const startsWith = tokenValue[0];+ const bit: IDateChunkToken = { type: '', size: 0, date: 1, pad: tokenValue.length };+ if (startsWith === 'h') {+ bit.size = u_HOUR;+ bit.type = 'hour-elap';+ } else if (startsWith === 'm') {+ bit.size = u_MIN;+ bit.type = 'min-elap';+ } else {+ bit.size = u_SEC;+ bit.type = 'sec-elap';+ }+ // signal date calc and track smallest needed unit+ part.date = part.date | bit.size;+ dateChunks.push(bit);+ add(bit, outputTokens);+ } else if (part.date && type === TOKEN_POINT && inputTokens[index + 1]?.type === TOKEN_ZERO) {+ // In locales where decimal symbol is set to "," Excel will expect+ // "," rather than a ".". The pattern must be re-localized first.+ let decimals = 1;+ index++;+ let raw = '0';+ if (inputTokens[index + 1]?.type === TOKEN_ZERO) {+ raw += '0';+ decimals = 2;+ index++;+ }+ if (inputTokens[index + 1]?.type === TOKEN_ZERO) {+ raw += '0';+ decimals = 3;+ index++;+ }+ patternSource += raw;+ const size = [u_SEC, u_DSEC, u_CSEC, u_MSEC][decimals];+ part.date = part.date | size;+ part.date_eval = true;+ part.sec_decimals = Math.max(part.sec_decimals, decimals);+ add({+ type: 'subsec',+ size,+ decimals,+ date: 1,+ }, outputTokens);+ } else if (type === TOKEN_CALENDAR) {+ // signal date system (ignored if defined with [$-xxx])+ if (!haveLocale) {+ if (token.value === 'B2' || token.value === 'b2') {+ // TODO: B2 also switches locale to [$-060401] (ar).+ part.date_system = EPOCH_1317;+ } else {+ part.date_system = EPOCH_1900;+ }+ }+ } else if (type === TOKEN_DATETIME) {+ // hh:mm:ss YYYY-MM-DD+ const bit: IDateChunkToken = { type: '', size: 0, date: 1 };+ const value = token.value.toLowerCase();+ const startsWith = value[0];+ if (value === 'y' || value === 'yy') {+ bit.size = u_YEAR;+ bit.type = 'year-short';+ } else if (startsWith === 'y' || startsWith === 'e') {+ bit.size = u_YEAR;+ bit.type = 'year';+ } else if (value === 'b' || value === 'bb') {+ bit.size = u_YEAR;+ bit.type = 'b-year-short';+ } else if (startsWith === 'b') {+ bit.size = u_YEAR;+ bit.type = 'b-year';+ } else if (value === 'd' || value === 'dd') {+ bit.size = u_DAY;+ bit.type = 'day';+ bit.pad = /dd/.test(value);+ } else if (value === 'ddd' || value === 'aaa') {+ bit.size = u_DAY;+ bit.type = 'weekday-short';+ } else if (startsWith === 'd' || startsWith === 'a') {+ bit.size = u_DAY;+ bit.type = 'weekday';+ } else if (startsWith === 'h') {+ bit.size = u_HOUR;+ bit.type = 'hour';+ bit.pad = /hh/i.test(value);+ } else if (startsWith === 'm') {+ if (value.length === 3) {+ bit.size = u_MONTH;+ bit.type = 'monthname-short';+ } else if (value.length === 5) {+ bit.size = u_MONTH;+ bit.type = 'monthname-single';+ } else if (value.length >= 4) {+ bit.size = u_MONTH;+ bit.type = 'monthname';+ }+ // m or mm can be either minute or month based on context+ const lastDateChunk = dateChunks[dateChunks.length - 1];+ if (+ !bit.type &&+ lastDateChunk &&+ !lastDateChunk.used &&+ (lastDateChunk.size & (u_HOUR | u_SEC))+ ) {+ lastDateChunk.used = true;+ bit.size = u_MIN;+ bit.type = 'min';+ bit.pad = /mm/.test(value);+ }+ // if we still don't know, treat as a month and defer+ if (!bit.type) {+ bit.size = u_MONTH;+ bit.type = 'month';+ bit.pad = /mm/.test(value);+ bit.indeterminate = true;+ }+ } else if (startsWith === 's') {+ bit.size = u_SEC;+ bit.type = 'sec';+ bit.pad = /ss/.test(value);+ const lastDateChunk = dateChunks[dateChunks.length - 1];+ if (lastDateChunk && (lastDateChunk.size & u_MIN)) {+ bit.used = true;+ } else if (lastDateChunk?.indeterminate) {+ delete lastDateChunk.indeterminate;+ lastDateChunk.size = u_MIN;+ lastDateChunk.type = 'min';+ bit.used = true;+ }+ } else if (startsWith === 'g') {+ // TODO: Don't know what this does? (yet!)+ }+ // signal date calc and track smallest needed unit+ part.date = part.date | bit.size;+ part.date_eval = true;+ dateChunks.push(bit);+ add(bit, outputTokens);+ } else if (type === TOKEN_AMPM) {+ part.clock = 12;+ part.date = part.date | u_HOUR;+ part.date_eval = true;+ token.short = token.value === 'A/P';+ add(token, outputTokens);+ } else if (type === TOKEN_STRING || type === TOKEN_ESCAPED || type === TOKEN_CHAR) {+ add(token.value, outputTokens);+ } else if (type === TOKEN_CONDITION) {+ part.condition = [token.value[0], Number.parseFloat(token.value[1])];+ } else if (type === TOKEN_LOCALE) {+ const bits = token.value.split('-');+ const code = bits.length < 2 ? '' : bits.slice(1).join('-');++ const currency = bits[0];+ if (currency) {+ add(currency, outputTokens);+ }++ const locale = resolveLocale(code);+ if (locale) {+ part.locale = locale;+ }+ const windowsCode = Number.parseInt(code, 16);+ if (Number.isFinite(windowsCode) && (windowsCode & 0xFF0000)) {+ const calendar = (windowsCode >> 16) & 0xFF;+ if (calendar === 6) {+ part.date_system = EPOCH_1317;+ }+ }++ haveLocale = true; // ignore any B2 & B1 tokens+ } else if (type === TOKEN_COLOR) {+ const normalizedColor: string = token.value.toLowerCase();+ let color: string | number = normalizedColor;+ const colorMatch = /^color\s*(\d+)$/i.exec(normalizedColor);+ if (colorMatch) {+ color = Number.parseInt(colorMatch[1], 10);+ }+ part.color = color;+ } else if (type === TOKEN_PERCENT) {+ part.scale = 100;+ part.scaleExponent = 2;+ part.percent = true;+ add('%', outputTokens);+ } else if (type === TOKEN_POINT) {+ add(token, outputTokens);+ if (!part.date) {+ part.dec_fractions = true;+ currentPattern = 'frac';+ }+ } else if (type === TOKEN_EXP) {+ part.exponential = true;+ part.exp_plus = token.value.includes('+');+ currentPattern = 'man';+ add({ type: 'exp', plus: part.exp_plus }, outputTokens);+ } else if (type === TOKEN_SKIP || type === TOKEN_FILL) {+ add(token, outputTokens);+ } else if (type === TOKEN_DBNUM || type === TOKEN_NATNUM) {+ // Unsupported upstream numeric modifiers are deliberately ignored.+ } else if (type === TOKEN_ERROR) {+ throw new SyntaxError(`Illegal character: ${patternSource}`);+ } else {+ throw new SyntaxError(`Unknown token ${type} in ${patternSource}`);+ }++ // advance parser+ last = token;+ }+ part.tokensUsed = index;+ part.pattern = patternSource;++ // Quickly determine if this pattern is condition only.+ if (/^((?:\[[^\]]+\])+)(;|$)/.test(part.pattern) && !/^\[(?:h+|m+|s+)\]/.test(part.pattern)) {+ add({ type: 'text' }, outputTokens);+ }++ if (+ (part.fractions && part.dec_fractions) ||+ (part.grouping && !part.int_pattern.length) ||+ (part.fractions && part.exponential) ||+ (part.fractions && (part.den_pattern.length * part.num_pattern.length) === 0) ||+ (haveSlash && !part.fractions && !part.date) ||+ (part.exponential && ((part.int_pattern.length || part.frac_pattern.length) * part.man_pattern.length) === 0)+ ) {+ throw new SyntaxError(`Invalid pattern: ${patternSource}`);+ }++ const intPattern = part.int_pattern.join('');+ const manPattern = part.man_pattern.join('');+ const fracPattern = part.frac_pattern.join('');+ minMaxPad(intPattern, part, 'int');+ let min = 0;+ for (let patternIndex = 0; patternIndex < intPattern.length; patternIndex++) {+ const character = intPattern[intPattern.length - 1 - patternIndex];+ if (/^[0-9?]/.test(character)) {+ min = patternIndex + 1;+ }+ }+ part.int_min = min;++ minMaxPad(fracPattern, part, 'frac');+ minMaxPad(manPattern, part, 'man');++ let numeratorPattern = part.num_pattern.join('');+ let denominatorPattern = part.den_pattern[0] || '';+ const enforcePadded = denominatorPattern.includes('?') || numeratorPattern.includes('?');+ if (enforcePadded) {+ denominatorPattern = denominatorPattern.replace(/\d/g, '?');+ denominatorPattern = denominatorPattern.replace(/#$/g, '?');+ minMaxPad(numeratorPattern, part, 'num');+ minMaxPad(denominatorPattern, part, 'den');+ numeratorPattern = numeratorPattern.replace(/#$/g, '?');+ } else {+ minMaxPad(numeratorPattern, part, 'num');+ minMaxPad(denominatorPattern, part, 'den');+ }++ part.int_p = intPattern;+ part.man_p = manPattern;+ part.num_p = numeratorPattern;+ part.den_p = denominatorPattern;++ if (part.den_pattern.length) {+ part.denominator = Number.parseInt(part.den_pattern.join('').replace(/\D/g, ''), 10);+ }++ part.integer = !!intPattern.length;++ if (!part.integer && !part.exponential && fracPattern.length) {+ const pointIndex = part.tokens.findIndex((token) => token.type === 'point');+ part.tokens.splice(pointIndex, 0, { type: 'int', value: '#' });+ part.integer = true;+ part.int_pattern = ['#'];+ part.int_p = '#';+ }++ // Extra whitespace rules for vulgar fractions.+ if (part.fractions) {+ for (let tokenIndex = 0; tokenIndex < outputTokens.length - 1; tokenIndex++) {+ const token = outputTokens[tokenIndex];+ if (token.type !== 'string' && token.type !== 'space') {+ continue;+ }+ const nextType = outputTokens[tokenIndex + 1].type;+ if (nextType === 'num') {+ token.rule = 'num+int';+ } else if (nextType === 'div') {+ token.rule = 'num';+ } else if (nextType === 'den') {+ token.rule = 'den';+ }+ }+ }++ if (part.grouping && part.int_pattern.length > 1) {+ part.grouping = false;+ }++ return part;+}diff --git a/packages/core/src/shared/numfmt/parse-pattern.ts b/packages/core/src/shared/numfmt/parse-pattern.tsnew file mode 100644index 0000000000..316bee173c--- /dev/null+++ b/packages/core/src/shared/numfmt/parse-pattern.ts@@ -0,0 +1,229 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type {+ ErrorFormatSection,+ ParsedFormatSection,+ ParsedPattern,+ RenderToken,+} from './types';+import { resolveLocale } from './locale';+import { parseFormatSection } from './parse-format-section';+import { tokenize } from './tokenize';++interface IGeneratedFormatSection extends ParsedFormatSection {+ generated?: boolean;+}++function maybeAddMinus(part: IGeneratedFormatSection): void {+ const operator = part.condition?.[0];+ const value = part.condition?.[1];+ const exception = (+ (typeof value === 'number' && value < 0 && (operator === '<' || operator === '<=' || operator === '=')) ||+ (value === 0 && operator === '<')+ );+ if (!exception) {+ part.tokens.unshift({+ type: 'minus',+ volatile: true,+ });+ }+}++function clonePart(part: IGeneratedFormatSection, prefixToken: RenderToken | null = null): IGeneratedFormatSection {+ const result: IGeneratedFormatSection = {+ ...part,+ int_pattern: [...part.int_pattern],+ frac_pattern: [...part.frac_pattern],+ man_pattern: [...part.man_pattern],+ den_pattern: [...part.den_pattern],+ num_pattern: [...part.num_pattern],+ tokens: [...part.tokens],+ };+ if (part.condition) {+ result.condition = [...part.condition];+ }+ if (prefixToken) {+ result.tokens.unshift(prefixToken);+ }+ result.generated = true;+ return result;+}++// eslint-disable-next-line max-lines-per-function, complexity+export function parsePattern(pattern: string): ParsedPattern {+ const partitions: IGeneratedFormatSection[] = [];+ let conditional = false;+ let localeOverride: string | null | undefined;+ let textPartition: IGeneratedFormatSection | null = null;+ let more = 0;+ let index = 0;+ let conditions = 0;+ let tokens = tokenize(pattern);+ do {+ const part: IGeneratedFormatSection = parseFormatSection(tokens);+ // Dates cannot blend with non-date tokens.+ // General cannot blend with non-date tokens.+ if (+ (part.date || part.general) &&+ (part.int_pattern.length || part.frac_pattern.length || part.scale !== 1 || part.text)+ ) {+ throw new Error('Illegal format');+ }+ if (part.condition) {+ conditions++;+ conditional = true;+ }+ if (part.text) {+ // only one text partition is allowed per pattern+ if (textPartition) {+ throw new Error('Unexpected partition');+ }+ textPartition = part;+ }+ if (part.locale) {+ localeOverride = resolveLocale(part.locale);+ }+ partitions.push(part);++ more = tokens[part.tokensUsed]?.type === 'break' ? 1 : 0;+ tokens = tokens.slice(part.tokensUsed + more);+ index++;+ } while (more && index < 4 && conditions < 3);++ // No more than 4 sections are allowed.+ if (more) {+ throw new Error('Unexpected partition');+ }+ // Only 2 conditional statements are allowed: "1;2;else;txt".+ if (conditions > 2) {+ throw new Error('Unexpected condition');+ }+ // 3rd part must be text or neutral if it is present.+ const fourthPart = partitions[3];+ if (fourthPart && (fourthPart.int_pattern.length || fourthPart.frac_pattern.length || fourthPart.date)) {+ throw new Error('Unexpected partition');+ }++ if (conditional) {+ // When a pattern has a single partition which exists in the second+ // partition, we must also set the first partition to `[>0]`.+ if (!partitions[0].condition) {+ partitions[0].condition = ['>', 0];+ }++ // Conditional patterns get a volatile minus on the "else" partitions.+ const numberOfParts = partitions.length;+ if (numberOfParts === 1) {+ // provide a fallback pattern if there isn't one+ const fallback: IGeneratedFormatSection = parseFormatSection(tokenize('General'));+ fallback.generated = true;+ partitions[1] = fallback;+ }+ if (numberOfParts <= 2) {+ // [<10]0;[>10]0 is valid but may not match a runtime value.+ }+ if (numberOfParts < 3) {+ const firstPart = partitions[0];+ const secondPart = partitions[1];+ maybeAddMinus(firstPart);+ if (secondPart.condition) {+ maybeAddMinus(secondPart);+ } else {+ const condition = firstPart.condition;+ if (+ condition?.[0] === '=' ||+ (typeof condition?.[1] === 'number' &&+ condition[1] >= 0 &&+ (condition[0] === '>' || condition[0] === '>='))+ ) {+ secondPart.tokens.unshift({+ type: 'minus',+ volatile: true,+ });+ }+ }+ } else {+ // 3 and 4 part patterns+ partitions.forEach(maybeAddMinus);+ }+ } else {+ // If there are fewer than 4 partitions and one is text, reserve it for text.+ if (partitions.length < 4 && textPartition) {+ for (let partitionIndex = 0, length = partitions.length; partitionIndex < length; partitionIndex++) {+ if (partitions[partitionIndex] === textPartition) {+ partitions.splice(partitionIndex, 1);+ }+ }+ }+ // missing positive+ if (partitions.length < 1 && textPartition) {+ const positive: IGeneratedFormatSection = parseFormatSection(tokenize('General'));+ positive.generated = true;+ partitions[0] = positive;+ }+ // missing negative+ if (partitions.length < 2) {+ const volatileMinus: RenderToken = { type: 'minus', volatile: true };+ partitions.push(clonePart(partitions[0], volatileMinus));+ }+ // missing zero+ if (partitions.length < 3) {+ partitions.push(clonePart(partitions[0]));+ }+ // missing text+ if (partitions.length < 4) {+ if (textPartition) {+ partitions.push(textPartition);+ } else {+ const text: IGeneratedFormatSection = parseFormatSection(tokenize('@'));+ text.generated = true;+ partitions.push(text);+ }+ }++ partitions[0].condition = ['>', 0];+ partitions[1].condition = ['<', 0];+ partitions[2].condition = null;+ }++ return {+ pattern,+ partitions,+ locale: localeOverride,+ };+}++export function parseCatch(pattern: string): ParsedPattern {+ try {+ return parsePattern(pattern);+ } catch (error: unknown) {+ const message = error instanceof Error ? error.message : String(error);+ const errorPart: ErrorFormatSection = {+ tokens: [{ type: 'error' }],+ error: message,+ };+ return {+ pattern,+ partitions: [errorPart, errorPart, errorPart, errorPart],+ error: message,+ locale: null,+ };+ }+}diff --git a/packages/core/src/shared/numfmt/parse-value.ts b/packages/core/src/shared/numfmt/parse-value.tsnew file mode 100644index 0000000000..0951107f97--- /dev/null+++ b/packages/core/src/shared/numfmt/parse-value.ts@@ -0,0 +1,733 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { LocaleData, ParseData } from './types';+import { currencySymbols, reCurrencySymbols } from './constants';+import { defaultLocale, getLocale } from './locale';++// eslint-disable-next-line ts/naming-convention+export interface ParseOptions {+ locale?: string;+}++/*+ * This is the list of allowed date formats. Legend:+ *+ * - `-`: any date separator+ * - `j`/`d`: day without/with a leading zero+ * - `D`/`l`: abbreviated/full day name+ * - `n`/`m`: month without/with a leading zero+ * - `M`/`F`: abbreviated/full month name+ * - `y`/`Y`: two-/four-digit year+ * - `x`: time of day+ * - `!`/`?`: date-first/month-first locales only+ */+const okDateFormats = [+ // day-month-year+ '!d-m-y',+ '!d-m-Y',+ '!j-m-y',+ '!j-m-Y',+ '!d-n-y',+ '!d-n-Y',+ '!j-n-y',+ '!j-n-Y',+ // month-day-year+ '?m-d-y',+ '?m-d-Y',+ '?m-j-y',+ '?m-j-Y',+ '?n-d-y',+ '?n-d-Y',+ '?n-j-y',+ '?n-j-Y',+ // unabbreviated+ 'd-M-y',+ 'd-M-Y',+ 'j-M-y',+ 'j-M-Y',+ 'M-d-y',+ 'M-d-Y',+ 'M-j-y',+ 'M-j-Y',+ 'd-F-y',+ 'd-F-Y',+ 'F-d-y',+ 'F-d-Y',+ 'F-j-y',+ 'F-j-Y',+ 'j-F-y',+ 'j-F-Y',+ 'y-F-d',+ 'y-F-j',+ 'y-M-d',+ 'y-M-j',+ 'Y-F-d',+ 'Y-F-j',+ 'Y-M-d',+ 'Y-m-d',+ 'Y-M-j',+ 'Y-m-j',+ 'Y-n-d',+ 'Y-n-j',+ 'j-F',+ 'j-M',+ 'd-F',+ 'd-M',+ 'n-d',+ 'n-j',+ 'n-Y',+ 'm-d',+ 'm-j',+ 'm-Y',+ 'M-Y',+ 'M-y',+ 'F-y',+ 'F-Y',+ 'Y-M',+ 'Y-n',+ 'Y-m',+ 'Y-F',+ 'Y-M',+];++const tx0: Record<string, string> = {+ j: 'd',+ d: 'd',+ D: 'ddd',+ l: 'dddd',+ n: 'm',+ m: 'm',+ M: 'mmm',+ F: 'mmmm',+ y: 'yy',+ Y: 'yyyy',+};+const tx00: Record<string, string> = {+ j: 'dd',+ d: 'dd',+ D: 'ddd',+ l: 'dddd',+ n: 'mm',+ m: 'mm',+ M: 'mmm',+ F: 'mmmm',+ y: 'yy',+ Y: 'yyyy',+};++interface IDateTrie {+ [token: string]: IDateTrie | number | undefined;+}++const dateTrieDM: IDateTrie = {};+const dateTrieMD: IDateTrie = {};++function packDate(format: string, node: IDateTrie, allowType: number = 1): void {+ if (format) {+ const char = format[0];+ const next = format.slice(1);+ if (char === '!') {+ packDate(next, node, 4);+ } else if (char === '?') {+ packDate(next, node, 2);+ } else {+ let branch = node[char];+ if (typeof branch !== 'object') {+ branch = {};+ node[char] = branch;+ }+ packDate(next, branch, allowType);+ }+ } else {+ node.$ = allowType;+ }+}++function addFormatToTrie(format: string, trie: IDateTrie): void {+ packDate(format, trie);+ packDate(`${format} x`, trie);+ packDate(`${format} l`, trie);+ packDate(`${format} l x`, trie);+ packDate(`l ${format}`, trie);+ packDate(`l ${format} x`, trie);+ packDate(`${format} D`, trie);+ packDate(`${format} D x`, trie);+ packDate(`D ${format}`, trie);+ packDate(`D ${format} x`, trie);+}++okDateFormats.forEach((format) => {+ if (!format.startsWith('?')) {+ addFormatToTrie(format, dateTrieDM);+ }+ if (!format.startsWith('!')) {+ addFormatToTrie(format, dateTrieMD);+ }+});++const currentYear = new Date().getUTCFullYear();++const PT = '.';+const CM = ',';+const SP = ' ';+const NS = ' ';+const NN = ' ';+const AP = "'";+const AG = '٬';+const dec2group: Record<string, string[]> = {+ '.': [CM, NS, NN, AP, AG],+ ',': [PT, NS, NN, AP, AG],+ '٫': [PT, NS, NN, AP, AG],+};++const isDigit = (digit: string | undefined): boolean =>+ digit?.length === 1 && digit >= '0' && digit <= '9';++/** Parse a numeric string and return its value and inferred format. */+// eslint-disable-next-line max-lines-per-function, complexity+export function parseNumber(value: string, options: ParseOptions = {}): ParseData<number> | null {+ const l10n = getLocale(options.locale || '') || defaultLocale;+ const decimal = l10n.decimal;+ const groupingChars = [...(dec2group[decimal] || [AP, AG])];+ if (+ !groupingChars.includes(l10n.group) &&+ l10n.group !== SP &&+ l10n.group !== decimal+ ) {+ groupingChars.push(l10n.group);+ }++ let number = '';+ let exponent = '';+ let sign = 1;+ let format = '';+ let minus = false;+ let openParen = false;+ let closeParen = false;+ let percent = false;+ let currency = false;+ let currencySymbol = '';+ let currencyTrailing = false;+ let index = 0;++ const prefixChars = [SP, NS, NN, '+', '%', '(', '-'].concat(currencySymbols);+ while (prefixChars.includes(value.charAt(index))) {+ const char = value.charAt(index);+ if (char === '-') {+ if (minus || openParen) {+ return null;+ }+ minus = true;+ sign = -1;+ } else if (reCurrencySymbols.test(char)) {+ if (currency) {+ return null;+ }+ currency = true;+ currencySymbol = char;+ } else if (char === '(') {+ if (openParen || minus) {+ return null;+ }+ openParen = true;+ sign = -1;+ } else if (char === '%') {+ if (percent) {+ return null;+ }+ percent = true;+ }+ index++;+ }++ let haveDecimal = false;+ let grouping: string | undefined;+ if (value.charAt(index) === decimal || isDigit(value.charAt(index))) {+ while (index < value.length) {+ const char = value.charAt(index);+ if (!grouping && groupingChars.includes(char)) {+ grouping = char;+ } else if (grouping && grouping === char) {+ // Keep consuming the selected grouping separator.+ } else if (char === decimal) {+ if (haveDecimal) {+ break;+ }+ number += '.';+ haveDecimal = true;+ } else if (isDigit(char)) {+ number += char;+ } else {+ break;+ }+ index++;+ }+ }++ if (value.charAt(index) === 'e' || value.charAt(index) === 'E') {+ exponent += value.charAt(index);+ index++;+ if (value.charAt(index) === '+' || value.charAt(index) === '-') {+ exponent += value.charAt(index);+ index++;+ }+ const exponentStart = index;+ while (isDigit(value.charAt(index))) {+ exponent += value.charAt(index);+ index++;+ }+ if (exponentStart === index) {+ return null;+ }+ }++ const suffixChars = [SP, NS, NN, '%', '$', ')'].concat(currencySymbols);+ while (suffixChars.includes(value.charAt(index))) {+ const char = value.charAt(index);+ if (reCurrencySymbols.test(char)) {+ if (currency) {+ return null;+ }+ currency = true;+ currencySymbol = char;+ currencyTrailing = true;+ } else if (char === ')') {+ if (closeParen || !openParen) {+ return null;+ }+ closeParen = true;+ } else if (char === '%') {+ if (percent) {+ return null;+ }+ percent = true;+ }+ index++;+ }++ if (index !== value.length) {+ return null;+ }++ let numberValue = Number.parseFloat(number + exponent);+ if (!Number.isFinite(numberValue)) {+ return null;+ }++ if (exponent) {+ if (percent || currency) {+ return null;+ }+ format = '0.00E+00';+ } else if (percent) {+ if (currency) {+ return null;+ }+ format = number.includes('.') ? '0.00%' : '0%';+ numberValue *= 0.01;+ } else if (currency) {+ const currencyFormat = number.includes('.') ? '#,##0.00' : '#,##0';+ format = currencyTrailing+ ? currencyFormat + currencySymbol+ : currencySymbol + currencyFormat;+ } else if (grouping) {+ format = number.includes('.') ? '#,##0.00' : '#,##0';+ }++ const result: ParseData<number> = { v: numberValue * sign };+ if (format) {+ result.z = format;+ }+ return result;+}++// eslint-disable-next-line complexity+export function isValidDate(year: number, month: number, day: number): boolean {+ if (day < 1) {+ return false;+ }+ if (month < 1 || month > 12) {+ return false;+ }+ if (month === 2) {+ const isLeapYear = (+ ((year % 4 === 0) && (year % 100 !== 0)) ||+ (year % 400 === 0)+ );+ const februaryDays = isLeapYear || year === 1900 ? 29 : 28;+ if (day > februaryDays) {+ return false;+ }+ } else if (+ ((month === 4 || month === 6 || month === 9 || month === 11) && day > 30) ||+ (+ (month === 1 || month === 3 || month === 5 || month === 7 || month === 8 || month === 10 || month === 12) &&+ day > 31+ )+ ) {+ return false;+ }+ return true;+}++type LookupSymbol = 'F' | 'M' | 'l' | 'D';+type LocaleLookup = [text: string, value: number, symbol: LookupSymbol];++interface IDateLocaleData {+ mon: LocaleLookup[];+ mp: boolean;+ day: LocaleLookup[];+ dp: boolean;+ locale?: string;+}++interface IDateParseState {+ path: string;+ sep?: string;+ day?: string;+ month?: number;+ _mon?: string;+ year?: number;+ time?: number;+ tf?: string;+}++const matchRec = (+ string: string,+ data: LocaleLookup[],+ skipPeriod: boolean = false+): [string, LocaleLookup | null] => {+ for (const item of data) {+ if (string.startsWith(item[0])) {+ let length = item[0].length;+ if (+ skipPeriod &&+ (item[2] === 'D' || item[2] === 'M') &&+ string[length] === '.'+ ) {+ length++;+ }+ return [string.slice(0, length), item];+ }+ }+ return ['', null];+};++/* eslint-disable max-lines-per-function, complexity */+const nextToken = (+ string: string,+ node: IDateTrie,+ data: IDateParseState,+ localeData: IDateLocaleData+): IDateParseState | undefined => {+ const path = data.path || '';+ const matchOrder = Object.keys(node);+ for (const token of matchOrder) {+ const branch = node[token];+ let result: IDateParseState | undefined;+ if (!branch) {+ continue;+ }+ if (token === '$' || token === '€') {+ if (!string) {+ result = data;+ }+ } else {+ if (typeof branch !== 'object') {+ continue;+ }+ if (token === '-') {+ const match = /^(\s*([./-]|,\s)\s*|\s+)/.exec(string);+ if (match) {+ const separator = (+ match[1] === '-' || match[1] === '/' || match[1] === '.'+ )+ ? match[1]+ : ' ';+ if (!data.sep || data.sep === separator) {+ const normalizedSeparator = match[0].replace(/\s+/g, ' ');+ result = nextToken(+ string.slice(match[0].length),+ branch,+ { ...data, sep: separator, path: path + normalizedSeparator },+ localeData+ );+ }+ }+ } else if (token === ' ') {+ const match = /^[,.]?\s+/.exec(string);+ if (match) {+ const normalizedSeparator = match[0].replace(/\s+/g, ' ');+ result = nextToken(+ string.slice(match[0].length),+ branch,+ { ...data, path: path + normalizedSeparator },+ localeData+ );+ }+ } else if (token === 'j' || token === 'd') {+ const match = /^(0?[1-9]|1\d|2\d|3[01])\b/.exec(string);+ if (match) {+ result = nextToken(+ string.slice(match[0].length),+ branch,+ { ...data, day: match[0], path: path + token },+ localeData+ );+ }+ } else if (token === 'n' || token === 'm') {+ const match = /^(0?[1-9]|1[012])\b/.exec(string);+ if (match) {+ result = nextToken(+ string.slice(match[0].length),+ branch,+ { ...data, month: +match[0], _mon: match[0], path: path + token },+ localeData+ );+ }+ } else if (token === 'F' || token === 'M') {+ const [matchedText, match] = matchRec(string, localeData.mon, localeData.mp);+ if (match?.[2] === token) {+ result = nextToken(+ string.slice(matchedText.length),+ branch,+ { ...data, month: match[1], _mon: matchedText, path: path + token },+ localeData+ );+ }+ } else if (token === 'l' || token === 'D') {+ const [matchedText, match] = matchRec(string, localeData.day, localeData.dp);+ if (match?.[2] === token) {+ result = nextToken(+ string.slice(matchedText.length),+ branch,+ { ...data, path: path + token },+ localeData+ );+ }+ } else if (token === 'y') {+ const match = /^\d\d\b/.exec(string);+ if (match) {+ const year = +match[0] >= 30 ? +match[0] + 1900 : +match[0] + 2000;+ result = nextToken(+ string.slice(match[0].length),+ branch,+ { ...data, year, path: path + token },+ localeData+ );+ }+ } else if (token === 'Y') {+ const match = /^\d\d\d\d\b/.exec(string);+ if (match) {+ result = nextToken(+ string.slice(match[0].length),+ branch,+ { ...data, year: +match[0], path: path + token },+ localeData+ );+ }+ } else if (token === 'x') {+ const time = parseTime(string, { locale: localeData.locale });+ if (time) {+ result = nextToken(+ '',+ branch,+ { ...data, time: time.v, tf: time.z, path: path + token },+ localeData+ );+ }+ } else {+ throw new Error(`Unknown date token "${token}"`);+ }+ }+ if (+ result &&+ isValidDate(data.year || 1916, data.month || 1, data.day ? +data.day : 1)+ ) {+ return result;+ }+ }+};+/* eslint-enable max-lines-per-function, complexity */++const normDateStr = (string: string): string =>+ string+ .replace(/\s+/g, ' ')+ .trim()+ .replace(/’/, "'")+ .replace(/\.$/, '')+ .toLowerCase();++const getLookups = (values: string[], symbol: LookupSymbol): LocaleLookup[] => {+ const lookups: LocaleLookup[] = values.map((value, index) => [+ normDateStr(value),+ index + 1,+ symbol,+ ]);+ lookups.sort((a, b) => b[0].length - a[0].length);+ return lookups;+};++/** Parse a date or datetime string and return its serial value and format. */+// eslint-disable-next-line complexity+export function parseDate(value: string, options: ParseOptions = {}): ParseData<number> | null {+ const l10n = getLocale(options.locale || '') || defaultLocale;+ const localeData: IDateLocaleData = {+ mon: getLookups(l10n.mmmm, 'F').concat(getLookups(l10n.mmm, 'M')),+ mp: l10n.mmm[0].at(-1) === '.',+ day: getLookups(l10n.dddd, 'l').concat(getLookups(l10n.ddd, 'D')),+ dp: l10n.ddd[0].at(-1) === '.',+ locale: options.locale,+ };+ const date = nextToken(+ normDateStr(value),+ l10n.preferMDY ? dateTrieMD : dateTrieDM,+ { path: '' },+ localeData+ );+ if (!date) {+ return null;+ }+ if (date.sep === '.' && date.path.length === 3) {+ return null;+ }+ if (date.month == null || date._mon == null) {+ return null;+ }++ const year = +(date.year ?? currentYear);+ const day = date.day ?? '1';+ let epoch = -Infinity;+ if (year < 1900) {+ return null;+ } else if (year <= 1900 && date.month <= 2) {+ epoch = 25568;+ } else if (year < 10000) {+ epoch = 25569;+ }+ const dateValue = (+ Date.UTC(year, date.month - 1, +day) / 864e5+ ) + epoch + (date.time || 0);+ if (dateValue < 0 || dateValue > 2958465) {+ return null;+ }++ const lead0 = (+ date._mon[0] === '0' ||+ day[0] === '0' ||+ (date._mon.length === 2 && day.length === 2)+ );+ const format = date.path.replace(/[jdlDnmMFyYx]/g, (token) => {+ if (token === 'x') {+ return date.tf || '';+ }+ return (lead0 ? tx00[token] : tx0[token]) || token;+ });+ return { v: dateValue, z: format };+}++const normAMPMStr = (string: string): string =>+ string.replace(/\s+/g, '').trim().replace(/\./g, '').toLowerCase();++/** Parse a time string and return its day fraction and inferred format. */+// eslint-disable-next-line complexity+export function parseTime(value: string, options: ParseOptions = {}): ParseData<number> | null {+ const l10n = getLocale(options.locale || '') || defaultLocale;+ const parts = /^\s*([10]?\d|2[0-4])(?::([0-5]\d|\d))?(?::([0-5]\d|\d))?(\.\d{1,10})?(?=\s*[^\s\d]|$)/.exec(value);+ let ampm = '';+ if (parts) {+ const tail = normAMPMStr(value.slice(parts[0].length));+ if (tail === normAMPMStr(l10n.ampm[0]) || tail === 'a' || tail === 'am') {+ ampm = 'a';+ } else if (tail === normAMPMStr(l10n.ampm[1]) || tail === 'p' || tail === 'pm') {+ ampm = 'p';+ } else if (tail === ':') {+ if (!parts[3]) {+ parts[3] = '0';+ }+ if (!parts[2]) {+ parts[2] = '0';+ }+ } else if (tail) {+ return null;+ }+ }+ if (!parts) {+ return null;+ }++ const [, hoursPart, minutesPart, secondsPart, fractionPart] = parts;+ if (fractionPart && !secondsPart) {+ return null;+ }+ if (!ampm && !minutesPart && !secondsPart) {+ return null;+ }++ let hours = +(hoursPart || 0);+ if (ampm) {+ if (hours >= 13) {+ return null;+ }+ if (ampm === 'a') {+ if (hours === 12) {+ hours = 0;+ }+ } else if (ampm === 'p' && hours !== 12) {+ hours += 12;+ }+ }+ const minutes = +(minutesPart || 0);+ const seconds = +(secondsPart || 0);+ const milliseconds = +(fractionPart || 0);++ const hourFormat = hoursPart.length === 2 ? 'hh' : 'h';+ const secondsFormat = secondsPart ? ':ss' : '';+ const ampmFormat = ampm ? ' AM/PM' : '';+ return {+ v: ((hours * 60 * 60) + (minutes * 60) + seconds + milliseconds) / (60 * 60 * 24),+ z: `${hourFormat}:mm${secondsFormat}${ampmFormat}`,+ };+}++/** Parse a localized or English boolean string. */+export function parseBool(value: string, options: ParseOptions = {}): ParseData<boolean> | null {+ const l10n: LocaleData = getLocale(options.locale || '') || defaultLocale;+ const normalizedValue = value.trim().toLowerCase();+ const localizedTrue = l10n.bool[0].toLowerCase();+ if (normalizedValue === 'true' || normalizedValue === localizedTrue) {+ return { v: true };+ }+ const localizedFalse = l10n.bool[1].toLowerCase();+ if (normalizedValue === 'false' || normalizedValue === localizedFalse) {+ return { v: false };+ }+ return null;+}++/** Parse a spreadsheet input as a number, date, time, or boolean. */+export function parseValue(value: string, options?: ParseOptions): ParseData | null {+ return (+ parseNumber(value, options) ??+ parseDate(value, options) ??+ parseTime(value, options) ??+ parseBool(value, options)+ );+}diff --git a/packages/core/src/shared/numfmt/round.ts b/packages/core/src/shared/numfmt/round.tsnew file mode 100644index 0000000000..2f3cf22481--- /dev/null+++ b/packages/core/src/shared/numfmt/round.ts@@ -0,0 +1,62 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import { decimalFromNumber, decimalPartsToNumber, roundDecimal } from './decimal';++function legacyRound(number: number, places = 0): number {+ if (number < 0) {+ return -legacyRound(-number, places);+ }+ if (places) {+ const power = 10 ** places || 1;+ return legacyRound(number * power, 0) / power;+ }+ return Math.round(number);+}++/**+ * Return a number rounded to the specified amount of places. This is the+ * rounding function used internally by the formatter (symmetric arithmetic+ * rounding).+ *+ * @param {number} number - The number to round.+ * @param {number} [places] - The number of decimals to round to.+ * @returns {number} A rounded number.+ */+export function round(number: number, places?: number): number;+export function round(number: unknown, places?: number): unknown;+export function round(number: unknown, places = 0): unknown {+ if (typeof number !== 'number') {+ return number;+ }+ if (!Number.isFinite(number) || number === 0) {+ return number === 0 ? 0 : number;+ }+ if (!Number.isFinite(places)) {+ return legacyRound(number, places);+ }++ const normalizedPlaces = Math.trunc(places);+ if ((Number.isInteger(number) && normalizedPlaces >= 0) || normalizedPlaces > 324) {+ return number;+ }++ const rounded = decimalPartsToNumber(roundDecimal(decimalFromNumber(number), normalizedPlaces));+ return Number.isFinite(rounded) ? rounded : number;+}diff --git a/packages/core/src/shared/numfmt/run-part.ts b/packages/core/src/shared/numfmt/run-part.tsnew file mode 100644index 0000000000..84da0c7ed8--- /dev/null+++ b/packages/core/src/shared/numfmt/run-part.ts@@ -0,0 +1,573 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { IDecimalValue, IRoundedDecimalParts } from './decimal';+import type {+ ErrorFormatSection,+ FormatSection,+ LocaleData,+ ParsedFormatSection,+ ResolvedFormatOptions,+} from './types';+import { clamp } from './clamp';+import {+ EPOCH_1317,+ MAX_L_DATE,+ MAX_S_DATE,+ MIN_L_DATE,+ MIN_S_DATE,+ u_CSEC,+ u_DSEC,+ u_MSEC,+} from './constants';+import { dec2frac } from './dec-to-frac';+import { decimalFromNumber, roundDecimal, roundScientificDecimal, shiftDecimal } from './decimal';+import { general } from './general';+import { defaultLocale } from './locale';+import { getExponent, getSignificand } from './number-props';+import { pad } from './pad';+import { toYMD } from './to-ymd';++const DAYSIZE = 86400;++type RuntimeFormatSection = ParsedFormatSection & Partial<ErrorFormatSection>;++function dateOverflows(inputValue: number, roundedValue: number, bigRange: boolean): boolean {+ if (bigRange) {+ return inputValue < MIN_L_DATE || roundedValue >= MAX_L_DATE;+ }+ return inputValue < MIN_S_DATE || roundedValue >= MAX_S_DATE;+}++function legacyRound(number: number, places = 0): number {+ if (number < 0) {+ return -legacyRound(-number, places);+ }+ if (places) {+ const power = 10 ** places || 1;+ return legacyRound(number * power, 0) / power;+ }+ return Math.round(number);+}++// eslint-disable-next-line max-lines-per-function, complexity+export function runPart(+ value: unknown,+ part: FormatSection,+ options: ResolvedFormatOptions,+ locale?: LocaleData | null,+ decimalValue: IDecimalValue | null = null+): string {+ // Error sections intentionally contain only tokens and an error. The+ // upstream renderer treats every other property as undefined until the+ // error token is emitted, so keep that duck-typed runtime contract local.+ const section = part as RuntimeFormatSection;+ let renderValue = value;+ let numericValue = value as number;+ let mantissa = '';+ let mantissaSign = '';+ let numerator = '';+ let denominator = '';+ let fraction = '';+ let integer = '';+ let exponent = 0;+ let roundedNumber: IRoundedDecimalParts | null = null;++ let date = 0;+ if (typeof renderValue === 'bigint') {+ if (renderValue <= Number.MAX_SAFE_INTEGER && renderValue >= Number.MIN_SAFE_INTEGER) {+ numericValue = Number(renderValue);+ renderValue = numericValue;+ } else {+ return options.bigintErrorNumber+ ? String(renderValue)+ : options.overflow;+ }+ date = numericValue;+ } else {+ date = Math.trunc(numericValue);+ }+ let time = 0;+ let year = 0;+ let month = 1;+ let day = 0;+ let weekday = 0;+ let hour = 0;+ let minute = 0;+ let second = 0;+ let subsec = 0;++ const l10n = locale || defaultLocale;++ let decimal = decimalValue;+ if (!decimal && typeof value === 'number' && Number.isFinite(value)) {+ decimal = decimalFromNumber(value);+ }+ if (decimal && !section.text && section.scaleExponent) {+ decimal = shiftDecimal(decimal, section.scaleExponent);+ }++ // scale number+ if (!section.text && Number.isFinite(section.scale) && section.scale !== 1) {+ numericValue = clamp(numericValue * section.scale);+ renderValue = numericValue;+ }++ // calc exponent+ // Below exponent -308, preserve numfmt's shortest-exponential path for+ // subnormal compatibility. Exponent -308 itself remains canonical.+ if (section.exponential && decimal && decimal.exponent >= -308) {+ const scientific = roundScientificDecimal(+ decimal,+ section.int_max,+ Boolean(section.integer),+ section.frac_max+ );+ exponent = scientific.exponent;+ roundedNumber = scientific.rounded;+ mantissa += Math.abs(exponent);+ } else if (section.exponential) {+ let significand = Math.abs(numericValue);+ if (significand) {+ exponent = getExponent(significand, section.int_max);+ }+ if (numericValue && !section.integer) {+ // when there isn't an integer part, the exp gets shifted by 1+ exponent++;+ }+ significand = getSignificand(significand, exponent);+ if (section.int_max === 1 && legacyRound(significand, section.frac_max) === 10) {+ significand = 1;+ exponent++;+ }+ numericValue = numericValue < 0 ? -significand : significand;+ renderValue = numericValue;+ mantissa += Math.abs(exponent);+ }++ const requiresDecimalRounding = !Number.isSafeInteger(numericValue) || Boolean(section.scaleExponent);+ roundedNumber = roundedNumber || (decimal &&+ requiresDecimalRounding &&+ !section.date &&+ !section.fractions &&+ !section.exponential &&+ (section.integer || section.dec_fractions)+ ? roundDecimal(decimal, section.frac_max)+ : null);++ // integer to text+ if (section.integer) {+ if (roundedNumber) {+ integer = roundedNumber.integer === '0' ? '' : roundedNumber.integer;+ } else {+ const places = section.fractions ? 1 : section.frac_max;+ const roundedInteger = Math.abs(Number.isSafeInteger(numericValue) && places === 0+ ? numericValue+ : legacyRound(numericValue, places));+ integer += roundedInteger < 1 ? '' : Math.floor(roundedInteger);+ }+ }+ // integer grouping+ const primaryGroup = options.grouping[0] ?? 3;+ const secondaryGroup = options.grouping[1] ?? primaryGroup;++ // fraction to text+ if (section.dec_fractions) {+ fraction = roundedNumber+ ? roundedNumber.fraction+ : String(legacyRound(numericValue, section.frac_max)).split('.')[1] || '';+ }++ // using vulgar fractions+ const fixedSlash = !section.error && (section.num_p.includes('0') || section.den_p.includes('0'));++ let haveFraction = fixedSlash;+ if (section.fractions) {+ haveFraction = fixedSlash || !!(numericValue % 1);+ const decimal = Math.abs(section.integer ? numericValue % 1 : numericValue);+ if (decimal) {+ haveFraction = true;+ if (section.denominator && Number.isFinite(section.denominator)) {+ // predefined denominator+ denominator += section.denominator;+ numerator += legacyRound(decimal * section.denominator);+ if (numerator === '0') {+ numerator = '';+ denominator = '';+ haveFraction = fixedSlash;+ }+ } else {+ const fractionParts = dec2frac(decimal, Infinity, section.den_max);+ numerator += fractionParts[0];+ denominator += fractionParts[1];+ if (section.integer && numerator === '0') {+ numerator = '';+ denominator = '';+ haveFraction = fixedSlash;+ }+ }+ } else if (!numericValue && !section.integer) {+ haveFraction = true;+ numerator = '0';+ denominator = '1';+ }+ if (section.integer && !haveFraction && !Math.trunc(numericValue)) {+ integer = '0';+ }+ }++ // using date/time+ if (section.date) {+ date = Math.trunc(numericValue);+ const rawTime = DAYSIZE * (numericValue - date);+ time = Math.floor(rawTime); // in seconds+ // "epsilon" correction+ subsec = rawTime - time;+ if (Math.abs(subsec) < 1e-6) { // 0.000001+ subsec = 0;+ } else if (subsec > 0.9999) {+ subsec = 0;+ time += 1;+ if (time === DAYSIZE) {+ time = 0;+ date += 1;+ }+ }+ if (subsec) {+ // round time based on smallest used unit+ const minimumUnit = section.date & u_MSEC || section.date & u_CSEC || section.date & u_DSEC;+ if (+ (minimumUnit === u_MSEC && subsec > 0.9995) ||+ (minimumUnit === u_CSEC && subsec > 0.995) ||+ (minimumUnit === u_DSEC && subsec > 0.95) ||+ (!minimumUnit && subsec >= 0.5)+ ) {+ time++;+ subsec = 0;+ }+ }+ // serial date/time to gregorian calendar+ if (date || section.date_system) {+ const dateOutput = toYMD(numericValue, section.date_system, options.leap1900);+ year = dateOutput[0];+ month = dateOutput[1];+ day = dateOutput[2];+ }+ if (time) {+ const normalizedTime = time < 0 ? DAYSIZE + time : time;+ second = Math.floor(normalizedTime) % 60;+ minute = Math.floor(normalizedTime / 60) % 60;+ hour = Math.floor((normalizedTime / 60) / 60) % 60;+ }+ weekday = (6 + date) % 7;+ if (+ section.date_eval &&+ dateOverflows(numericValue, date + (time / DAYSIZE), options.dateSpanLarge)+ ) {+ // if value is out of bounds and formatting is date Excel emits a+ // stream of "######" that fills the cell width.+ // This doesn't happen, if the only date tokens are "elapsed time" tokens.+ // Code instead follows the TEXT function which emits a #VALUE! error.+ if (options.dateErrorThrows) {+ throw new Error('Date out of bounds');+ }+ if (options.dateErrorNumber) {+ const output: Array<string | number> = numericValue < 0 ? [l10n.negative] : [];+ return general(output, {}, numericValue, l10n, decimal).join('');+ }+ return options.overflow;+ }+ }++ const questionPadding = pad('?', options.nbsp);++ // mantissa sign+ if (exponent < 0) {+ mantissaSign = '-';+ } else if (section.exp_plus) {+ mantissaSign = '+';+ }++ const output: unknown[] = [];++ const digitsStart = (numberString: string, pattern: string, tokenPattern: string, offset: number): number => {+ let normalizedOffset = offset;+ const length = !normalizedOffset && numberString.length > pattern.length+ ? tokenPattern.length + numberString.length - pattern.length+ : tokenPattern.length;+ if (numberString.length < pattern.length) {+ normalizedOffset += numberString.length - pattern.length;+ }+ for (let index = 0; index < length; index++) {+ output.push(numberString[index + normalizedOffset] || pad(tokenPattern[index], options.nbsp));+ }+ return length;+ };++ let denominatorFixed = false;+ const counter = { int: 0, frac: 0, man: 0, num: 0, den: 0 };+ for (let tokenIndex = 0, tokenLength = section.tokens.length; tokenIndex < tokenLength; tokenIndex++) {+ const token = section.tokens[tokenIndex];+ const tokenType = token.type;+ const length = token.num ? token.num.length : 0;++ if (tokenType === 'string') {+ const tokenValue = token.value as string;+ // special rules may apply if next or prev is numerator or denominator+ if (token.rule) {+ if (token.rule === 'num') {+ if (haveFraction) {+ output.push(tokenValue.replace(/ /g, questionPadding));+ } else if (section.num_min > 0 || section.den_min > 0) {+ // FIXME: output.push(''.repeat(tokenValue.length))+ output.push(tokenValue.replace(/./g, questionPadding));+ }+ } else if (token.rule === 'num+int') {+ if (haveFraction && integer) {+ output.push(tokenValue.replace(/ /g, questionPadding));+ } else if ((section.den_min > 0) && (integer || section.num_min)) {+ output.push(tokenValue.replace(/./g, questionPadding));+ }+ } else if (token.rule === 'den') {+ if (haveFraction) {+ output.push(tokenValue.replace(/ /g, questionPadding));+ } else if (section.den_min > 0) {+ output.push(tokenValue.replace(/./g, questionPadding));+ }+ }+ } else {+ output.push(tokenValue.replace(/ /g, questionPadding));+ }+ } else if (tokenType === 'space') {+ if (token.rule === 'num+int') {+ if (+ (haveFraction || section.num_min || section.den_min) &&+ (integer || section.num_min)+ ) {+ output.push(questionPadding);+ }+ } else {+ output.push(questionPadding);+ }+ } else if (tokenType === 'error') {+ // token used to define invalid pattern+ output.push(options.invalid);+ } else if (tokenType === 'point') {+ // Excel always emits a period: TEXT(0, "#.#") => "."+ output.push(section.date ? token.value : l10n.decimal);+ } else if (tokenType === 'general') {+ general(output as Array<string | number>, section, renderValue as number | string, l10n, decimal);+ } else if (tokenType === 'exp') {+ output.push(l10n.exponent);+ } else if (tokenType === 'minus') {+ if (token.volatile && section.date) {+ // don't emit the prepended minus if this is a date+ } else if (token.volatile && roundedNumber) {+ if (roundedNumber.negative && !roundedNumber.zero) {+ output.push(l10n.negative);+ }+ } else if (token.volatile && (numericValue >= 0 || typeof renderValue !== 'number')) {+ // don't emit volatile minus for positive numbers+ } else if (token.volatile && !section.fractions && (section.integer || section.dec_fractions)) {+ // minus is only shown if there is a non-zero digit present+ if ((numericValue < 0 && !!integer && integer !== '0') || fraction) {+ output.push(l10n.negative);+ }+ } else {+ output.push(l10n.negative);+ }+ } else if (tokenType === 'plus') {+ output.push(l10n.positive);+ } else if (tokenType === 'text') {+ output.push(renderValue);+ } else if (tokenType === 'fill') {+ // If user has provided a token to signal that next char is a fill char,+ // then emit that plus the fill char. By default this does what the+ // TEXT function does in this case: Emits nothing.+ if (options.fillChar) {+ output.push(options.fillChar, token.value);+ }+ } else if (tokenType === 'skip') {+ // If user has provided a token to signal that next char is a fill char,+ // then emit that plus the fill char. By default this does what the+ // TEXT function does in this case: Emits a space.+ if (options.skipChar) {+ output.push(options.skipChar, token.value);+ } else {+ output.push(options.nbsp ? '\u00A0' : ' ');+ }+ } else if (tokenType === 'div') {+ if (haveFraction) {+ output.push('/');+ } else if (section.num_min > 0 || section.den_min > 0) {+ output.push(questionPadding);+ } else {+ output.push(pad('#', options.nbsp));+ }+ } else if (tokenType === 'int') {+ // number isn't fragmented+ if (section.int_pattern.length === 1) {+ const pattern = section.int_p;+ const length = Math.max(section.int_min, integer.length);+ let digits = '';+ for (let index = length; index > 0; index--) {+ const digit = integer.charAt(integer.length - index);+ const patternDigit = digit ? '' : pattern.charAt(pattern.length - index) || pattern[0];+ let separator = '';+ if (section.grouping) {+ const groupIndex = (index - 1) - primaryGroup;+ if (groupIndex >= 0 && !(groupIndex % secondaryGroup)) {+ separator = digit || patternDigit === '0'+ ? l10n.group+ : pad('?', options.nbsp);+ }+ }+ digits += (digit || pad(patternDigit, options.nbsp)) + separator;+ }+ output.push(digits);+ } else {+ counter.int += digitsStart(integer, section.int_p, token.num!, counter.int);+ }+ } else if (tokenType === 'frac') {+ const offset = counter.frac;+ for (let index = 0; index < length; index++) {+ output.push(fraction[index + offset] || pad(token.num![index], options.nbsp));+ }+ counter.frac += length;+ } else if (tokenType === 'man') {+ // mantissa sign is attached to the first digit, not the exponent symbol+ // "0E+ 0" will print as "1E +12"+ if (!counter[tokenType] && !counter.man) {+ output.push(mantissaSign);+ }+ counter.man += digitsStart(mantissa, section.man_p, token.num!, counter.man);+ } else if (tokenType === 'num') {+ counter.num += digitsStart(numerator, section.num_p, token.num!, counter.num);+ } else if (tokenType === 'den') {+ const offset = counter.den;+ for (let index = 0; index < length; index++) {+ let digit = denominator[index + offset];+ if (!digit) {+ const char = token.num![index];+ if (+ '123456789'.includes(char) ||+ (denominatorFixed && char === '0')+ ) {+ denominatorFixed = true;+ digit = options.nbsp ? '\u00A0' : ' ';+ } else if (+ !denominatorFixed &&+ index === length - 1 &&+ char === '0' &&+ !denominator+ ) {+ digit = '1';+ } else {+ digit = pad(char, options.nbsp);+ }+ }+ output.push(digit);+ }+ counter.den += length;+ } else if (tokenType === 'year') {+ if (year < 0) {+ output.push(l10n.negative);+ }+ output.push(String(Math.abs(year)).padStart(4, '0'));+ } else if (tokenType === 'year-short') {+ const shortYear = year % 100;+ output.push(shortYear < 10 ? '0' : '', shortYear);+ } else if (tokenType === 'month') {+ output.push(token.pad && month < 10 ? '0' : '', month);+ } else if (tokenType === 'monthname-single') {+ // This is what Excel does.+ // The Vietnamese list goes:+ // from ["Tháng 1", "Tháng 2", ... ] to [ "T", "T", ... ]+ // Simplified Chinese goes:+ // from [ 1月, ... 9月, 10月, 11月, 12月 ] to [ 1, ... 9, 1, 1, 1 ]+ if (section.date_system === EPOCH_1317) {+ output.push(l10n.mmmm6[month - 1].charAt(0));+ } else {+ output.push(l10n.mmmm[month - 1].charAt(0));+ }+ } else if (tokenType === 'monthname-short') {+ if (section.date_system === EPOCH_1317) {+ output.push(l10n.mmm6[month - 1]);+ } else {+ output.push(l10n.mmm[month - 1]);+ }+ } else if (tokenType === 'monthname') {+ if (section.date_system === EPOCH_1317) {+ output.push(l10n.mmmm6[month - 1]);+ } else {+ output.push(l10n.mmmm[month - 1]);+ }+ } else if (token.type === 'weekday-short') {+ output.push(l10n.ddd[weekday]);+ } else if (tokenType === 'weekday') {+ output.push(l10n.dddd[weekday]);+ } else if (tokenType === 'day') {+ output.push(token.pad && day < 10 ? '0' : '', day);+ } else if (tokenType === 'hour') {+ const displayHour = hour % section.clock || (section.clock < 24 ? section.clock : 0);+ output.push(token.pad && displayHour < 10 ? '0' : '', displayHour);+ } else if (tokenType === 'min') {+ output.push(token.pad && minute < 10 ? '0' : '', minute);+ } else if (tokenType === 'sec') {+ output.push(token.pad && second < 10 ? '0' : '', second);+ } else if (tokenType === 'subsec') {+ output.push(l10n.decimal);+ // decimals is pre-determined by longest subsec token+ // but the number emitted is per-token+ const formattedSubseconds = subsec.toFixed(section.sec_decimals);+ output.push(formattedSubseconds.slice(2, 2 + token.decimals!));+ } else if (tokenType === 'ampm') {+ const index = hour < 12 ? 0 : 1;+ if (token.short && !locale) {+ output.push('AP'[index]);+ } else {+ output.push(l10n.ampm[index]);+ }+ } else if (tokenType === 'hour-elap') {+ if (numericValue < 0) {+ output.push(l10n.negative);+ }+ const elapsedHours = (date * 24) + Math.floor(Math.abs(time) / (60 * 60));+ output.push(String(Math.abs(elapsedHours)).padStart(token.pad as number, '0'));+ } else if (tokenType === 'min-elap') {+ if (numericValue < 0) {+ output.push(l10n.negative);+ }+ const elapsedMinutes = (date * 1440) + Math.floor(Math.abs(time) / 60);+ output.push(String(Math.abs(elapsedMinutes)).padStart(token.pad as number, '0'));+ } else if (tokenType === 'sec-elap') {+ if (numericValue < 0) {+ output.push(l10n.negative);+ }+ const elapsedSeconds = (date * DAYSIZE) + Math.abs(time);+ output.push(String(Math.abs(elapsedSeconds)).padStart(token.pad as number, '0'));+ } else if (tokenType === 'b-year') {+ output.push(year + 543);+ } else if (tokenType === 'b-year-short') {+ const shortYear = (year + 543) % 100;+ output.push(shortYear < 10 ? '0' : '', shortYear);+ }+ }+ return output.join('');+}diff --git a/packages/core/src/shared/numfmt/serial-date.ts b/packages/core/src/shared/numfmt/serial-date.tsnew file mode 100644index 0000000000..c210a7581a--- /dev/null+++ b/packages/core/src/shared/numfmt/serial-date.ts@@ -0,0 +1,99 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { DateTimeParts } from './types';+import { toYMD } from './to-ymd';++const floor = Math.floor;+const DAYSIZE = 86400;+const dateUTC = Date.UTC as (...values: unknown[]) => number;++/**+ * Convert a native JavaScript Date, or array to a spreadsheet serial date.+ *+ * Returns a serial date number if input was a Date object or an array of+ * numbers, or null.+ */+export function dateToSerial(+ date: unknown,+ options?: { ignoreTimezone?: boolean }+): number | null {+ let timestamp: number | null = null;+ if (Array.isArray(date)) {+ const [year, month, day, hours, minutes, seconds] = date;+ timestamp = dateUTC(+ year,+ month == null ? 0 : month - 1,+ day ?? 1,+ hours || 0,+ minutes || 0,+ seconds || 0+ );+ } else if (date instanceof Date) {+ timestamp = date.getTime();+ if (!options?.ignoreTimezone) {+ // Many timezones are offset in seconds but getTimezoneOffset() returns+ // time "rounded" to minutes, so reconstruct the local components in UTC.+ const localDate = new Date();+ localDate.setUTCFullYear(+ date.getFullYear(),+ date.getMonth(),+ date.getDate()+ );+ localDate.setUTCHours(+ date.getHours(),+ date.getMinutes(),+ date.getSeconds(),+ date.getMilliseconds()+ );+ timestamp = localDate.getTime();+ }+ }+ if (timestamp != null && Number.isFinite(timestamp)) {+ const days = timestamp / 864e5;+ return days - (days <= -25509 ? -25568 : -25569);+ }+ return null;+}++/**+ * Convert a spreadsheet serial date to an array of date parts, accurate to a+ * second.+ */+export function dateFromSerial(+ serial: number,+ options?: { leap1900?: boolean }+): DateTimeParts {+ let date = serial | 0;+ const fractionalSeconds = DAYSIZE * (serial - date);+ let time = floor(fractionalSeconds);+ if ((fractionalSeconds - time) > 0.9999) {+ time += 1;+ if (time === DAYSIZE) {+ time = 0;+ date += 1;+ }+ }+ const normalizedTime = time < 0 ? DAYSIZE + time : time;+ const [year, month, day] = toYMD(serial, 0, options?.leap1900);+ const hours = floor((normalizedTime / 60) / 60) % 60;+ const minutes = floor(normalizedTime / 60) % 60;+ const seconds = floor(normalizedTime) % 60;+ return [year, month, day, hours, minutes, seconds];+}diff --git a/packages/core/src/shared/numfmt/to-ymd.ts b/packages/core/src/shared/numfmt/to-ymd.tsnew file mode 100644index 0000000000..3dd0773a1b--- /dev/null+++ b/packages/core/src/shared/numfmt/to-ymd.ts@@ -0,0 +1,92 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { DateParts } from './types';+import { EPOCH_1317, EPOCH_1904 } from './constants';++const floor = Math.floor;++// https://www.codeproject.com/Articles/2750/Excel-Serial-Date-to-Day-Month-Year-and-Vice-Versa+export function toYMD1900(serial: number, leap1900: boolean = true): DateParts {+ if (leap1900 && serial >= 0) {+ if (serial === 0) {+ return [1900, 1, 0];+ }+ if (serial === 60) {+ return [1900, 2, 29];+ }+ if (serial < 60) {+ return [1900, serial < 32 ? 1 : 2, ((serial - 1) % 31) + 1];+ }+ }+ let l = serial + 68569 + 2415019;+ const n = floor((4 * l) / 146097);+ l -= floor((146097 * n + 3) / 4);+ const i = floor((4000 * (l + 1)) / 1461001);+ l = l - floor((1461 * i) / 4) + 31;+ const j = floor((80 * l) / 2447);+ const nDay = l - floor((2447 * j) / 80);+ l = floor(j / 11);+ const nMonth = j + 2 - (12 * l);+ const nYear = 100 * (n - 49) + i + l;+ return [nYear | 0, nMonth | 0, nDay | 0];+}++export function toYMD1904(serial: number): DateParts {+ return toYMD1900(serial + 1462);+}++// https://web.archive.org/web/20080209173858/https://www.microsoft.com/globaldev/DrIntl/columns/002/default.mspx+// > [algorithm] is used in many Microsoft products, including all+// > operating systems that support Arabic locales, Microsoft Office,+// > COM, Visual Basic, VBA, and SQL Server 2000.+export function toYMD1317(serial: number): DateParts {+ if (serial === 60) {+ throw new Error('#VALUE!');+ }+ if (serial <= 1) {+ return [1317, 8, 29];+ }+ if (serial < 60) {+ return [1317, serial < 32 ? 9 : 10, 1 + ((serial - 2) % 30)];+ }+ const y = 10631 / 30;+ const shift1 = 8.01 / 60;+ let z = serial + 466935;+ const cyc = floor(z / 10631);+ z -= 10631 * cyc;+ const j = floor((z - shift1) / y);+ z -= floor(j * y + shift1);+ const m = floor((z + 28.5001) / 29.5);+ if (m === 13) {+ return [30 * cyc + j, 12, 30];+ }+ return [30 * cyc + j, m, z - floor(29.5001 * m - 29)];+}++export function toYMD(serial: number, system: number = 0, leap1900: boolean = true): DateParts {+ const int = floor(serial);+ if (system === EPOCH_1317) {+ return toYMD1317(int);+ }+ if (system === EPOCH_1904) {+ return toYMD1904(int);+ }+ return toYMD1900(int, leap1900);+}diff --git a/packages/core/src/shared/numfmt/tokenize.ts b/packages/core/src/shared/numfmt/tokenize.tsnew file mode 100644index 0000000000..477eebc997--- /dev/null+++ b/packages/core/src/shared/numfmt/tokenize.ts@@ -0,0 +1,195 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++import type { FormatToken } from './types';+import {+ TOKEN_AMPM,+ TOKEN_BREAK,+ TOKEN_CALENDAR,+ TOKEN_CHAR,+ TOKEN_COLOR,+ TOKEN_COMMA,+ TOKEN_CONDITION,+ TOKEN_DATETIME,+ TOKEN_DBNUM,+ TOKEN_DIGIT,+ TOKEN_DURATION,+ TOKEN_ERROR,+ TOKEN_ESCAPED,+ TOKEN_EXP,+ TOKEN_FILL,+ TOKEN_GENERAL,+ TOKEN_GROUP,+ TOKEN_HASH,+ TOKEN_LOCALE,+ TOKEN_MINUS,+ TOKEN_MODIFIER,+ TOKEN_NATNUM,+ TOKEN_PAREN,+ TOKEN_PERCENT,+ TOKEN_PLUS,+ TOKEN_POINT,+ TOKEN_QMARK,+ TOKEN_SCALE,+ TOKEN_SKIP,+ TOKEN_SLASH,+ TOKEN_SPACE,+ TOKEN_STRING,+ TOKEN_TEXT,+ TOKEN_ZERO,+} from './constants';++type TokenGroup = number | readonly number[];+type TokenHandler = readonly [type: string, expression: RegExp, group: TokenGroup];++const tokenHandlers: readonly TokenHandler[] = [+ [TOKEN_GENERAL, /^General/i, 0],+ [TOKEN_HASH, /^#/, 0],+ [TOKEN_ZERO, /^0/, 0],+ [TOKEN_QMARK, /^\?/, 0],+ [TOKEN_SLASH, /^\//, 0],+ // Commas are dealt with as a special case in the tokenizer but will end up+ // as one of these:+ // [ TOKEN_GROUP, /^(,),*/, 1 ],+ // [ TOKEN_SCALE, /^(,),*/, 1 ],+ // [ TOKEN_COMMA, /^(,),*/, 1 ],+ [TOKEN_BREAK, /^;/, 0],+ [TOKEN_TEXT, /^@/, 0],+ [TOKEN_PLUS, /^\+/, 0],+ [TOKEN_MINUS, /^-/, 0],+ [TOKEN_POINT, /^\./, 0],+ [TOKEN_SPACE, /^ /, 0],+ [TOKEN_PERCENT, /^%/, 0],+ [TOKEN_DIGIT, /^[1-9]/, 0],+ [TOKEN_CALENDAR, /^(?:B[12])/i, 0],+ [TOKEN_ERROR, /^B$/, 0], // pattern must not end in a "B"+ [TOKEN_DATETIME, /^(?:[hH]+|[mM]+|[sS]+|[yY]+|[bB]+|[dD]+|[gG]+|[aA]{3,}|e+)/, 0],+ [TOKEN_DURATION, /^(?:\[(h+|m+|s+)\])/i, 1],+ [TOKEN_CONDITION, /^\[(<[=>]?|>=?|=)\s*(-?[.\d]+)\]/, [1, 2]],+ [TOKEN_DBNUM, /^\[(DBNum[0-4]?\d)\]/i, 1],+ [TOKEN_NATNUM, /^\[(NatNum[0-4]?\d)\]/i, 1],+ [TOKEN_LOCALE, /^\[\$([^\]]+)\]/, 1],+ [TOKEN_COLOR, /^\[(black|blue|cyan|green|magenta|red|white|yellow|color\s*\d+)\]/i, 1],+ // conditionally allow these open ended directions?+ [TOKEN_MODIFIER, /^\[([^\]]+)\]/, 1],+ [TOKEN_AMPM, /^(?:AM\/PM|am\/pm|A\/P)/, 0],+ [TOKEN_ESCAPED, /^\\(.)/, 1],+ [TOKEN_STRING, /^"([^"]*?)"/, 1],+ [TOKEN_SKIP, /^_(\\.|.)/, 1],+ // Google Sheets and Excel diverge on "e": Excel only accepts E.+ [TOKEN_EXP, /^[Ee]([+-])/, 1],+ [TOKEN_FILL, /^\*(\\.|.)/, 1],+ [TOKEN_PAREN, /^[()]/, 0],+ [TOKEN_ERROR, /^[EÈÉÊËèéêëĒēĔĕĖėĘęĚěȄȅȆȇȨȩNnÑñŃńŅņŇňǸǹ["*/\\_]/, 0],+ [TOKEN_CHAR, /^./, 0],+];++const CODE_QMRK = 63;+const CODE_HASH = 35;+const CODE_ZERO = 48;+const CODE_NINE = 57;+const isNumOp = (char: string | undefined): boolean => {+ const code = (char || '\0').charCodeAt(0);+ return code === CODE_QMRK || code === CODE_HASH || (code >= CODE_ZERO && code <= CODE_NINE);+};++/**+ * Breaks a format pattern string into a list of tokens.+ */+// eslint-disable-next-line complexity+export function tokenize(pattern: string): FormatToken[] {+ let index = 0;+ const tokens: FormatToken[] = [];+ const unresolvedCommas: FormatToken[] = [];+ while (index < pattern.length) {+ const current = pattern.slice(index);+ let step = 0;+ // A comma is context sensitive and needs to be handled as a special case.+ // This needs to happen in the tokenizer because to be able to re-localize+ // the pattern we'll need to know what each comma means.+ const commaMatch = /^(,+)(.)?/.exec(current);+ if (commaMatch) {+ // comma depends on what it follows+ const raw = commaMatch[1];+ step = raw.length;+ const lookBehind = pattern[index - 1] || '';+ let maybeGroup = false;+ let maybeScale = false;+ if (isNumOp(lookBehind)) { // 0-9, '#', or '?': may be GROUP or SCALE+ maybeGroup = true;+ maybeScale = true;+ } else if (lookBehind === '.') { // '.': may be SCALE only+ maybeScale = true;+ }+ // if at the end of the pattern or section, then this can't be a GROUP op+ const lookAhead = commaMatch[2] || '';+ if (maybeGroup && (!lookAhead || lookAhead === ';')) {+ maybeGroup = false;+ }+ // if next char is a num token, then this cannot be a SCALE op+ if (maybeScale && isNumOp(lookAhead)) {+ maybeScale = false;+ }+ if (maybeGroup && !maybeScale) {+ tokens.push({ type: TOKEN_GROUP, value: ',', raw });+ } else if (!maybeGroup && maybeScale) {+ tokens.push({ type: TOKEN_SCALE, value: ',', raw });+ } else if (maybeGroup && maybeScale) {+ // this token will be set to scale, but switched to group if we hit a+ // num token later on in the pattern...+ const token: FormatToken = { type: TOKEN_SCALE, value: ',', raw };+ tokens.push(token);+ unresolvedCommas.push(token);+ } else {+ tokens.push({ type: TOKEN_COMMA, value: ',', raw });+ }+ } else {+ // all other symbols are matched using token handlers+ let token: FormatToken | undefined;+ for (const [type, expression, group] of tokenHandlers) {+ const match = expression.exec(current);+ if (match) {+ const value = typeof group !== 'number'+ ? group.map((matchIndex) => match[matchIndex])+ : match[group || 0];+ token = { type, value, raw: match[0] };+ tokens.push(token);+ step = match[0].length;+ break;+ }+ }+ // if we just matched a break, then deal with any unresolved commas+ if (unresolvedCommas.length && token?.raw === ';') {+ unresolvedCommas.length = 0;+ }+ // if we just matched a num operator, then deal with any unresolved commas+ if (unresolvedCommas.length && isNumOp(token?.raw)) {+ unresolvedCommas.forEach((unresolved) => (unresolved.type = TOKEN_GROUP));+ unresolvedCommas.length = 0;+ }+ }+ if (!step) {+ const raw = current[0];+ step = 1;+ tokens.push({ type: TOKEN_CHAR, value: raw, raw });+ }+ index += step;+ }+ return tokens;+}diff --git a/packages/core/src/shared/numfmt/types.ts b/packages/core/src/shared/numfmt/types.tsnew file mode 100644index 0000000000..5b66c88b94--- /dev/null+++ b/packages/core/src/shared/numfmt/types.ts@@ -0,0 +1,226 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++// Derived from numfmt 3.2.6 (MIT), commit c2cfdfa01bb1f24df51e985825671eb480daed4c.+// See packages/core/src/shared/numfmt/LICENSE.++export type ConditionOperator = '<' | '<=' | '=' | '>=' | '>' | '<>';+export type FormatCondition = [ConditionOperator, number];++export interface LocaleToken {+ lang: string;+ language: string;+ territory: string;+}++export interface LocaleData {+ group: string;+ decimal: string;+ positive: string;+ negative: string;+ percent: string;+ exponent: string;+ nan: string;+ infinity: string;+ ampm: string[];+ mmmm6: string[];+ mmm6: string[];+ mmmm: string[];+ mmm: string[];+ dddd: string[];+ ddd: string[];+ bool: string[];+ preferMDY: boolean;+ isDefault?: boolean;+}++export type LocaleSettings = Partial<Omit<LocaleData, 'isDefault'>>;++export interface ParseData<T extends number | boolean = number | boolean> {+ v: T;+ z?: string;+}++export interface NumberDigits {+ total: number;+ digits?: number;+ sign: number;+ period: number;+ int: number;+ frac: number;+}++export interface FormatOptions {+ overflow?: string;+ dateErrorThrows?: boolean;+ dateErrorNumber?: boolean;+ bigintErrorNumber?: boolean;+ dateSpanLarge?: boolean;+ leap1900?: boolean;+ nbsp?: boolean;+ throws?: boolean;+ invalid?: string;+ locale?: string;+ ignoreTimezone?: boolean;+ grouping?: readonly [number, number?];+ indexColors?: boolean;+ skipChar?: string | boolean;+ fillChar?: string | boolean;+}++export interface ResolvedFormatOptions {+ overflow: string;+ dateErrorThrows: boolean;+ dateErrorNumber: boolean;+ bigintErrorNumber: boolean;+ dateSpanLarge: boolean;+ leap1900: boolean;+ nbsp: boolean;+ throws: boolean;+ invalid: string;+ locale: string;+ ignoreTimezone: boolean;+ grouping: readonly [number, number?];+ indexColors: boolean;+ skipChar: string | boolean;+ fillChar: string | boolean;+}++export interface FormatToken {+ raw: string;+ type: string;+ value: any;+ short?: boolean;+}++export interface RenderToken {+ type: string;+ raw?: string;+ value?: string | string[];+ num?: string;+ rule?: 'num' | 'num+int' | 'den';+ volatile?: boolean;+ plus?: boolean;+ size?: number;+ date?: 1;+ pad?: boolean | number;+ decimals?: number;+ short?: boolean;+}++export interface ParsedFormatSection {+ scale: number;+ scaleExponent: number;+ percent: boolean;+ text: boolean;+ date: number;+ date_eval: boolean;+ date_system: number;+ sec_decimals: number;+ general: boolean;+ clock: 12 | 24;+ int_pattern: string[];+ frac_pattern: string[];+ man_pattern: string[];+ den_pattern: string[];+ num_pattern: string[];+ tokens: RenderToken[];+ tokensUsed: number;+ pattern: string;+ int_max: number;+ int_min: number;+ frac_max: number;+ frac_min: number;+ man_max: number;+ man_min: number;+ num_max: number;+ num_min: number;+ den_max: number;+ den_min: number;+ int_p: string;+ man_p: string;+ num_p: string;+ den_p: string;+ integer: boolean;+ parens?: boolean;+ fractions?: boolean;+ grouping?: boolean;+ condition?: FormatCondition | null;+ locale?: string;+ color?: string | number;+ dec_fractions?: boolean;+ exponential?: boolean;+ exp_plus?: boolean;+ denominator?: number;+}++export interface ErrorFormatSection {+ tokens: RenderToken[];+ error: string;+}++export type FormatSection = ParsedFormatSection | ErrorFormatSection;++export interface ParsedPattern {+ pattern: string;+ partitions: Array<FormatSection | undefined>;+ locale?: string | null;+ error?: string;+ info?: FormatInfo;+ dateInfo?: FormatDateInfo;+}++export interface FormatDateInfo {+ year: boolean;+ month: boolean;+ day: boolean;+ hours: boolean;+ minutes: boolean;+ seconds: boolean;+ clockType: 12 | 24;+}++export type FormatInfoType =+ | 'currency'+ | 'date'+ | 'datetime'+ | 'error'+ | 'fraction'+ | 'general'+ | 'grouped'+ | 'number'+ | 'percent'+ | 'scientific'+ | 'text'+ | 'time';++export interface FormatInfo {+ type: FormatInfoType;+ isDate: boolean;+ isText: boolean;+ isPercent: boolean;+ maxDecimals: number;+ color: 0 | 1;+ parentheses: 0 | 1;+ grouped: 0 | 1;+ code: string;+ scale: number;+ level: number;+}++export type DateParts = [number, number, number];+export type DateTimeParts = [number, number, number, number, number, number];+export type FormatColor = string | number | null;diff --git a/packages/core/src/shared/numfmt.ts b/packages/core/src/shared/numfmt/utils.tssimilarity index 82%rename from packages/core/src/shared/numfmt.tsrename to packages/core/src/shared/numfmt/utils.tsindex aab77742f8..f2cab867fe 100644--- a/packages/core/src/shared/numfmt.ts+++ b/packages/core/src/shared/numfmt/utils.ts@@ -14,10 +14,9 @@* limitations under the License.*/-import * as numfmt from 'numfmt';-import { regexp } from '../common/regexp';--export * as numfmt from 'numfmt';+import type { ParseData } from './api';+import { regexp } from '../../common/regexp';+import { parseDate, parseNumber, parseTime, tokenize, tokenTypes } from './api';export const DEFAULT_TEXT_FORMAT = '@@@'; // Compatible with old dataexport const DEFAULT_TEXT_FORMAT_EXCEL = '@'; // The default text format in Excel, recommended@@ -72,37 +71,37 @@ export const isPatternEqualWithoutDecimal = (patternA: string, patternB: string)}const getStringWithoutDecimal = (pattern: string): string => {- const tokens = numfmt.tokenize(pattern);+ const tokens = tokenize(pattern);let result = '';let isDecimalPart = false;let isColorBefore = false;for (const token of tokens) {- if (token.type === numfmt.tokenTypes.POINT) {+ if (token.type === tokenTypes.POINT) {isDecimalPart = true; // Start ignoring tokens after the decimal pointcontinue;}// for the excel number// this if should be before the color token check- if (isColorBefore && token.type === numfmt.tokenTypes.MINUS) {+ if (isColorBefore && token.type === tokenTypes.MINUS) {// ignore the minus token in the decimal part after the color tokencontinue;}- if (token.type === numfmt.tokenTypes.SKIP) {+ if (token.type === tokenTypes.SKIP) {// Skip tokens that are not relevant to the string representationcontinue;}- if (token.type === numfmt.tokenTypes.COLOR) {+ if (token.type === tokenTypes.COLOR) {isColorBefore = true; // If we are in the decimal part, we ignore the color tokenscontinue;} else {isColorBefore = false; // Reset after processing the color part}- if (isDecimalPart && token.type === numfmt.tokenTypes.ZERO) {+ if (isDecimalPart && token.type === tokenTypes.ZERO) {// If we are in the decimal part, we ignore the number tokenscontinue;} else {@@ -125,15 +124,49 @@ export const isPatternEqualWithoutDecimal = (patternA: string, patternB: string)const ignoreCommonPatterns = new Set(['m d']);const ignoreAMPMPatterns = new Set(['h:mm AM/PM', 'hh:mm AM/PM']);-export const currencySymbols = ['Rp', 'zł', 'NT$', 'R$', 'HK$', '$', '£', '¥', '¤', '֏', '؋', '৳', '฿', '៛', '₡', '₦', '₩', '₪', '₫', '€', '₭', '₮', '₱', '₲', '₴', '₸', '₹', '₺', '₼', '₽', '₾', '₿', '﷼'];+export const currencySymbols = [+ 'Rp',+ 'zł',+ 'NT$',+ 'R$',+ 'HK$',+ '$',+ '£',+ '¥',+ '¤',+ '֏',+ '؋',+ '৳',+ '฿',+ '៛',+ '₡',+ '₦',+ '₩',+ '₪',+ '₫',+ '€',+ '₭',+ '₮',+ '₱',+ '₲',+ '₴',+ '₸',+ '₹',+ '₺',+ '₼',+ '₽',+ '₾',+ '₿',+ '﷼',+];const CURRENCY_SYMBOL_PREFIX_REG = new RegExp(`^${regexp.charset(...Array.from(new Set(currencySymbols.join(''))))}+`);/*** Get the numfmt parse value, and filter out the parse error.*/-export const getNumfmtParseValueFilter = (value: string): numfmt.ParseData | null => {- const parseData = numfmt.parseDate(value) ?? numfmt.parseTime(value) ?? numfmt.parseNumber(value);+export const getNumfmtParseValueFilter = (value: string): ParseData | null => {+ const parseData = parseDate(value) ?? parseTime(value) ?? parseNumber(value);if (!parseData) return null;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 2764f10b78..5bc92a856a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -795,9 +795,6 @@ importers:lodash-es:specifier: ^4.18.1version: 4.18.1- numfmt:- specifier: 3.2.6- version: 3.2.6ot-json1:specifier: ^1.0.2version: 1.0.2@@ -9603,9 +9600,6 @@ packages:resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==}- resolution: {integrity: sha512-MXc2KP3j+2usdHTY5/ENUc2S+3BRF/cJqnR6RHeq6LBqKoIZOAQ62DQw974nnaZOencbfkmkTPyTmMnlkCpjzg==}-resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}engines: {node: '>=0.10.0'}@@ -17694,8 +17688,6 @@ snapshots:dependencies:boolbase: 1.0.0- [email protected]: {}-