mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
dates stuff
This commit is contained in:
@@ -38,22 +38,29 @@ const parseNumberOrThrow = (value: string, label: string): number => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const parseDateOrThrow = (value: string, label: string): string => {
|
const parseDateOrThrow = (value: string, label: string): string => {
|
||||||
const date = new Date(value);
|
const [datePart, timePart] = value.split(" ");
|
||||||
|
const [day, month, year] = datePart.split("/").map(Number);
|
||||||
|
const [hours, minutes, seconds] = timePart.split(":").map(Number);
|
||||||
|
const date = new Date(year, month - 1, day, hours, minutes, seconds);
|
||||||
|
|
||||||
if (isNaN(date.getTime())) {
|
if (isNaN(date.getTime())) {
|
||||||
throw new Error(`Error with ${label}: ${value}`);
|
throw new Error(`Error with ${label}: ${value}`);
|
||||||
}
|
}
|
||||||
const day = String(date.getDate()).padStart(2, "0");
|
const stringDay = String(date.getDate()).padStart(2, "0");
|
||||||
const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-based
|
const stringMonth = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-based
|
||||||
const year = date.getFullYear();
|
const stringYear = date.getFullYear();
|
||||||
const hours = String(date.getHours()).padStart(2, "0");
|
const stringHours = String(date.getHours()).padStart(2, "0");
|
||||||
const minutes = String(date.getMinutes()).padStart(2, "0");
|
const stringMinutes = String(date.getMinutes()).padStart(2, "0");
|
||||||
const seconds = String(date.getSeconds()).padStart(2, "0");
|
const stringSeconds = String(date.getSeconds()).padStart(2, "0");
|
||||||
|
|
||||||
return `${day}/${month}/${year} ${hours}:${minutes}:${seconds}`;
|
return `${stringDay}/${stringMonth}/${stringYear} ${stringHours}:${stringMinutes}:${stringSeconds}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseDateOrNull = (value: string): string | undefined => {
|
const parseDateOrNull = (value: string): string | undefined => {
|
||||||
const date = new Date(value);
|
const [datePart, timePart] = value.split(" ");
|
||||||
|
const [day, month, year] = datePart.split("/").map(Number);
|
||||||
|
const [hours, minutes, seconds] = timePart.split(":").map(Number);
|
||||||
|
const date = new Date(year, month - 1, day, hours, minutes, seconds);
|
||||||
return isNaN(date.getTime()) ? undefined : date.toISOString();
|
return isNaN(date.getTime()) ? undefined : date.toISOString();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user