Skip to content

Commit

Permalink
feat: real date representation
Browse files Browse the repository at this point in the history
  • Loading branch information
TomyCesaille committed Sep 24, 2024
1 parent ed48aa4 commit 7894fa4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = {
quotes: ["error", "double"],
semi: ["error", "always"],
"comma-dangle": ["error", "always-multiline"],
"@typescript-eslint/no-unused-vars": ["error", { varsIgnorePattern: "^_" }],
},
ignorePatterns: ["dist/"],
};
60 changes: 30 additions & 30 deletions src/tests/e2e/__snapshots__/e2e-testing.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 0,
"sequence": 1,
"datetime": "20240624-010850",
"datetime": "2024-06-23T23:08:50.000Z",
"temperature": "-10.1C",
"fileName": "Light_FOV_120.0s_Bin1_S_gain0_20240624-010850_-10.1C_0001.fit",
"extension": "fit",
Expand All @@ -42,7 +42,7 @@ exports[`E2E should be neat 2`] = `
"filter": "L",
"gain": 0,
"sequence": 1,
"datetime": "20240308-155722",
"datetime": "2024-03-08T14:57:22.000Z",
"temperature": "-10.0C",
"fileName": "Dark_120.0s_Bin1_L_gain0_20240308-155722_-10.0C_0001.fit",
"extension": "fit",
Expand All @@ -60,7 +60,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 1,
"datetime": "20240511-094304",
"datetime": "2024-05-11T07:43:04.000Z",
"temperature": "-10.5C",
"fileName": "Flat_1.0ms_Bin1_S_gain100_20240511-094304_-10.5C_0001.fit",
"extension": "fit",
Expand All @@ -76,7 +76,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 2,
"datetime": "20240511-094305",
"datetime": "2024-05-11T07:43:05.000Z",
"temperature": "-10.0C",
"fileName": "Flat_1.0ms_Bin1_S_gain100_20240511-094305_-10.0C_0002.fit",
"extension": "fit",
Expand All @@ -92,7 +92,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 3,
"datetime": "20240511-094306",
"datetime": "2024-05-11T07:43:06.000Z",
"temperature": "-10.5C",
"fileName": "Flat_1.0ms_Bin1_S_gain100_20240511-094306_-10.5C_0003.fit",
"extension": "fit",
Expand All @@ -110,7 +110,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 1,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0001.fit",
"extension": "fit",
Expand All @@ -126,7 +126,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 2,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0002.fit",
"extension": "fit",
Expand All @@ -142,7 +142,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 3,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0003.fit",
"extension": "fit",
Expand Down Expand Up @@ -171,7 +171,7 @@ exports[`E2E should be neat 2`] = `
"filter": "H",
"gain": 0,
"sequence": 1,
"datetime": "20240624-010850",
"datetime": "2024-06-23T23:08:50.000Z",
"temperature": "-10.1C",
"fileName": "Light_FOV_60.0s_Bin1_H_gain0_20240624-010850_-10.1C_0001.fit",
"extension": "fit",
Expand All @@ -187,7 +187,7 @@ exports[`E2E should be neat 2`] = `
"filter": "H",
"gain": 0,
"sequence": 2,
"datetime": "20240624-010851",
"datetime": "2024-06-23T23:08:51.000Z",
"temperature": "-10.1C",
"fileName": "Light_FOV_60.0s_Bin1_H_gain0_20240624-010851_-10.1C_0002.fit",
"extension": "fit",
Expand All @@ -203,7 +203,7 @@ exports[`E2E should be neat 2`] = `
"filter": "H",
"gain": 0,
"sequence": 3,
"datetime": "20240624-010852",
"datetime": "2024-06-23T23:08:52.000Z",
"temperature": "-10.1C",
"fileName": "Light_FOV_60.0s_Bin1_H_gain0_20240624-010852_-10.1C_0003.fit",
"extension": "fit",
Expand All @@ -221,7 +221,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 0,
"sequence": 1,
"datetime": "20240308-155722",
"datetime": "2024-03-08T14:57:22.000Z",
"temperature": "-10.0C",
"fileName": "Dark_60.0s_Bin1_gain0_20240308-155722_-10.0C_0001.fit",
"extension": "fit",
Expand All @@ -239,7 +239,7 @@ exports[`E2E should be neat 2`] = `
"filter": "H",
"gain": 100,
"sequence": 1,
"datetime": "20240511-094306",
"datetime": "2024-05-11T07:43:06.000Z",
"temperature": "-10.5C",
"fileName": "Flat_1.0ms_Bin1_H_gain100_20240511-094306_-10.5C_0001.fit",
"extension": "fit",
Expand All @@ -255,7 +255,7 @@ exports[`E2E should be neat 2`] = `
"filter": "H",
"gain": 100,
"sequence": 2,
"datetime": "20240511-094306",
"datetime": "2024-05-11T07:43:06.000Z",
"temperature": "-10.5C",
"fileName": "Flat_1.0ms_Bin1_H_gain100_20240511-094306_-10.5C_0002.fit",
"extension": "fit",
Expand All @@ -271,7 +271,7 @@ exports[`E2E should be neat 2`] = `
"filter": "H",
"gain": 100,
"sequence": 3,
"datetime": "20240511-094306",
"datetime": "2024-05-11T07:43:06.000Z",
"temperature": "-10.5C",
"fileName": "Flat_1.0ms_Bin1_H_gain100_20240511-094306_-10.5C_0003.fit",
"extension": "fit",
Expand All @@ -289,7 +289,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 1,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0001.fit",
"extension": "fit",
Expand All @@ -305,7 +305,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 2,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0002.fit",
"extension": "fit",
Expand All @@ -321,7 +321,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 3,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0003.fit",
"extension": "fit",
Expand Down Expand Up @@ -350,7 +350,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 1,
"datetime": "20240624-010850",
"datetime": "2024-06-23T23:08:50.000Z",
"temperature": "-10.1C",
"fileName": "Light_FOV_60.0s_Bin1_S_gain100_20240624-010850_-10.1C_0001.fit",
"extension": "fit",
Expand All @@ -366,7 +366,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 2,
"datetime": "20240624-010851",
"datetime": "2024-06-23T23:08:51.000Z",
"temperature": "-10.1C",
"fileName": "Light_FOV_60.0s_Bin1_S_gain100_20240624-010851_-10.1C_0002.fit",
"extension": "fit",
Expand All @@ -382,7 +382,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 3,
"datetime": "20240624-010852",
"datetime": "2024-06-23T23:08:52.000Z",
"temperature": "-10.1C",
"fileName": "Light_FOV_60.0s_Bin1_S_gain100_20240624-010852_-10.1C_0003.fit",
"extension": "fit",
Expand All @@ -400,7 +400,7 @@ exports[`E2E should be neat 2`] = `
"filter": "L",
"gain": 100,
"sequence": 1,
"datetime": "20240308-155722",
"datetime": "2024-03-08T14:57:22.000Z",
"temperature": "-10.0C",
"fileName": "Dark_60.0s_Bin1_L_gain100_20240308-155722_-10.0C_0001.fit",
"extension": "fit",
Expand All @@ -416,7 +416,7 @@ exports[`E2E should be neat 2`] = `
"filter": "L",
"gain": 100,
"sequence": 2,
"datetime": "20240308-155723",
"datetime": "2024-03-08T14:57:23.000Z",
"temperature": "-10.0C",
"fileName": "Dark_60.0s_Bin1_L_gain100_20240308-155723_-10.0C_0002.fit",
"extension": "fit",
Expand All @@ -432,7 +432,7 @@ exports[`E2E should be neat 2`] = `
"filter": "L",
"gain": 100,
"sequence": 3,
"datetime": "20240308-155724",
"datetime": "2024-03-08T14:57:24.000Z",
"temperature": "-10.0C",
"fileName": "Dark_60.0s_Bin1_L_gain100_20240308-155724_-10.0C_0003.fit",
"extension": "fit",
Expand All @@ -450,7 +450,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 1,
"datetime": "20240511-094304",
"datetime": "2024-05-11T07:43:04.000Z",
"temperature": "-10.5C",
"fileName": "Flat_1.0ms_Bin1_S_gain100_20240511-094304_-10.5C_0001.fit",
"extension": "fit",
Expand All @@ -466,7 +466,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 2,
"datetime": "20240511-094305",
"datetime": "2024-05-11T07:43:05.000Z",
"temperature": "-10.0C",
"fileName": "Flat_1.0ms_Bin1_S_gain100_20240511-094305_-10.0C_0002.fit",
"extension": "fit",
Expand All @@ -482,7 +482,7 @@ exports[`E2E should be neat 2`] = `
"filter": "S",
"gain": 100,
"sequence": 3,
"datetime": "20240511-094306",
"datetime": "2024-05-11T07:43:06.000Z",
"temperature": "-10.5C",
"fileName": "Flat_1.0ms_Bin1_S_gain100_20240511-094306_-10.5C_0003.fit",
"extension": "fit",
Expand All @@ -500,7 +500,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 1,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0001.fit",
"extension": "fit",
Expand All @@ -516,7 +516,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 2,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0002.fit",
"extension": "fit",
Expand All @@ -532,7 +532,7 @@ exports[`E2E should be neat 2`] = `
"filter": null,
"gain": 100,
"sequence": 3,
"datetime": "20230910-101133",
"datetime": "2023-09-10T08:11:33.000Z",
"temperature": "-9.8C",
"fileName": "Bias_1.0ms_Bin1_gain100_20230910-101133_-9.8C_0003.fit",
"extension": "fit",
Expand Down
3 changes: 1 addition & 2 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ export type FileImageSpec = ImageSpec & {
*/
projectDirectory: string;

// TODO. Change to datetime.
/**
* Recorded time.
*/
datetime: string;
datetime: Date;
/**
* Sequence number: 1, 60, etc...
*/
Expand Down
22 changes: 21 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const getFileImageSpecFromFilename = (
gain: parseInt(match.groups.gain, 10),

sequence: parseInt(match.groups.sequence, 10),
datetime: match.groups.datetime,
datetime: parseDate(match.groups.datetime),
temperature: match.groups.temperature,

fileName: fileFS.name,
Expand Down Expand Up @@ -102,6 +102,26 @@ export const getFileImageSpecFromFilename = (
}
};

const parseDate = (datetimeString: string): Date => {
const datetimeRegex = /(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})/;
const matchResult = datetimeString.match(datetimeRegex);

if (matchResult) {
const [_, year, month, day, hour, minute, second] = matchResult;
const parsedDate = new Date(
parseInt(year, 10),
parseInt(month, 10) - 1, // Month is zero-based in JavaScript Date
parseInt(day, 10),
parseInt(hour, 10),
parseInt(minute, 10),
parseInt(second, 10),
);
return parsedDate;
} else {
throw new Error(`Invalid datetime string: ${datetimeString}`);
}
};

export const copyFileToProject = (file: FileImageSpec) => {
if (!fs.existsSync(file.projectDirectory)) {
fs.mkdirSync(file.projectDirectory, { recursive: true });
Expand Down

0 comments on commit 7894fa4

Please sign in to comment.