({
take: [
{ type: "number", label: "Year" },
{ type: "number", label: "Month", min: 1, max: 12 },
{ type: "number", label: "Day", min: 1, max: 31 },
],
make: ([y, m, d]) => {
const d0 = new Date()
const d1 = new Date().setFullYear(y, m - 1, d)
const delta = Math.abs((d1 - d0) / (1000 * 60 * 60 * 24 * 7))
const major = Math.floor(delta)
const minor = Math.round((delta % 1) * 7)
const date = new Intl.DateTimeFormat(undefined, {
year: "numeric",
day: "numeric",
month: "long",
weekday: "long",
era: y < 1200 ? "short" : undefined,
}).format(d1)
const majNoun = "week" + (major === 1 ? "" : "s")
const minNoun = "day" + (minor === 1 ? "" : "s")
const count = [
major > 0 && `${major} ${majNoun}`,
minor > 0 && `${minor} ${minNoun}`,
]
.filter((f) => f)
.join(" and ")
let title, body
if (d1 - d0 === 0) {
title = `It's here!`
body = `It's ${date} today!`
} else if (d1 - d0 > 0) {
title = `${major} ${majNoun} left`
body = `${date} is in <br>${count}.`
} else {
title = `${major} ${majNoun} ago`
body = `${date} was <br>${count} ago.`
}
return {
type: "card",
title,
body,
}
},
})