@jsb188/mday 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +58 -23
- package/src/constants/agentMemory.ts +14 -45
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +156 -47
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +12 -38
- package/src/constants/dataTableFieldTypes.generated.ts +3 -7
- package/src/constants/docAccess.ts +3 -2
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +114 -12
- package/src/constants/fieldDoc.ts +74 -4
- package/src/constants/graphqlReactivity.ts +108 -25
- package/src/constants/log.ts +9 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +1834 -730
- package/src/constants/organization.ts +13 -14
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +65 -101
- package/src/constants/sms.ts +18 -0
- package/src/constants/storage.ts +33 -9
- package/src/constants/usage.ts +3 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +106 -283
- package/src/schemas/inboundContact.ts +5 -5
- package/src/types/agentMemory.d.ts +38 -14
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1043 -193
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +102 -309
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +144 -55
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +579 -150
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +8 -0
- package/src/types/log.d.ts +94 -3
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +8 -3
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +180 -463
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +266 -27
- package/src/types/workflow.d.ts +196 -66
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +31 -14
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +642 -209
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +18 -556
- package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/email.ts +208 -1
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +81 -37
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +232 -141
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logStoreRead.ts +9 -13
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomyDisplay.ts +80 -124
- package/src/utils/noteDoc.ts +66 -284
- package/src/utils/organization.ts +117 -283
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +123 -4834
- package/src/utils/sheetAxisMove.ts +77 -291
- package/src/utils/sheetBootstrap.ts +771 -1138
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +23 -88
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +17 -69
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +388 -403
- package/src/utils/sheetFormulaEvaluator.ts +589 -444
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +140 -18
- package/src/utils/sheetNumberFormat.ts +68 -267
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +13 -43
- package/src/utils/sheetSnapshot.ts +176 -429
- package/src/utils/sheetStructureEdit.ts +537 -907
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/storage.ts +49 -3
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +199 -73
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +37 -192
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +49 -40
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +93 -200
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +4 -23
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +492 -37
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/src/constants/agentDoc.ts +0 -12
- package/src/constants/logActivityGroupColors.generated.ts +0 -19
- package/src/constants/schedule.ts +0 -220
- package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
- package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
- package/src/constants/sheetRegionSources.generated.ts +0 -578
- package/src/schemas/fieldDocsQuery.ts +0 -12
- package/src/schemas/organization.ts +0 -68
- package/src/types/agentDoc.d.ts +0 -64
- package/src/types/noteDoc.d.ts +0 -86
- package/src/types/schedule.d.ts +0 -391
- package/src/utils/agentDoc.ts +0 -109
- package/src/utils/campaignFormEditor.ts +0 -871
- package/src/utils/dataTableRealtimeAuthority.ts +0 -209
- package/src/utils/dataTableRealtimeSelection.ts +0 -134
- package/src/utils/dataTableRowDocument.ts +0 -508
- package/src/utils/dataTableSource.ts +0 -230
- package/src/utils/schedule.ts +0 -799
- package/src/utils/scheduleEvaluation.ts +0 -1994
- package/src/utils/scheduleICS.ts +0 -246
- package/src/utils/scheduleRuleTemplates.ts +0 -188
- package/src/utils/sheetRegion.ts +0 -374
- package/src/utils/sheetRegionFilter.ts +0 -1259
- package/src/utils/sheetRegionSourceRegistry.ts +0 -594
- package/tests/schedule.test.ts +0 -693
- package/tests/scheduleEvaluation.test.ts +0 -1970
- package/tests/scheduleICS.test.ts +0 -208
- package/tests/scheduleRuleTemplates.test.ts +0 -176
- package/tests/scheduleSweepInvariants.test.ts +0 -428
- package/tests/sheetRegionFilter.test.ts +0 -1135
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { getCurrencySymbol } from '@jsb188/app/utils/number.ts';
|
|
2
2
|
import { DateTime } from 'luxon';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
SHEET_NUMBER_FORMAT_PRESET_PATTERNS,
|
|
6
|
-
} from '../constants/sheet.ts';
|
|
7
|
-
import type {
|
|
8
|
-
SheetCellFormatObj,
|
|
9
|
-
SheetCellNumberFormatTypeEnum,
|
|
10
|
-
} from '../types/sheet.d.ts';
|
|
3
|
+
import { SHEET_CELL_NUMBER_FORMAT_TYPE_ENUMS, SHEET_NUMBER_FORMAT_PRESET_PATTERNS } from '../constants/sheet.ts';
|
|
4
|
+
import type { SheetCellFormatObj, SheetCellNumberFormatTypeEnum } from '../types/sheet.d.ts';
|
|
11
5
|
|
|
12
6
|
/*
|
|
13
7
|
* Google/Excel spreadsheet serial date epoch (1899-12-30T00:00:00 UTC).
|
|
@@ -24,30 +18,12 @@ const SHEET_NUMBER_FORMAT_MAX_MAGNITUDE = 1e21;
|
|
|
24
18
|
|
|
25
19
|
// Parsed pattern cache; cleared whole when it hits the cap so long sessions
|
|
26
20
|
// with many custom patterns cannot grow it unbounded
|
|
27
|
-
const SHEET_NUMBER_FORMAT_PARSE_CACHE = new Map<
|
|
28
|
-
string,
|
|
29
|
-
SheetParsedNumberFormat | null
|
|
30
|
-
>();
|
|
21
|
+
const SHEET_NUMBER_FORMAT_PARSE_CACHE = new Map<string, SheetParsedNumberFormat | null>();
|
|
31
22
|
const SHEET_NUMBER_FORMAT_PARSE_CACHE_MAX = 256;
|
|
32
23
|
|
|
33
|
-
const SHEET_NUMBER_FORMAT_COLOR_NAMES = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
'cyan',
|
|
37
|
-
'green',
|
|
38
|
-
'magenta',
|
|
39
|
-
'red',
|
|
40
|
-
'white',
|
|
41
|
-
'yellow',
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
export type SheetNumberFormatConditionOperator =
|
|
45
|
-
| '<'
|
|
46
|
-
| '<='
|
|
47
|
-
| '>'
|
|
48
|
-
| '>='
|
|
49
|
-
| '='
|
|
50
|
-
| '<>';
|
|
24
|
+
const SHEET_NUMBER_FORMAT_COLOR_NAMES = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
|
|
25
|
+
|
|
26
|
+
export type SheetNumberFormatConditionOperator = '<' | '<=' | '>' | '>=' | '=' | '<>';
|
|
51
27
|
|
|
52
28
|
export type SheetNumberFormatToken =
|
|
53
29
|
| { kind: 'literal'; text: string }
|
|
@@ -118,12 +94,8 @@ export interface SheetNumberFormatCellValues {
|
|
|
118
94
|
/*
|
|
119
95
|
* Return whether a value is a supported number format type enum.
|
|
120
96
|
*/
|
|
121
|
-
export function isSheetCellNumberFormatType(
|
|
122
|
-
value
|
|
123
|
-
): value is SheetCellNumberFormatTypeEnum {
|
|
124
|
-
return SHEET_CELL_NUMBER_FORMAT_TYPE_ENUMS.includes(
|
|
125
|
-
value as SheetCellNumberFormatTypeEnum,
|
|
126
|
-
);
|
|
97
|
+
export function isSheetCellNumberFormatType(value: unknown): value is SheetCellNumberFormatTypeEnum {
|
|
98
|
+
return SHEET_CELL_NUMBER_FORMAT_TYPE_ENUMS.includes(value as SheetCellNumberFormatTypeEnum);
|
|
127
99
|
}
|
|
128
100
|
|
|
129
101
|
/*
|
|
@@ -138,24 +110,13 @@ export function resolveSheetCellNumberFormat(
|
|
|
138
110
|
): SheetResolvedNumberFormat | null {
|
|
139
111
|
const numberFormat = format?.numberFormat;
|
|
140
112
|
|
|
141
|
-
if (
|
|
142
|
-
!numberFormat ||
|
|
143
|
-
typeof numberFormat !== 'object' ||
|
|
144
|
-
!isSheetCellNumberFormatType(numberFormat.type)
|
|
145
|
-
) {
|
|
113
|
+
if (!numberFormat || typeof numberFormat !== 'object' || !isSheetCellNumberFormatType(numberFormat.type)) {
|
|
146
114
|
return null;
|
|
147
115
|
}
|
|
148
116
|
|
|
149
|
-
const currency =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
: null;
|
|
153
|
-
const explicitPattern =
|
|
154
|
-
typeof numberFormat.pattern === 'string' && numberFormat.pattern
|
|
155
|
-
? numberFormat.pattern
|
|
156
|
-
: null;
|
|
157
|
-
let pattern =
|
|
158
|
-
explicitPattern || SHEET_NUMBER_FORMAT_PRESET_PATTERNS[numberFormat.type];
|
|
117
|
+
const currency = typeof numberFormat.currency === 'string' && numberFormat.currency ? numberFormat.currency : null;
|
|
118
|
+
const explicitPattern = typeof numberFormat.pattern === 'string' && numberFormat.pattern ? numberFormat.pattern : null;
|
|
119
|
+
let pattern = explicitPattern || SHEET_NUMBER_FORMAT_PRESET_PATTERNS[numberFormat.type];
|
|
159
120
|
|
|
160
121
|
// Preset currency-family patterns carry a "$" literal that stands in for
|
|
161
122
|
// the resolved locale symbol; explicit custom patterns are left untouched
|
|
@@ -222,16 +183,11 @@ function splitSheetNumberFormatSections(pattern: string): string[] {
|
|
|
222
183
|
* Return one parsed bracket block token/metadata for a section, or null when
|
|
223
184
|
* the block is unknown and should be ignored.
|
|
224
185
|
*/
|
|
225
|
-
function parseSheetNumberFormatBracket(
|
|
226
|
-
content: string,
|
|
227
|
-
section: SheetNumberFormatSection,
|
|
228
|
-
): SheetNumberFormatToken | null {
|
|
186
|
+
function parseSheetNumberFormatBracket(content: string, section: SheetNumberFormatSection): SheetNumberFormatToken | null {
|
|
229
187
|
// Currency with optional locale id, e.g. [$€-407] or [$USD]
|
|
230
188
|
const currencyMatch = content.match(/^\$([^-\]]*)(?:-[^\]]*)?$/);
|
|
231
189
|
if (currencyMatch) {
|
|
232
|
-
return currencyMatch[1]
|
|
233
|
-
? { kind: 'literal', text: currencyMatch[1] }
|
|
234
|
-
: null;
|
|
190
|
+
return currencyMatch[1] ? { kind: 'literal', text: currencyMatch[1] } : null;
|
|
235
191
|
}
|
|
236
192
|
|
|
237
193
|
// Elapsed duration units, e.g. [h] [mm] [s]
|
|
@@ -243,9 +199,7 @@ function parseSheetNumberFormatBracket(
|
|
|
243
199
|
}
|
|
244
200
|
|
|
245
201
|
// Section condition, e.g. [>100] or [<=-5.5]
|
|
246
|
-
const conditionMatch = content.match(
|
|
247
|
-
/^(<=|>=|<>|<|>|=)\s*(-?\d+(?:\.\d+)?)$/,
|
|
248
|
-
);
|
|
202
|
+
const conditionMatch = content.match(/^(<=|>=|<>|<|>|=)\s*(-?\d+(?:\.\d+)?)$/);
|
|
249
203
|
if (conditionMatch) {
|
|
250
204
|
section.condition = {
|
|
251
205
|
operator: conditionMatch[1] as SheetNumberFormatConditionOperator,
|
|
@@ -256,10 +210,7 @@ function parseSheetNumberFormatBracket(
|
|
|
256
210
|
|
|
257
211
|
// Color tags are parsed as metadata only; the canvas does not paint them yet
|
|
258
212
|
const lowerContent = content.toLowerCase();
|
|
259
|
-
if (
|
|
260
|
-
SHEET_NUMBER_FORMAT_COLOR_NAMES.includes(lowerContent) ||
|
|
261
|
-
/^color\s*\d+$/.test(lowerContent)
|
|
262
|
-
) {
|
|
213
|
+
if (SHEET_NUMBER_FORMAT_COLOR_NAMES.includes(lowerContent) || /^color\s*\d+$/.test(lowerContent)) {
|
|
263
214
|
section.color = content;
|
|
264
215
|
return null;
|
|
265
216
|
}
|
|
@@ -271,9 +222,7 @@ function parseSheetNumberFormatBracket(
|
|
|
271
222
|
* Tokenize one pattern section into a raw token stream. Date-vs-minute and
|
|
272
223
|
* comma semantics are resolved afterwards in classifySheetNumberFormatSection.
|
|
273
224
|
*/
|
|
274
|
-
function tokenizeSheetNumberFormatSection(
|
|
275
|
-
src: string,
|
|
276
|
-
): SheetNumberFormatSection | null {
|
|
225
|
+
function tokenizeSheetNumberFormatSection(src: string): SheetNumberFormatSection | null {
|
|
277
226
|
const section: SheetNumberFormatSection = {
|
|
278
227
|
condition: null,
|
|
279
228
|
color: null,
|
|
@@ -336,10 +285,7 @@ function tokenizeSheetNumberFormatSection(
|
|
|
336
285
|
if (end === -1) {
|
|
337
286
|
return null;
|
|
338
287
|
}
|
|
339
|
-
const bracketToken = parseSheetNumberFormatBracket(
|
|
340
|
-
src.slice(i + 1, end),
|
|
341
|
-
section,
|
|
342
|
-
);
|
|
288
|
+
const bracketToken = parseSheetNumberFormatBracket(src.slice(i + 1, end), section);
|
|
343
289
|
if (bracketToken) {
|
|
344
290
|
tokens.push(bracketToken);
|
|
345
291
|
}
|
|
@@ -356,17 +302,11 @@ function tokenizeSheetNumberFormatSection(
|
|
|
356
302
|
tokens.push({ kind: 'slash' });
|
|
357
303
|
} else if (char === '@') {
|
|
358
304
|
tokens.push({ kind: 'text' });
|
|
359
|
-
} else if (
|
|
360
|
-
(char === 'E' || char === 'e') &&
|
|
361
|
-
(src[i + 1] === '+' || src[i + 1] === '-')
|
|
362
|
-
) {
|
|
305
|
+
} else if ((char === 'E' || char === 'e') && (src[i + 1] === '+' || src[i + 1] === '-')) {
|
|
363
306
|
const sign = src[i + 1] as '+' | '-';
|
|
364
307
|
let digits = 0;
|
|
365
308
|
let j = i + 2;
|
|
366
|
-
while (
|
|
367
|
-
j < src.length &&
|
|
368
|
-
(src[j] === '0' || src[j] === '#' || src[j] === '?')
|
|
369
|
-
) {
|
|
309
|
+
while (j < src.length && (src[j] === '0' || src[j] === '#' || src[j] === '?')) {
|
|
370
310
|
digits++;
|
|
371
311
|
j++;
|
|
372
312
|
}
|
|
@@ -411,28 +351,17 @@ function tokenizeSheetNumberFormatSection(
|
|
|
411
351
|
* section kind, disambiguate month-vs-minute, fold date punctuation into
|
|
412
352
|
* literals, and derive digit placeholder/grouping/scaling info.
|
|
413
353
|
*/
|
|
414
|
-
function classifySheetNumberFormatSection(
|
|
415
|
-
section: SheetNumberFormatSection,
|
|
416
|
-
): SheetNumberFormatSection {
|
|
354
|
+
function classifySheetNumberFormatSection(section: SheetNumberFormatSection): SheetNumberFormatSection {
|
|
417
355
|
const tokens = section.tokens;
|
|
418
|
-
const hasDateTokens = tokens.some(
|
|
419
|
-
(token) =>
|
|
420
|
-
token.kind === 'date' ||
|
|
421
|
-
token.kind === 'elapsed' ||
|
|
422
|
-
token.kind === 'meridiem',
|
|
423
|
-
);
|
|
356
|
+
const hasDateTokens = tokens.some((token) => token.kind === 'date' || token.kind === 'elapsed' || token.kind === 'meridiem');
|
|
424
357
|
const hasTextToken = tokens.some((token) => token.kind === 'text');
|
|
425
358
|
|
|
426
359
|
if (hasDateTokens) {
|
|
427
360
|
section.kind = 'date';
|
|
428
361
|
section.hasMeridiem = tokens.some((token) => token.kind === 'meridiem');
|
|
429
362
|
section.hasElapsed = tokens.some((token) => token.kind === 'elapsed');
|
|
430
|
-
section.hasElapsedHour = tokens.some(
|
|
431
|
-
|
|
432
|
-
);
|
|
433
|
-
section.hasElapsedMinute = tokens.some(
|
|
434
|
-
(token) => token.kind === 'elapsed' && token.unit === 'minute',
|
|
435
|
-
);
|
|
363
|
+
section.hasElapsedHour = tokens.some((token) => token.kind === 'elapsed' && token.unit === 'hour');
|
|
364
|
+
section.hasElapsedMinute = tokens.some((token) => token.kind === 'elapsed' && token.unit === 'minute');
|
|
436
365
|
|
|
437
366
|
// Month tokens mean minutes when preceded by an hour token or followed
|
|
438
367
|
// by a seconds token within the same section
|
|
@@ -443,9 +372,7 @@ function classifySheetNumberFormatSection(
|
|
|
443
372
|
} else if (token.kind !== 'date') {
|
|
444
373
|
return;
|
|
445
374
|
} else if (token.unit === 'month' && token.length <= 2) {
|
|
446
|
-
const nextDateToken = tokens
|
|
447
|
-
.slice(index + 1)
|
|
448
|
-
.find((t) => t.kind === 'date' || t.kind === 'elapsed') as
|
|
375
|
+
const nextDateToken = tokens.slice(index + 1).find((t) => t.kind === 'date' || t.kind === 'elapsed') as
|
|
449
376
|
| Extract<SheetNumberFormatToken, { kind: 'date' | 'elapsed' }>
|
|
450
377
|
| undefined;
|
|
451
378
|
|
|
@@ -470,11 +397,7 @@ function classifySheetNumberFormatSection(
|
|
|
470
397
|
(prevToken?.kind === 'date' && prevToken.unit === 'second') ||
|
|
471
398
|
(prevToken?.kind === 'elapsed' && prevToken.unit === 'second');
|
|
472
399
|
|
|
473
|
-
if (
|
|
474
|
-
followsSeconds &&
|
|
475
|
-
nextToken?.kind === 'digit' &&
|
|
476
|
-
nextToken.placeholder === '0'
|
|
477
|
-
) {
|
|
400
|
+
if (followsSeconds && nextToken?.kind === 'digit' && nextToken.placeholder === '0') {
|
|
478
401
|
let length = 0;
|
|
479
402
|
while (tokens[i + 1]?.kind === 'digit') {
|
|
480
403
|
tokens.splice(i + 1, 1);
|
|
@@ -517,9 +440,7 @@ function classifySheetNumberFormatSection(
|
|
|
517
440
|
const decimalIndex = tokens.findIndex((token) => token.kind === 'decimal');
|
|
518
441
|
|
|
519
442
|
section.hasExponent = tokens.some((token) => token.kind === 'exponent');
|
|
520
|
-
section.percentCount = tokens.filter(
|
|
521
|
-
(token) => token.kind === 'percent',
|
|
522
|
-
).length;
|
|
443
|
+
section.percentCount = tokens.filter((token) => token.kind === 'percent').length;
|
|
523
444
|
section.hasFraction = tokens.some(
|
|
524
445
|
(token, index) =>
|
|
525
446
|
token.kind === 'slash' &&
|
|
@@ -563,9 +484,7 @@ function classifySheetNumberFormatSection(
|
|
|
563
484
|
* sections. Results are cached by pattern; null means unusable pattern (the
|
|
564
485
|
* caller should fall back to raw display).
|
|
565
486
|
*/
|
|
566
|
-
export function parseSheetNumberFormatPattern(
|
|
567
|
-
pattern: string,
|
|
568
|
-
): SheetParsedNumberFormat | null {
|
|
487
|
+
export function parseSheetNumberFormatPattern(pattern: string): SheetParsedNumberFormat | null {
|
|
569
488
|
if (typeof pattern !== 'string' || !pattern || pattern.length > 500) {
|
|
570
489
|
return null;
|
|
571
490
|
}
|
|
@@ -577,24 +496,18 @@ export function parseSheetNumberFormatPattern(
|
|
|
577
496
|
let parsed: SheetParsedNumberFormat | null = null;
|
|
578
497
|
|
|
579
498
|
try {
|
|
580
|
-
const sections = splitSheetNumberFormatSections(pattern).map((sectionSrc) =>
|
|
581
|
-
tokenizeSheetNumberFormatSection(sectionSrc),
|
|
582
|
-
);
|
|
499
|
+
const sections = splitSheetNumberFormatSections(pattern).map((sectionSrc) => tokenizeSheetNumberFormatSection(sectionSrc));
|
|
583
500
|
|
|
584
501
|
if (!sections.some((section) => section === null) && sections.length) {
|
|
585
502
|
parsed = {
|
|
586
|
-
sections: (sections as SheetNumberFormatSection[]).map(
|
|
587
|
-
classifySheetNumberFormatSection,
|
|
588
|
-
),
|
|
503
|
+
sections: (sections as SheetNumberFormatSection[]).map(classifySheetNumberFormatSection),
|
|
589
504
|
};
|
|
590
505
|
}
|
|
591
506
|
} catch {
|
|
592
507
|
parsed = null;
|
|
593
508
|
}
|
|
594
509
|
|
|
595
|
-
if (
|
|
596
|
-
SHEET_NUMBER_FORMAT_PARSE_CACHE.size >= SHEET_NUMBER_FORMAT_PARSE_CACHE_MAX
|
|
597
|
-
) {
|
|
510
|
+
if (SHEET_NUMBER_FORMAT_PARSE_CACHE.size >= SHEET_NUMBER_FORMAT_PARSE_CACHE_MAX) {
|
|
598
511
|
SHEET_NUMBER_FORMAT_PARSE_CACHE.clear();
|
|
599
512
|
}
|
|
600
513
|
|
|
@@ -624,10 +537,7 @@ export function getSheetSerialFromDateTime(dateTime: DateTime): number {
|
|
|
624
537
|
* Return the UTC Luxon date-time represented by one serial-day value.
|
|
625
538
|
*/
|
|
626
539
|
export function getSheetDateTimeFromSerial(serial: number): DateTime {
|
|
627
|
-
return DateTime.fromMillis(
|
|
628
|
-
SHEET_SERIAL_EPOCH_MS + Math.round(serial * MS_PER_DAY),
|
|
629
|
-
{ zone: 'utc' },
|
|
630
|
-
);
|
|
540
|
+
return DateTime.fromMillis(SHEET_SERIAL_EPOCH_MS + Math.round(serial * MS_PER_DAY), { zone: 'utc' });
|
|
631
541
|
}
|
|
632
542
|
|
|
633
543
|
/*
|
|
@@ -641,11 +551,7 @@ function addSheetNumberFormatGrouping(digits: string): string {
|
|
|
641
551
|
* Render the integer digit region for one number section: pads missing
|
|
642
552
|
* leading positions per placeholder type and applies grouping.
|
|
643
553
|
*/
|
|
644
|
-
function renderSheetNumberFormatIntegerPart(
|
|
645
|
-
intDigits: string,
|
|
646
|
-
placeholders: string,
|
|
647
|
-
grouping: boolean,
|
|
648
|
-
): string {
|
|
554
|
+
function renderSheetNumberFormatIntegerPart(intDigits: string, placeholders: string, grouping: boolean): string {
|
|
649
555
|
let zeroPad = '';
|
|
650
556
|
let spacePad = '';
|
|
651
557
|
const missingCount = Math.max(placeholders.length - intDigits.length, 0);
|
|
@@ -660,22 +566,14 @@ function renderSheetNumberFormatIntegerPart(
|
|
|
660
566
|
|
|
661
567
|
const fullDigits = zeroPad + intDigits;
|
|
662
568
|
|
|
663
|
-
return (
|
|
664
|
-
spacePad +
|
|
665
|
-
(grouping && fullDigits
|
|
666
|
-
? addSheetNumberFormatGrouping(fullDigits)
|
|
667
|
-
: fullDigits)
|
|
668
|
-
);
|
|
569
|
+
return spacePad + (grouping && fullDigits ? addSheetNumberFormatGrouping(fullDigits) : fullDigits);
|
|
669
570
|
}
|
|
670
571
|
|
|
671
572
|
/*
|
|
672
573
|
* Render the decimal digit region for one number section: trims insignificant
|
|
673
574
|
* trailing zeros per placeholder type ("#" drops, "?" pads with space).
|
|
674
575
|
*/
|
|
675
|
-
function renderSheetNumberFormatDecimalPart(
|
|
676
|
-
decDigits: string,
|
|
677
|
-
placeholders: string,
|
|
678
|
-
): string {
|
|
576
|
+
function renderSheetNumberFormatDecimalPart(decDigits: string, placeholders: string): string {
|
|
679
577
|
const chars = decDigits.split('');
|
|
680
578
|
|
|
681
579
|
for (let i = chars.length - 1; i >= 0; i--) {
|
|
@@ -697,11 +595,7 @@ function renderSheetNumberFormatDecimalPart(
|
|
|
697
595
|
* Return {mantissa, exponent} for scientific rendering where the mantissa
|
|
698
596
|
* keeps as many integer digits as the section has integer placeholders.
|
|
699
597
|
*/
|
|
700
|
-
function getSheetNumberFormatScientificParts(
|
|
701
|
-
absValue: number,
|
|
702
|
-
intPlaceholderCount: number,
|
|
703
|
-
decCount: number,
|
|
704
|
-
) {
|
|
598
|
+
function getSheetNumberFormatScientificParts(absValue: number, intPlaceholderCount: number, decCount: number) {
|
|
705
599
|
if (!absValue) {
|
|
706
600
|
return { exponent: 0, mantissa: 0 };
|
|
707
601
|
}
|
|
@@ -722,10 +616,7 @@ function getSheetNumberFormatScientificParts(
|
|
|
722
616
|
/*
|
|
723
617
|
* Render one non-negative number through one parsed number section's tokens.
|
|
724
618
|
*/
|
|
725
|
-
function renderSheetNumberFormatSection(
|
|
726
|
-
section: SheetNumberFormatSection,
|
|
727
|
-
absValue: number,
|
|
728
|
-
): string {
|
|
619
|
+
function renderSheetNumberFormatSection(section: SheetNumberFormatSection, absValue: number): string {
|
|
729
620
|
// Fraction patterns degrade to the plain decimal representation in v1
|
|
730
621
|
if (section.hasFraction) {
|
|
731
622
|
return String(absValue);
|
|
@@ -737,11 +628,7 @@ function renderSheetNumberFormatSection(
|
|
|
737
628
|
let exponentValue = 0;
|
|
738
629
|
|
|
739
630
|
if (section.hasExponent) {
|
|
740
|
-
const scientific = getSheetNumberFormatScientificParts(
|
|
741
|
-
absValue,
|
|
742
|
-
section.intPlaceholders.length,
|
|
743
|
-
decCount,
|
|
744
|
-
);
|
|
631
|
+
const scientific = getSheetNumberFormatScientificParts(absValue, section.intPlaceholders.length, decCount);
|
|
745
632
|
const fixedParts = scientific.mantissa.toFixed(decCount).split('.');
|
|
746
633
|
intDigits = fixedParts[0];
|
|
747
634
|
decDigits = fixedParts[1] || '';
|
|
@@ -758,10 +645,7 @@ function renderSheetNumberFormatSection(
|
|
|
758
645
|
intDigits = '';
|
|
759
646
|
}
|
|
760
647
|
|
|
761
|
-
const decOut = renderSheetNumberFormatDecimalPart(
|
|
762
|
-
decDigits,
|
|
763
|
-
section.decPlaceholders,
|
|
764
|
-
);
|
|
648
|
+
const decOut = renderSheetNumberFormatDecimalPart(decDigits, section.decPlaceholders);
|
|
765
649
|
let out = '';
|
|
766
650
|
let intRendered = false;
|
|
767
651
|
let decRendered = false;
|
|
@@ -785,11 +669,7 @@ function renderSheetNumberFormatSection(
|
|
|
785
669
|
// Each digit region renders whole at its first placeholder; the
|
|
786
670
|
// remaining placeholders emit nothing
|
|
787
671
|
if (!passedDecimal && !intRendered) {
|
|
788
|
-
out += renderSheetNumberFormatIntegerPart(
|
|
789
|
-
intDigits,
|
|
790
|
-
section.intPlaceholders,
|
|
791
|
-
section.grouping,
|
|
792
|
-
);
|
|
672
|
+
out += renderSheetNumberFormatIntegerPart(intDigits, section.intPlaceholders, section.grouping);
|
|
793
673
|
intRendered = true;
|
|
794
674
|
} else if (passedDecimal && !decRendered) {
|
|
795
675
|
out += decOut;
|
|
@@ -836,18 +716,8 @@ function renderSheetDateFormatSection(
|
|
|
836
716
|
|
|
837
717
|
if (token.kind === 'meridiem') {
|
|
838
718
|
const isPM = localized.hour >= 12;
|
|
839
|
-
const long =
|
|
840
|
-
|
|
841
|
-
? isPM
|
|
842
|
-
? 'PM'
|
|
843
|
-
: 'AM'
|
|
844
|
-
: token.style === 'am/pm'
|
|
845
|
-
? isPM
|
|
846
|
-
? 'pm'
|
|
847
|
-
: 'am'
|
|
848
|
-
: null;
|
|
849
|
-
out +=
|
|
850
|
-
long ?? (token.style === 'A/P' ? (isPM ? 'P' : 'A') : isPM ? 'p' : 'a');
|
|
719
|
+
const long = token.style === 'AM/PM' ? (isPM ? 'PM' : 'AM') : token.style === 'am/pm' ? (isPM ? 'pm' : 'am') : null;
|
|
720
|
+
out += long ?? (token.style === 'A/P' ? (isPM ? 'P' : 'A') : isPM ? 'p' : 'a');
|
|
851
721
|
continue;
|
|
852
722
|
}
|
|
853
723
|
|
|
@@ -863,13 +733,7 @@ function renderSheetDateFormatSection(
|
|
|
863
733
|
}
|
|
864
734
|
|
|
865
735
|
if (token.kind === 'fractionalSecond') {
|
|
866
|
-
out +=
|
|
867
|
-
'.' +
|
|
868
|
-
String(
|
|
869
|
-
Math.floor(
|
|
870
|
-
(localized.millisecond * Math.pow(10, token.length)) / 1000,
|
|
871
|
-
),
|
|
872
|
-
).padStart(token.length, '0');
|
|
736
|
+
out += '.' + String(Math.floor((localized.millisecond * Math.pow(10, token.length)) / 1000)).padStart(token.length, '0');
|
|
873
737
|
continue;
|
|
874
738
|
}
|
|
875
739
|
|
|
@@ -879,10 +743,7 @@ function renderSheetDateFormatSection(
|
|
|
879
743
|
|
|
880
744
|
switch (token.unit) {
|
|
881
745
|
case 'year':
|
|
882
|
-
out +=
|
|
883
|
-
token.length >= 3
|
|
884
|
-
? String(localized.year).padStart(4, '0')
|
|
885
|
-
: String(localized.year % 100).padStart(2, '0');
|
|
746
|
+
out += token.length >= 3 ? String(localized.year).padStart(4, '0') : String(localized.year % 100).padStart(2, '0');
|
|
886
747
|
break;
|
|
887
748
|
case 'month':
|
|
888
749
|
out +=
|
|
@@ -909,33 +770,18 @@ function renderSheetDateFormatSection(
|
|
|
909
770
|
case 'hour': {
|
|
910
771
|
// Remainder hours under an elapsed-minute/second section make no
|
|
911
772
|
// sense; hours always come from the clock
|
|
912
|
-
const hourValue = section.hasMeridiem
|
|
913
|
-
|
|
914
|
-
: localized.hour;
|
|
915
|
-
out +=
|
|
916
|
-
token.length >= 2
|
|
917
|
-
? String(hourValue).padStart(2, '0')
|
|
918
|
-
: String(hourValue);
|
|
773
|
+
const hourValue = section.hasMeridiem ? localized.hour % 12 || 12 : localized.hour;
|
|
774
|
+
out += token.length >= 2 ? String(hourValue).padStart(2, '0') : String(hourValue);
|
|
919
775
|
break;
|
|
920
776
|
}
|
|
921
777
|
case 'minute': {
|
|
922
|
-
const minuteValue = section.hasElapsedHour
|
|
923
|
-
|
|
924
|
-
: localized.minute;
|
|
925
|
-
out +=
|
|
926
|
-
token.length >= 2
|
|
927
|
-
? String(minuteValue).padStart(2, '0')
|
|
928
|
-
: String(minuteValue);
|
|
778
|
+
const minuteValue = section.hasElapsedHour ? Math.floor((totalSeconds % 3600) / 60) : localized.minute;
|
|
779
|
+
out += token.length >= 2 ? String(minuteValue).padStart(2, '0') : String(minuteValue);
|
|
929
780
|
break;
|
|
930
781
|
}
|
|
931
782
|
case 'second': {
|
|
932
|
-
const secondValue = section.hasElapsed
|
|
933
|
-
|
|
934
|
-
: localized.second;
|
|
935
|
-
out +=
|
|
936
|
-
token.length >= 2
|
|
937
|
-
? String(secondValue).padStart(2, '0')
|
|
938
|
-
: String(secondValue);
|
|
783
|
+
const secondValue = section.hasElapsed ? totalSeconds % 60 : localized.second;
|
|
784
|
+
out += token.length >= 2 ? String(secondValue).padStart(2, '0') : String(secondValue);
|
|
939
785
|
break;
|
|
940
786
|
}
|
|
941
787
|
}
|
|
@@ -947,10 +793,7 @@ function renderSheetDateFormatSection(
|
|
|
947
793
|
/*
|
|
948
794
|
* Render one text value through one parsed text section ("@" substitution).
|
|
949
795
|
*/
|
|
950
|
-
function renderSheetTextFormatSection(
|
|
951
|
-
section: SheetNumberFormatSection,
|
|
952
|
-
text: string,
|
|
953
|
-
): string {
|
|
796
|
+
function renderSheetTextFormatSection(section: SheetNumberFormatSection, text: string): string {
|
|
954
797
|
return section.tokens.reduce((out, token) => {
|
|
955
798
|
if (token.kind === 'text') {
|
|
956
799
|
return out + text;
|
|
@@ -991,9 +834,7 @@ function pickSheetNumberFormatSection(
|
|
|
991
834
|
parsed: SheetParsedNumberFormat,
|
|
992
835
|
value: number,
|
|
993
836
|
): { section: SheetNumberFormatSection; useAutoMinus: boolean } | null {
|
|
994
|
-
const sections = parsed.sections.filter(
|
|
995
|
-
(section) => section.kind !== 'text' || parsed.sections.length === 1,
|
|
996
|
-
);
|
|
837
|
+
const sections = parsed.sections.filter((section) => section.kind !== 'text' || parsed.sections.length === 1);
|
|
997
838
|
|
|
998
839
|
if (!sections.length) {
|
|
999
840
|
return null;
|
|
@@ -1001,11 +842,7 @@ function pickSheetNumberFormatSection(
|
|
|
1001
842
|
|
|
1002
843
|
if (sections.some((section) => section.condition)) {
|
|
1003
844
|
const matched =
|
|
1004
|
-
sections.find(
|
|
1005
|
-
(section) =>
|
|
1006
|
-
section.condition &&
|
|
1007
|
-
sheetNumberFormatConditionMatches(section.condition, value),
|
|
1008
|
-
) ||
|
|
845
|
+
sections.find((section) => section.condition && sheetNumberFormatConditionMatches(section.condition, value)) ||
|
|
1009
846
|
sections.find((section) => !section.condition) ||
|
|
1010
847
|
sections[sections.length - 1];
|
|
1011
848
|
|
|
@@ -1019,9 +856,7 @@ function pickSheetNumberFormatSection(
|
|
|
1019
856
|
// Round with the sign-picked section first so values like -0.004 with two
|
|
1020
857
|
// decimals land in the positive/zero section, not "(0.00)"
|
|
1021
858
|
const tentative = value < 0 && negative ? negative : positive;
|
|
1022
|
-
const scaled =
|
|
1023
|
-
(value * Math.pow(100, tentative.percentCount)) /
|
|
1024
|
-
Math.pow(1000, tentative.scaleCommaCount);
|
|
859
|
+
const scaled = (value * Math.pow(100, tentative.percentCount)) / Math.pow(1000, tentative.scaleCommaCount);
|
|
1025
860
|
const rounded =
|
|
1026
861
|
tentative.kind === 'number' && !tentative.hasExponent
|
|
1027
862
|
? Number(Math.abs(scaled).toFixed(tentative.decPlaceholders.length))
|
|
@@ -1032,9 +867,7 @@ function pickSheetNumberFormatSection(
|
|
|
1032
867
|
}
|
|
1033
868
|
|
|
1034
869
|
if (value < 0) {
|
|
1035
|
-
return negative
|
|
1036
|
-
? { section: negative, useAutoMinus: false }
|
|
1037
|
-
: { section: positive, useAutoMinus: true };
|
|
870
|
+
return negative ? { section: negative, useAutoMinus: false } : { section: positive, useAutoMinus: true };
|
|
1038
871
|
}
|
|
1039
872
|
|
|
1040
873
|
return { section: positive, useAutoMinus: false };
|
|
@@ -1044,15 +877,8 @@ function pickSheetNumberFormatSection(
|
|
|
1044
877
|
* Format one numeric value with one parsed pattern, dispatching to date
|
|
1045
878
|
* rendering via serial conversion when the chosen section uses date tokens.
|
|
1046
879
|
*/
|
|
1047
|
-
export function formatSheetNumberValue(
|
|
1048
|
-
value
|
|
1049
|
-
parsed: SheetParsedNumberFormat,
|
|
1050
|
-
locale?: string | null,
|
|
1051
|
-
): string | null {
|
|
1052
|
-
if (
|
|
1053
|
-
!Number.isFinite(value) ||
|
|
1054
|
-
Math.abs(value) >= SHEET_NUMBER_FORMAT_MAX_MAGNITUDE
|
|
1055
|
-
) {
|
|
880
|
+
export function formatSheetNumberValue(value: number, parsed: SheetParsedNumberFormat, locale?: string | null): string | null {
|
|
881
|
+
if (!Number.isFinite(value) || Math.abs(value) >= SHEET_NUMBER_FORMAT_MAX_MAGNITUDE) {
|
|
1056
882
|
return null;
|
|
1057
883
|
}
|
|
1058
884
|
|
|
@@ -1063,46 +889,29 @@ export function formatSheetNumberValue(
|
|
|
1063
889
|
}
|
|
1064
890
|
|
|
1065
891
|
if (picked.section.kind === 'date') {
|
|
1066
|
-
return renderSheetDateFormatSection(
|
|
1067
|
-
picked.section,
|
|
1068
|
-
getSheetDateTimeFromSerial(value),
|
|
1069
|
-
value,
|
|
1070
|
-
locale,
|
|
1071
|
-
);
|
|
892
|
+
return renderSheetDateFormatSection(picked.section, getSheetDateTimeFromSerial(value), value, locale);
|
|
1072
893
|
}
|
|
1073
894
|
|
|
1074
895
|
if (picked.section.kind === 'text') {
|
|
1075
896
|
return null;
|
|
1076
897
|
}
|
|
1077
898
|
|
|
1078
|
-
const scaled =
|
|
1079
|
-
(Math.abs(value) * Math.pow(100, picked.section.percentCount)) /
|
|
1080
|
-
Math.pow(1000, picked.section.scaleCommaCount);
|
|
899
|
+
const scaled = (Math.abs(value) * Math.pow(100, picked.section.percentCount)) / Math.pow(1000, picked.section.scaleCommaCount);
|
|
1081
900
|
const rendered = renderSheetNumberFormatSection(picked.section, scaled);
|
|
1082
|
-
const roundedIsZero =
|
|
1083
|
-
!picked.section.hasExponent &&
|
|
1084
|
-
Number(scaled.toFixed(picked.section.decPlaceholders.length)) === 0;
|
|
901
|
+
const roundedIsZero = !picked.section.hasExponent && Number(scaled.toFixed(picked.section.decPlaceholders.length)) === 0;
|
|
1085
902
|
|
|
1086
903
|
return picked.useAutoMinus && !roundedIsZero ? `-${rendered}` : rendered;
|
|
1087
904
|
}
|
|
1088
905
|
|
|
1089
906
|
/*
|
|
1090
907
|
* Return the Luxon date-time for one cell's date-like value. Canonical typed
|
|
1091
|
-
* mirrors win; a strict ISO text mirror also supports
|
|
908
|
+
* mirrors win; a strict ISO text mirror also supports serialized cells.
|
|
1092
909
|
* Date-only values keep their wall clock, while datetimes shift by time zone.
|
|
1093
910
|
*/
|
|
1094
|
-
function getSheetCellFormatDateTime(
|
|
1095
|
-
cell:
|
|
1096
|
-
|
|
1097
|
-
)
|
|
1098
|
-
const isoTextValue =
|
|
1099
|
-
typeof cell.textValue === 'string' ? cell.textValue.trim() : '';
|
|
1100
|
-
const textDateValue = /^\d{4}-\d{2}-\d{2}$/.test(isoTextValue)
|
|
1101
|
-
? isoTextValue
|
|
1102
|
-
: null;
|
|
1103
|
-
const textDateTimeValue = /^\d{4}-\d{2}-\d{2}T/.test(isoTextValue)
|
|
1104
|
-
? isoTextValue
|
|
1105
|
-
: null;
|
|
911
|
+
function getSheetCellFormatDateTime(cell: SheetNumberFormatCellValues, timeZone?: string | null): DateTime | null {
|
|
912
|
+
const isoTextValue = typeof cell.textValue === 'string' ? cell.textValue.trim() : '';
|
|
913
|
+
const textDateValue = /^\d{4}-\d{2}-\d{2}$/.test(isoTextValue) ? isoTextValue : null;
|
|
914
|
+
const textDateTimeValue = /^\d{4}-\d{2}-\d{2}T/.test(isoTextValue) ? isoTextValue : null;
|
|
1106
915
|
const dateValue = cell.dateValue || textDateValue;
|
|
1107
916
|
const datetimeValue = cell.datetimeValue || textDateTimeValue;
|
|
1108
917
|
const value = dateValue || datetimeValue;
|
|
@@ -1112,9 +921,7 @@ function getSheetCellFormatDateTime(
|
|
|
1112
921
|
}
|
|
1113
922
|
|
|
1114
923
|
const dateTime =
|
|
1115
|
-
value instanceof Date
|
|
1116
|
-
? DateTime.fromJSDate(value, { zone: 'utc' })
|
|
1117
|
-
: DateTime.fromISO(String(value), { setZone: true });
|
|
924
|
+
value instanceof Date ? DateTime.fromJSDate(value, { zone: 'utc' }) : DateTime.fromISO(String(value), { setZone: true });
|
|
1118
925
|
|
|
1119
926
|
if (!dateTime.isValid) {
|
|
1120
927
|
return null;
|
|
@@ -1178,12 +985,7 @@ export function formatSheetCellValue(
|
|
|
1178
985
|
const picked = pickSheetNumberFormatSection(parsed, serial);
|
|
1179
986
|
|
|
1180
987
|
if (picked?.section.kind === 'date') {
|
|
1181
|
-
return renderSheetDateFormatSection(
|
|
1182
|
-
picked.section,
|
|
1183
|
-
dateTime,
|
|
1184
|
-
serial,
|
|
1185
|
-
locale,
|
|
1186
|
-
);
|
|
988
|
+
return renderSheetDateFormatSection(picked.section, dateTime, serial, locale);
|
|
1187
989
|
}
|
|
1188
990
|
|
|
1189
991
|
return formatSheetNumberValue(serial, parsed, locale);
|
|
@@ -1191,8 +993,7 @@ export function formatSheetCellValue(
|
|
|
1191
993
|
|
|
1192
994
|
// Text values only pick up an explicit "@" section: the 4th section of a
|
|
1193
995
|
// full pattern, or a single-section pure text pattern
|
|
1194
|
-
const textValue =
|
|
1195
|
-
typeof cell.textValue === 'string' ? cell.textValue : null;
|
|
996
|
+
const textValue = typeof cell.textValue === 'string' ? cell.textValue : null;
|
|
1196
997
|
const textSection =
|
|
1197
998
|
parsed.sections.length === 4 && parsed.sections[3].kind === 'text'
|
|
1198
999
|
? parsed.sections[3]
|