How many days to Christmas?

Calculate the number of days to wait before Christmas is here.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
export const take = [{ type: "date" }]

export const make = (eventDate) => {
  if (!eventDate) return

  const todayDate = new Date()

  const dayMs = 1000 * 60 * 60 * 24
  const delta = Math.abs(Math.round((eventDate - todayDate) / dayMs))

  const days = new Intl.NumberFormat().format(delta)

  const date = new Intl.DateTimeFormat(undefined, {
    year: "numeric",
    day: "numeric",
    month: "long",
    weekday: "long",
    era: eventDate.getFullYear() < 1200 ? "short" : undefined,
  }).format(eventDate)

  const isOrAre = delta === 1 ? "is" : "are"
  const dayOrDays = delta === 1 ? "day" : "days"

  let value, detail

  if (delta === 0) {
    value = `It’s here!`
    detail = `It’s ${date} today!`
  } else if (eventDate - todayDate > 0) {
    value = `${days} ${dayOrDays} left`
    detail = `There ${isOrAre} ${days} ${dayOrDays} to go until ${date}!`
  } else {
    value = `${days} ${dayOrDays} ago`
    detail = `It’s been ${days} ${dayOrDays} since ${date}!`
  }

  return {
    type: "card",
    value,
    detail,
  }
}