From 66f60bc9ae0072ed230ba5477393f82eb95956b4 Mon Sep 17 00:00:00 2001 From: sstent Date: Tue, 17 Feb 2026 08:26:20 -0800 Subject: [PATCH] Bump version to 0.2.14 and simplify date processing to native browser behavior --- PLUG.md | 2 +- icalendar.ts | 45 +++++++++++---------------------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/PLUG.md b/PLUG.md index 8e47d15..2586fee 100644 --- a/PLUG.md +++ b/PLUG.md @@ -1,6 +1,6 @@ --- name: Library/sstent/icalendar/PLUG -version: 0.2.13 +version: 0.2.14 tags: meta/library files: - icalendar.plug.js diff --git a/icalendar.ts b/icalendar.ts index 51fad90..1315410 100644 --- a/icalendar.ts +++ b/icalendar.ts @@ -1,24 +1,10 @@ import { clientStore, config, datastore, editor, index } from "@silverbulletmd/silverbullet/syscalls"; import { convertIcsCalendar, type IcsCalendar, type IcsEvent, type IcsDateObjects } from "ts-ics"; -const VERSION = "0.2.13"; +const VERSION = "0.2.14"; const CACHE_KEY = "icalendar:lastSync"; const DEFAULT_CACHE_DURATION_SECONDS = 21600; // 6 hours -// Mapping of common Windows/Outlook timezones to their standard offsets -const TIMEZONE_OFFSETS: Record = { - "GMT Standard Time": 0, - "W. Europe Standard Time": 1, - "Central Europe Standard Time": 1, - "Romance Standard Time": 1, - "Central European Standard Time": 1, - "Eastern Standard Time": -5, - "Central Standard Time": -6, - "Mountain Standard Time": -7, - "Pacific Standard Time": -8, - "UTC": 0 -}; - console.log(`[iCalendar] Plug loading (Version ${VERSION})...`); // ============================================================================ @@ -67,30 +53,21 @@ function toLocalISO(d: Date): string { } /** - * Robustly converts an ICS date object to a localized PST string + * Simplified date processor that trusts the parsed Date object */ function processIcsDate(obj: any, manualShift = 0): string { if (!obj) return ""; - // Handle case where it's already a Date object - if (obj instanceof Date) { - return toLocalISO(new Date(obj.getTime() + (manualShift * 3600000))); - } - - // Extract the underlying Date object from the ts-ics structure - const baseDate = obj.date instanceof Date ? obj.date : null; - if (!baseDate) return ""; - - // If ts-ics gave us a 'local' field, it has already tried to parse the TZID - const tzName = obj.local?.timezone || obj.timezone || "UTC"; - const sourceOffset = TIMEZONE_OFFSETS[tzName] || 0; + // The 'date' property from ts-ics is already a native JS Date object + // which has been parsed with the correct TZID context if available. + const d = obj.date instanceof Date ? obj.date : (obj instanceof Date ? obj : null); - // Calculate the TRUE UTC time if it wasn't already in UTC - // WallTime (baseDate) - SourceOffset = UTC - const utcTime = baseDate.getTime() - (sourceOffset * 3600000); + if (!d) return ""; + + // Apply ONLY the user requested shift + const shiftedDate = new Date(d.getTime() + (manualShift * 3600000)); - // Create final localized date - return toLocalISO(new Date(utcTime + (manualShift * 3600000))); + return toLocalISO(shiftedDate); } function isIcsDateObjects(obj: any): obj is IcsDateObjects { @@ -219,4 +196,4 @@ export async function clearCache() { export async function showVersion() { await editor.flashNotification(`iCalendar Plug ${VERSION}`, "info"); -} \ No newline at end of file +}