diff --git a/api/src/constants/dates.ts b/api/src/constants/dates.ts index 4093dde22c..00722e6895 100644 --- a/api/src/constants/dates.ts +++ b/api/src/constants/dates.ts @@ -1,4 +1,4 @@ -/** +/* * Date formats. * * See BC Gov standards: https://www2.gov.bc.ca/gov/content/governments/services-for-government/policies-procedures/web-content-development-guides/writing-for-the-web/web-style-guide/numbers @@ -11,7 +11,12 @@ export const AltDateFormat = 'YYYY/MM/DD'; // 2020/01/05 export const AltDateFormatReverse = 'DD/MM/YYYY'; // 05/01/2020 -/** +/* * Time formats. */ export const DefaultTimeFormat = 'HH:mm:ss'; // 23:00:00 + +/* + * Datetime formats. + */ +export const DefaultDateTimeFormat = `${DefaultDateFormat}T${DefaultTimeFormat}`; // 2020-01-05T23:00:00 diff --git a/api/src/services/import-services/capture/import-captures-strategy.test.ts b/api/src/services/import-services/capture/import-captures-strategy.test.ts index b7df1d6eff..c5687cac27 100644 --- a/api/src/services/import-services/capture/import-captures-strategy.test.ts +++ b/api/src/services/import-services/capture/import-captures-strategy.test.ts @@ -22,18 +22,18 @@ describe('import-captures-service', () => { I1: { t: 's', v: 'RELEASE_LONGITUDE' }, J1: { t: 's', v: 'RELEASE_COMMENT' }, K1: { t: 's', v: 'CAPTURE_COMMENT' }, - A2: { z: 'm/d/yy', t: 'd', v: '2024-10-10T07:00:00.000Z', w: '10/10/24' }, + A2: { z: 'dd/mm/yyyy', t: 'd', v: new Date('2024-10-11T00:00:00'), w: '11/10/2024' }, B2: { t: 's', v: 'Carl' }, C2: { t: 's', v: '10:10:10' }, D2: { t: 'n', w: '90', v: 90 }, E2: { t: 'n', w: '100', v: 100 }, - F2: { z: 'm/d/yy', t: 'd', v: '2024-10-10T07:00:00.000Z', w: '10/10/24' }, + F2: { t: 's', v: '2024-10-11' }, G2: { t: 's', v: '9:09' }, H2: { t: 'n', w: '90', v: 90 }, I2: { t: 'n', w: '90', v: 90 }, J2: { t: 's', v: 'release' }, K2: { t: 's', v: 'capture' }, - A3: { z: 'm/d/yy', t: 'd', v: '2024-10-10T07:00:00.000Z', w: '10/10/24' }, + A3: { z: 'yyyy-mm-dd', t: 'd', v: new Date('2024-10-11T07:00:00.000Z'), w: '2024-10-11' }, B3: { t: 's', v: 'Carlita' }, D3: { t: 'n', w: '90', v: 90 }, E3: { t: 'n', w: '100', v: 100 }, diff --git a/api/src/utils/xlsx-utils/cell-utils.ts b/api/src/utils/xlsx-utils/cell-utils.ts index 51e0f0a371..bfc8c91daa 100644 --- a/api/src/utils/xlsx-utils/cell-utils.ts +++ b/api/src/utils/xlsx-utils/cell-utils.ts @@ -111,7 +111,7 @@ export function isStringCellWithDateValue(cell: CellObject): false | string { } const matchedFormats = [DefaultDateFormat, DefaultDateFormatReverse, AltDateFormat, AltDateFormatReverse].filter( - (format) => dayjs(String(cell.v), format, true).isValid() + (format) => dayjs(String(cell.v), format).isValid() ); // Ensure only one format matched diff --git a/api/src/utils/xlsx-utils/worksheet-utils.ts b/api/src/utils/xlsx-utils/worksheet-utils.ts index f989c76e5d..38812641ae 100644 --- a/api/src/utils/xlsx-utils/worksheet-utils.ts +++ b/api/src/utils/xlsx-utils/worksheet-utils.ts @@ -53,7 +53,7 @@ export const constructXLSXWorkbook = (file: MediaFile): xlsx.WorkBook => { cellDates: true, cellNF: true, cellHTML: false, - dateNF: 'yyyy-mm-dd HH:mm:ss', + dateNF: '_', raw: false }); };