From abbfef15085281645b93f6671980e61720f7ca8f Mon Sep 17 00:00:00 2001 From: Acylation <532117255@qq.com> Date: Tue, 19 Nov 2024 21:52:00 -0500 Subject: [PATCH] Fix platform dependent call on weekInfo --- src/obsidianProjects.d.ts | 7 +++---- src/ui/views/Calendar/calendar.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/obsidianProjects.d.ts b/src/obsidianProjects.d.ts index a18c593a..e80d49b2 100644 --- a/src/obsidianProjects.d.ts +++ b/src/obsidianProjects.d.ts @@ -1,14 +1,13 @@ import type { DataFrame } from "./lib/dataframe/dataframe"; declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace namespace Intl { interface Locale { - weekInfo: { - firstDay: number; - }; + weekInfo?: WeekInfo; + getWeekInfo?: () => WeekInfo; } } + type WeekInfo = { firstDay: number; weekend: number[]; minimalDays: number }; } declare module "obsidian" { diff --git a/src/ui/views/Calendar/calendar.ts b/src/ui/views/Calendar/calendar.ts index 1f9fd39d..de987b17 100644 --- a/src/ui/views/Calendar/calendar.ts +++ b/src/ui/views/Calendar/calendar.ts @@ -225,7 +225,15 @@ export function getFirstDayOfWeek(day: FirstDayOfWeek): number { return 0; case "monday": return 1; - case "default": - return getLocale("obsidian").weekInfo.firstDay; + case "default": { + const obLocale = getLocale("obsidian"); + if (obLocale.weekInfo) { + return obLocale.weekInfo.firstDay ?? 0; + } + if (typeof obLocale.getWeekInfo === "function") { + return obLocale.getWeekInfo().firstDay ?? 0; + } + return 0; + } } }