vuestic-ui
Version:
Vue 3 UI Framework
39 lines (38 loc) • 1.02 kB
JavaScript
const useTimeFormatter = (props) => {
const formatDate = (date) => {
if (!date) {
return "";
}
if (props.ampm) {
return date.toLocaleTimeString("en-US");
}
return date.toLocaleTimeString("en-GB");
};
const sliceTime = (time, start, end) => time.split(":").slice(start, end).join(":");
const formatWithView = (date) => {
if (props.view === "seconds") {
return formatDate(date);
}
const [time, period] = formatDate(date).split(" ");
if (props.view === "minutes") {
if (!period) {
return sliceTime(time, 0, 2);
}
return [sliceTime(time, 0, 2), period].join(" ");
}
if (props.view === "hours") {
if (!period) {
return sliceTime(time, 0, 1);
}
return [sliceTime(time, 0, 1), period].join(" ");
}
return "";
};
return {
format: (date) => props.format ? props.format(date) : formatWithView(date)
};
};
export {
useTimeFormatter as u
};
//# sourceMappingURL=time-text-formatter.js.map