fix: enhance time utility to validate and return string formatted time in HH:mm

This commit is contained in:
faisolavolut 2025-03-14 11:22:29 +07:00
parent 97e7bf8eec
commit dbe47210ce
1 changed files with 6 additions and 0 deletions

View File

@ -61,6 +61,12 @@ export const formatTime = (date: string | Date) => {
};
export const time = (date: string | Date) => {
if (date === "string") {
const timeFormatRegex = /^([01]\d|2[0-3]):([0-5]\d)$/;
if (timeFormatRegex.test(date)) {
return date; // Jika sudah format HH:mm, langsung return
}
}
if (date instanceof Date || typeof date === "string") {
return day(date).format("HH:mm");
}