A "whose name day is it today?" widget from an open JSON file

2026-12-03来源 dev.toEnglish

In Lithuania (and several other European countries) people celebrate their name day – the calendar day assigned to their first name. A small "today's name days" line is a nice touch for school sites, intranets or greeting apps. Here is a dependency-free version that uses an openly licensed JSON file.

The data

The file is a single object keyed by MM-DD, with an array of names for each of the 366 days (29 February included):

{ "01-01": ["Arvaidas", "Arvaidė", "Eufrozija", "Eufrozina", ...], "01-02": ["Bazilijus", "Fulgentas", "Gailutė", "Mažvydas", ...] } 

It is published under CC BY-SA 4.0 at https://dovanasuvardu.lt/duomenys/vardadieniai.json (there is also a long-format CSV, one row per name).

The widget

<p id="name-days">Loading…</p> <script> function todayInLithuania() { // name days follow the local date, not UTC const parts = new Intl.DateTimeFormat("en-CA", { timeZone: "Europe/Vilnius", month: "2-digit", day: "2-digit" }).formatToParts(new Date()); const get = t => parts.find(p => p.type === t).value; return `${get("month")}-${get("day")}`; } fetch("https://dovanasuvardu.lt/duomenys/vardadieniai.json") .then(r => r.json()) .then(cal => { const names = cal[todayInLithuania()] || []; document.getElementById("name-days").textContent = names.length ? `Today's name days: ${names.join(", ")}` : "No name days today"; }); </script> 

Two details matter:

  1. Use the local time zone. A visitor in New York at 23:00 on 3 December is already on 4 December in Vilnius. Intl.DateTimeFormat with timeZone: "Europe/Vilnius" avoids the off-by-one.
  2. Cache it. The JSON is ~50 KB and changes rarely, so store it in localStorage with a date and refetch once a day if you embed it on a busy page.

Finding a name instead of a day

Some names have several dates (Marija has four, Tomas seven), so the reverse lookup returns an array:

const datesFor = (cal, name) => Object.keys(cal).filter(d => cal[d].includes(name)); 

Credit

If you use the data, link back to the source: the Lithuanian name day calendar. A ready-made human version with today's and tomorrow's names is on the name days today page.

原文:https://www.a8q9.cn/en/article/a-whose-name-day-is-it-today-widget-from-an-open-json-file-5e791b.html

相关文章