@cloudstrytech/validations 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/csv/csvValidator.js
CHANGED
|
@@ -5,6 +5,7 @@ import { isValidEmail } from "../validators/emailValidator.js";
|
|
|
5
5
|
import { isValidIndianMobile } from "../validators/mobileValidator.js";
|
|
6
6
|
import { isValidDate } from "../validators/dateValidator.js";
|
|
7
7
|
import { normalizeDate } from "../validators/normalizeDate.js";
|
|
8
|
+
import { normalizeExcelDate } from "../validators/normalizeExcelDate.js";
|
|
8
9
|
|
|
9
10
|
/* Normalize CSV headers */
|
|
10
11
|
function normalizeKey(key = "") {
|
|
@@ -80,7 +81,7 @@ export async function validateCSV(csvInput) {
|
|
|
80
81
|
...row,
|
|
81
82
|
"issuedate-b1":
|
|
82
83
|
messages.length === 0
|
|
83
|
-
? normalizeDate(normalizedRow["issuedate-b1"])
|
|
84
|
+
? normalizeDate(normalizeExcelDate(normalizedRow["issuedate-b1"]))
|
|
84
85
|
: row["issuedate-b1"],
|
|
85
86
|
|
|
86
87
|
__status: messages.length > 0 ? "ERROR" : "SUCCESS",
|
package/src/csv/parseCsv.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert Excel date OR string → DD/MM/YYYY
|
|
3
|
+
*/
|
|
4
|
+
export function normalizeExcelDate(value) {
|
|
5
|
+
// Excel serial date (number)
|
|
6
|
+
if (typeof value === "number") {
|
|
7
|
+
const excelEpoch = new Date(Date.UTC(1899, 11, 30));
|
|
8
|
+
const date = new Date(excelEpoch.getTime() + value * 86400000);
|
|
9
|
+
|
|
10
|
+
const dd = String(date.getUTCDate()).padStart(2, "0");
|
|
11
|
+
const mm = String(date.getUTCMonth() + 1).padStart(2, "0");
|
|
12
|
+
const yyyy = date.getUTCFullYear();
|
|
13
|
+
|
|
14
|
+
return `${dd}/${mm}/${yyyy}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Already string → trust validator
|
|
18
|
+
return value;
|
|
19
|
+
}
|