Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TECHDEBT: XLSX Date / Time #1466

Merged
merged 16 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,959 changes: 995 additions & 1,964 deletions api/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"uuid": "^8.3.2",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^5.0.0",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.19.3/xlsx-0.19.3.tgz",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
24 changes: 24 additions & 0 deletions api/src/__mocks__/xlsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import xlsx from 'xlsx';
import { DEFAULT_XLSX_SHEET_NAME } from '../utils/xlsx-utils/worksheet-utils';

/**
* Returns a mock XLSX workbook buffer.
*
* Note: The keys of the record will be used as the worksheet headers.
*
* @param {Record<string, any>[]} data The data to inject into the workbook.
* @return {*} {Buffer}
*/
export const getMockXLSXWorkbookBuffer = (data: Record<string, any>[]): Buffer => {
// Create a new empty workbook
const workbook = xlsx.utils.book_new();

// Create a new worksheet with the array of records
const worksheet = xlsx.utils.json_to_sheet(data);

// Inject the worksheet data into the workbook with the default name
xlsx.utils.book_append_sheet(workbook, worksheet, DEFAULT_XLSX_SHEET_NAME);

// Convert the workbook to a xlsx buffer
return xlsx.write(workbook, { bookType: 'xlsx', type: 'buffer' });
};
16 changes: 12 additions & 4 deletions api/src/constants/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
*
* 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
*/
export const DefaultDateFormat = 'YYYY-MM-DD'; // 2020-01-05
export const DefaultDateFormat = 'YYYY-MM-DD'; // 2020-01-15

export const DefaultDateFormatReverse = 'DD-MM-YYYY'; // 05-01-2020
export const DefaultDateFormatReverse = 'DD-MM-YYYY'; // 15-01-2020

export const AltDateFormat = 'YYYY/MM/DD'; // 2020/01/05
export const AltDateFormat = 'YYYY/MM/DD'; // 2020/01/15

export const AltDateFormatReverse = 'DD/MM/YYYY'; // 05/01/2020
export const AltDateFormatReverse = 'DD/MM/YYYY'; // 15/01/2020

export const USDefaultDateFormat = 'YYYY-DD-MM'; // 2020-15-01

export const USDefaultDateFormatReverse = 'MM-DD-YYYY'; // 01-15-2020

export const USAltDateFormat = 'MM/DD/YYYY'; // 01/15/2020

export const USAltDateFormatReverse = 'YYYY/DD/MM'; // 2020/15/01

/*
* Time formats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { importCSV } from '../import-csv';
import { ImportMeasurementsStrategy } from './import-measurements-strategy';

describe('importMeasurementsStrategy', () => {
describe('importCSV', () => {
beforeEach(() => {
sinon.restore();
});
beforeEach(() => {
sinon.restore();
});

describe('importCSV', () => {
it('should import the csv file correctly', async () => {
const worksheet = {
A1: { t: 's', v: 'ALIAS' },
Expand All @@ -31,7 +31,7 @@ describe('importMeasurementsStrategy', () => {
D2: { t: 'n', w: '2', v: 2 },
E2: { t: 'n', w: '0', v: 'good' },
A3: { t: 's', v: 'carlita' },
B3: { z: 'yyyy-mm-dd', t: 'd', v: new Date('2024-10-10T07:00:00.000Z'), w: '2024-10-10' },
B3: { z: worksheetUtils.CUSTOM_XLSX_DATE_FORMAT, t: 'n', v: 54321, w: '2024-10-10' },
C3: { t: 's', v: '10:10:12' },
D3: { t: 'n', w: '2', v: 2 },
E3: { t: 'n', w: '0', v: 'good' },
Expand Down
285 changes: 0 additions & 285 deletions api/src/utils/media/csv/csv-file.test.ts

This file was deleted.

Loading
Loading