amplify-codegen-ui
amplify-codegen-ui copied to clipboard
`convertToLocal` incorrectly parses dates between midnight and 1am
Given the following code
const convertToLocal = (date) => {
const df = new Intl.DateTimeFormat("default", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
calendar: "iso8601",
numberingSystem: "latn",
hour12: false,
});
const parts = df.formatToParts(date).reduce((acc, part) => {
acc[part.type] = part.value;
return acc;
}, {});
return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}`;
};
If I pass in a date like 2023-03-06T08:58:00.000Z, It incorrectly treats the hour as 24 instead of 0. This leads to an invalid date of 2023-03-06T24:58
The fix here might be to switch from hour12: false to hourCycle: 'h23' to display the hours from 00:00 to 23:59.