Skip to content

Commit 6a73deb

Browse files
committed
fix(file-parsers): keep the elapsed-format check on the uncapped format
1 parent d7d44df commit 6a73deb

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎apps/sim/lib/file-parsers/sheet-display-text.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,13 @@ describe('normalizeSheetDisplayText', () => {
236236
const at = new Date(Date.UTC(2024, 2, 15, 14, 30))
237237
sheet.A1 = { t: 'd', v: at, z: `h:mm:ss${'"x"'.repeat(100)}`, w: '14:30:00' }
238238
sheet.B1 = { t: 'd', v: at, z: `h:mm:ss${'"x"'.repeat(80)}`, w: '14:30:00' }
239-
sheet['!ref'] = 'A1:B1'
239+
sheet.C1 = { t: 'd', v: at, z: `[h]:mm${'"x"'.repeat(100)}`, w: '14:30' }
240+
sheet['!ref'] = 'A1:C1'
240241

241-
normalizeSheetDisplayText(sheet, XLSX.utils.decode_range('A1:B1'), XLSX.utils)
242+
normalizeSheetDisplayText(sheet, XLSX.utils.decode_range('A1:C1'), XLSX.utils)
242243

243244
expect(sheet.A1.w).toBe('2024-03-15T14:30:00')
244245
expect(sheet.B1.w).toBe('14:30:00')
246+
expect(sheet.C1.w).toBe('14:30')
245247
})
246248
})

‎apps/sim/lib/file-parsers/sheet-display-text.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function isGeneralFormat(format: unknown): boolean {
126126
* Elapsed-time formats (`[h]:mm`, `[mm]:ss`) are durations, not moments;
127127
* `cellDates` still parses them into a `Date`, so their `w` (`30:00`) is kept.
128128
*
129-
* A date whose format is longer than Excel allows is treated as unformatted.
129+
* A date whose format is longer than Excel allows is rendered as unformatted.
130130
*
131131
* A number with no format at all is treated as General too. Every other
132132
* number keeps the text the file rendered for it, so a LibreOffice workbook
@@ -154,12 +154,12 @@ export function normalizeSheetDisplayText(
154154
if (!cell) continue
155155

156156
if (cell.t === 'd' && cell.v instanceof Date) {
157-
const format =
158-
typeof cell.z === 'string' && cell.z.length <= MAX_NUMBER_FORMAT_LENGTH
159-
? cell.z
160-
: undefined
157+
const format = typeof cell.z === 'string' ? cell.z : undefined
161158
if (format !== undefined && ELAPSED_TOKEN.test(format)) continue
162-
cell.w = isoDateText(cell.v, format)
159+
cell.w = isoDateText(
160+
cell.v,
161+
format !== undefined && format.length <= MAX_NUMBER_FORMAT_LENGTH ? format : undefined
162+
)
163163
} else if (cell.t === 'n' && typeof cell.v === 'number' && isGeneralFormat(cell.z)) {
164164
cell.w = generalNumberText(cell.v)
165165
}

0 commit comments

Comments
 (0)