cineclub-site/front/composables/strUtils.ts

34 lines
927 B
TypeScript
Raw Normal View History

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}`
}
2022-07-13 01:02:23 +02:00
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)
2022-07-13 01:02:23 +02:00
return `${strDate}, ${time}`
},
}