diff --git a/package.json b/package.json index c9f8f42..d38b8d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xlstream", - "version": "2.5.3", + "version": "2.5.4", "description": "Turns XLSX into a readable stream.", "main": "lib/index", "types": "lib/index", diff --git a/src/index.ts b/src/index.ts index 6a5d6da..4db905f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -139,6 +139,7 @@ function getTransform(formats: (string | number)[], strings: string[], dict?: IM numFormat = numberFormat[numFormat]; } if (typeof numFormat === 'string') { + numFormat = numFormat.replace(/[Hh]{2}/g, 'hh'); value = numfmt.format(numFormat, value); } else { value = ssf.format(numFormat, value); diff --git a/tests/__snapshots__/xlsx-stream.spec.ts.snap b/tests/__snapshots__/xlsx-stream.spec.ts.snap index 2b91f0d..4e20a4c 100644 --- a/tests/__snapshots__/xlsx-stream.spec.ts.snap +++ b/tests/__snapshots__/xlsx-stream.spec.ts.snap @@ -162,6 +162,53 @@ Array [ ] `; +exports[`correctly formats Hh hours in date 1`] = ` +Array [ + Object { + "formatted": Object { + "arr": Array [ + "Date", + ], + "obj": Object { + "A": "Date", + }, + }, + "header": Array [], + "processedSheetSize": 1480, + "raw": Object { + "arr": Array [ + "Date", + ], + "obj": Object { + "A": "Date", + }, + }, + "totalSheetSize": 1480, + }, + Object { + "formatted": Object { + "arr": Array [ + "2024-05-25 10:56:55", + ], + "obj": Object { + "A": "2024-05-25 10:56:55", + }, + }, + "header": Array [], + "processedSheetSize": 1480, + "raw": Object { + "arr": Array [ + 45437.456192129626, + ], + "obj": Object { + "A": 45437.456192129626, + }, + }, + "totalSheetSize": 1480, + }, +] +`; + exports[`correctly handles custom format 1`] = ` Array [ Object { diff --git a/tests/assets/incorrect-hours-format.xlsx b/tests/assets/incorrect-hours-format.xlsx new file mode 100644 index 0000000..e350507 Binary files /dev/null and b/tests/assets/incorrect-hours-format.xlsx differ diff --git a/tests/xlsx-stream.spec.ts b/tests/xlsx-stream.spec.ts index 1ce5611..b23a474 100644 --- a/tests/xlsx-stream.spec.ts +++ b/tests/xlsx-stream.spec.ts @@ -393,4 +393,17 @@ it('reads XLSX file with styles.xml tags prefixed with `x:` correctly', async (d expect(data).toMatchSnapshot(); done(); }) +}); + +it('correctly formats Hh hours in date', async (done) => { + const data: any = []; + const stream = await getXlsxStream({ + filePath: './tests/assets/incorrect-hours-format.xlsx', + sheet: 0, + }); + stream.on('data', x => data.push(x)); + stream.on('end', () => { + expect(data).toMatchSnapshot(); + done(); + }) }); \ No newline at end of file