fix date formatting and parsing logic

- Support time formatting in `formatDate` with `time` option.
- Improve parsing in `ISOToDate` to handle time information or date-only strings.
This commit is contained in:
2025-08-11 15:51:46 +02:00
parent ebc2921696
commit 90d3bf32e6
3 changed files with 33 additions and 5 deletions

View File

@@ -37,8 +37,13 @@ export const ISOToDate = (str: string | null): Date | null => {
return null;
}
const [year, month, day] = str.split("-").map((p) => parseInt(p));
// If the string already contains time info, use it directly
if (str.includes('T') || str.includes(' ')) {
return new Date(str);
}
// Otherwise, parse date only
const [year, month, day] = str.split("-").map((p) => parseInt(p));
return new Date(year, month - 1, day, 0, 0, 0, 0);
};