sunset theme following

This commit is contained in:
k
2026-09-22 08:06:47 +02:00
parent 2592c92f66
commit 76f1834712
8 changed files with 88 additions and 11 deletions
+12
View File
@@ -35,6 +35,8 @@ const en = {
"common.theme": "Theme",
"common.themeAuto": "Auto",
"common.themeAutoFull": "Auto (follows system)",
"common.themeSunset": "Sunset",
"common.themeSunsetFull": "Sunset (follows local time)",
"common.light": "Light",
"common.dark": "Dark",
"common.saveFailed": "Save failed",
@@ -585,6 +587,8 @@ const es: Dict = {
"common.theme": "Tema",
"common.themeAuto": "Automático",
"common.themeAutoFull": "Automático (según el sistema)",
"common.themeSunset": "Puesta de sol",
"common.themeSunsetFull": "Puesta de sol (hora local)",
"common.light": "Claro",
"common.dark": "Oscuro",
"common.saveFailed": "No se pudo guardar",
@@ -1125,6 +1129,8 @@ const fr: Dict = {
"common.theme": "Thème",
"common.themeAuto": "Auto",
"common.themeAutoFull": "Auto (suit le système)",
"common.themeSunset": "Coucher de soleil",
"common.themeSunsetFull": "Coucher de soleil (heure locale)",
"common.light": "Clair",
"common.dark": "Sombre",
"common.saveFailed": "Échec de l'enregistrement",
@@ -1665,6 +1671,8 @@ const ru: Dict = {
"common.theme": "Тема",
"common.themeAuto": "Авто",
"common.themeAutoFull": "Авто (как в системе)",
"common.themeSunset": "Закат",
"common.themeSunsetFull": "Закат (местное время)",
"common.light": "Светлая",
"common.dark": "Тёмная",
"common.saveFailed": "Не удалось сохранить",
@@ -2192,6 +2200,8 @@ const it: Dict = {
"common.theme": "Tema",
"common.themeAuto": "Auto",
"common.themeAutoFull": "Auto (segue il sistema)",
"common.themeSunset": "Tramonto",
"common.themeSunsetFull": "Tramonto (ora locale)",
"common.light": "Chiaro",
"common.dark": "Scuro",
"common.saveFailed": "Salvataggio non riuscito",
@@ -2725,6 +2735,8 @@ const pt: Dict = {
"common.theme": "Tema",
"common.themeAuto": "Auto",
"common.themeAutoFull": "Auto (segue o sistema)",
"common.themeSunset": "Pôr do sol",
"common.themeSunsetFull": "Pôr do sol (hora local)",
"common.light": "Claro",
"common.dark": "Escuro",
"common.saveFailed": "Falha ao guardar",
+39
View File
@@ -0,0 +1,39 @@
/**
* "Sunset" theme: follows the browser's local time instead of the OS setting.
* Day (07:00–19:00 local) -> light, night -> dark. No geolocation needed.
*/
export const SOLAR_DAY_START_HOUR = 7;
export const SOLAR_NIGHT_START_HOUR = 19;
/** True when the given local time falls in the night range (dark theme). */
export function isSolarDark(now: Date = new Date()): boolean {
const h = now.getHours();
return h < SOLAR_DAY_START_HOUR || h >= SOLAR_NIGHT_START_HOUR;
}
/** Milliseconds from `now` until the next 07:00 / 19:00 local boundary. */
export function msUntilNextSolarSwitch(now: Date = new Date()): number {
const next = new Date(now);
const h = now.getHours();
if (h < SOLAR_DAY_START_HOUR) {
next.setHours(SOLAR_DAY_START_HOUR, 0, 0, 0);
} else if (h < SOLAR_NIGHT_START_HOUR) {
next.setHours(SOLAR_NIGHT_START_HOUR, 0, 0, 0);
} else {
next.setDate(next.getDate() + 1);
next.setHours(SOLAR_DAY_START_HOUR, 0, 0, 0);
}
return Math.max(1000, next.getTime() - now.getTime());
}
/** Resolve a stored theme value to dark/light. `sunset` uses local time. */
export function resolveThemeDark(theme: string, now: Date = new Date()): boolean {
if (theme === "dark") return true;
if (theme === "light") return false;
if (theme === "sunset") return isSolarDark(now);
if (typeof window !== "undefined" && window.matchMedia) {
return window.matchMedia("(prefers-color-scheme: dark)").matches;
}
return false;
}