Risposta breve
API e widget incorporabile
Endpoint JSON documentati e widget ISO privo di tracciamento.
Risposta breve
L’API convalida gli input e restituisce codici stabili; il widget non usa font esterni.
Come funziona
CORS è restrittivo per impostazione predefinita e il contratto è disponibile in OpenAPI.
JavaScript: data senza spostamento di fuso
La ricetta completa accetta YYYY-MM-DD dal 1900 al 2100, rifiuta giorni impossibili e calcola in UTC. Per un timestamp, ricava prima la data nel fuso IANA desiderato. 2027-01-01 restituisce { isoYear: 2026, isoWeek: 53, isoWeekday: 5 }.
Eseguito con Node.js 24.19.0, Python 3.14.3 e SQLite 3.53.3. Le ricette mostrate vengono confrontate con il motore per tutte le 73.414 date dal 1900 al 2100 e otto input non validi.
function isoWeekDate(value) {
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value))
throw new RangeError("Use a date in YYYY-MM-DD format");
const [year, month, day] = value.split("-").map(Number);
if (year < 1900 || year > 2100) throw new RangeError("Supported years: 1900–2100");
const date = new Date(Date.UTC(year, month - 1, day));
if (date.toISOString().slice(0, 10) !== value) throw new RangeError("Invalid date");
const isoWeekday = date.getUTCDay() || 7;
date.setUTCDate(date.getUTCDate() + 4 - isoWeekday);
const isoYear = date.getUTCFullYear();
const isoWeek = Math.ceil(((date.getTime() - Date.UTC(isoYear, 0, 1)) / 86400000 + 1) / 7);
return { isoYear, isoWeek, isoWeekday };
}
isoWeekDate("2027-01-01");Python: date.isocalendar()
Python date.isocalendar() restituisce anno ISO, settimana e giorno ISO insieme. La ricetta verifica anche formato e intervallo degli anni. Inserisci una data, non un timestamp.
from datetime import date
def iso_week_date(value):
day = date.fromisoformat(value)
if day.isoformat() != value or not 1900 <= day.year <= 2100:
raise ValueError("Use YYYY-MM-DD, years 1900–2100")
year, week, weekday = day.isocalendar()
return {"isoYear": year, "isoWeek": week, "isoWeekday": weekday}
print(iso_week_date("2027-01-01"))SQLite: %G / %V / %u
SQLite: associa :date come parametro di testo senza concatenare SQL. Abbina %G e %V; %Y e %W non equivalgono all’ISO. WHERE rifiuta date non valide o non normalizzate. Versioni precedenti prive di %G/%V non sono adatte.
SELECT CAST(strftime('%G', :date) AS INTEGER) AS isoYear,
CAST(strftime('%V', :date) AS INTEGER) AS isoWeek,
CAST(strftime('%u', :date) AS INTEGER) AS isoWeekday
WHERE length(:date) = 10
AND :date GLOB '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
AND substr(:date, 1, 4) BETWEEN '1900' AND '2100'
AND date(:date, '+0 days') = :date;Ricette diverse per i dialetti SQL
Questi tre esempi usano le funzioni documentate dai produttori, senza esecuzione locale in PostgreSQL, MySQL o SQL Server. Per 2027-01-01 il risultato atteso è anno ISO 2026 e settimana 53. Verifica la tua versione e il fuso aziendale dei timestamp.
PostgreSQL: ISOYEAR + WEEK
SELECT EXTRACT(ISOYEAR FROM d)::int AS iso_year,
EXTRACT(WEEK FROM d)::int AS iso_week
FROM (VALUES (DATE '2027-01-01')) AS dates(d);MySQL: YEARWEEK(date, 3)
SELECT YEARWEEK('2027-01-01', 3) DIV 100 AS iso_year,
MOD(YEARWEEK('2027-01-01', 3), 100) AS iso_week;SQL Server: iso_week
DECLARE @d date = DATEFROMPARTS(2027, 1, 1);
SELECT CASE
WHEN MONTH(@d) = 1 AND DATEPART(iso_week, @d) >= 52 THEN YEAR(@d) - 1
WHEN MONTH(@d) = 12 AND DATEPART(iso_week, @d) = 1 THEN YEAR(@d) + 1
ELSE YEAR(@d)
END AS iso_year,
DATEPART(iso_week, @d) AS iso_week;