cineclub-site/front/composables/strUtils.ts

33 lines
927 B
TypeScript

function prettyTime(date: Date) {
const hour = date
.getHours()
.toLocaleString("fr-FR", { minimumIntegerDigits: 2 })
const minute = date
.getMinutes()
.toLocaleString("fr-FR", { minimumIntegerDigits: 2 })
return `${hour}h${minute}`
}
export const prettyDate = {
full(date: Date | string) {
const objDate = typeof date === "string" ? new Date(date) : date
const strDate = objDate.toLocaleDateString("fr-FR", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
})
const time = prettyTime(objDate)
return `${strDate}, ${time}`
},
short(date: Date | string) {
const objDate = typeof date === "string" ? new Date(date) : date
const strDate = objDate.toLocaleDateString("fr-FR", {
weekday: "narrow",
month: "numeric",
day: "numeric",
})
const time = prettyTime(objDate)
return `${strDate}, ${time}`
},
}