mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 10:05:03 +00:00
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:
@@ -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);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user