Skip to content
AtsuraeDownload

Development sign-in

Only on a local server with DEV_AUTH. Enter any account name.

Countdown

Two text options hold the event’s name and date. The script works out the days between today and that date, and handles today, the past and a badly typed date.

The Countdown widget

Download Countdown.atsuraewidget and drop it on the Widgets section of your Library, or create the files yourself:

Countdown.atsuraewidget/widget.json
{
"$schema": "https://atsurae.app/docs/schema/widget.schema.json",
"formatVersion": 2,
"id": "countdown",
"name": "Countdown",
"summary": "Days left until a date you choose.",
"author": "Atsurae",
"version": "1.0",
"options": [
{ "key": "event", "label": "Event", "kind": "text", "defaultValue": "New Year" },
{ "key": "date", "label": "Date (YYYY-MM-DD)", "kind": "text", "defaultValue": "2027-01-01" }
],
"script": { "file": "script.js", "updateEvery": "minute" },
"elements": [
{ "text": "{script.number}", "font": { "family": "Michroma", "size": 0.08 } },
{ "text": "{script.label|upper}", "font": { "family": "Michroma", "size": 0.014 }, "tracking": 0.3, "opacity": 0.8, "offset": [0, 0.065] }
]
}
Countdown.atsuraewidget/script.js
const DAY = 24 * 60 * 60 * 1000;
function update(context) {
const { event, date } = context.options;
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date.trim());
if (!match) {
return { number: "?", label: "Set the date as YYYY-MM-DD" };
}
// Midnight at the start of that day, in your time zone.
const target = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3]));
const today = new Date(context.now.getFullYear(), context.now.getMonth(), context.now.getDate());
const days = Math.round((target - today) / DAY);
if (days > 1) return { number: String(days), label: `days until ${event}` };
if (days === 1) return { number: "1", label: `day until ${event}` };
if (days === 0) return { number: "🎉", label: `${event} is today` };
return { number: String(-days), label: `days since ${event}` };
}
  • The date is checked with a regular expression, so a typo shows Set the date as YYYY-MM-DD instead of an error.
  • new Date(year, month - 1, day) makes midnight in your time zone (months start at 0 in JavaScript). Comparing against today’s midnight gives whole days, without daylight-saving surprises; Math.round absorbs the 23- or 25-hour days.
  • Every branch returns both number and label, so neither token is ever left over from a previous run.
  • Show hours and minutes when it’s less than a day away (and switch updateEvery to "second" if you show seconds).
  • Add a progress ring from a start date to the event.
  • Add a choice option for a repeating yearly event, like a birthday.