diff --git a/PLUG.md b/PLUG.md index eceece8..aaddb12 100644 --- a/PLUG.md +++ b/PLUG.md @@ -1,6 +1,6 @@ --- name: Library/sstent/icalendar -version: "0.4.2" +version: "0.4.3" tags: meta/library files: - icalendar.plug.js diff --git a/deno.json b/deno.json index b8c7f6f..c83ab5b 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "icalendar-plug", - "version": "0.4.2", + "version": "0.4.3", "nodeModulesDir": "auto", "tasks": { "sync-version": "deno run -A scripts/sync-version.ts", diff --git a/icalendar.plug.yaml b/icalendar.plug.yaml index 90b511c..9a4e421 100644 --- a/icalendar.plug.yaml +++ b/icalendar.plug.yaml @@ -1,5 +1,5 @@ name: icalendar -version: 0.4.2 +version: 0.4.3 author: sstent index: icalendar.ts # Legacy SilverBullet permission name diff --git a/icalendar.ts b/icalendar.ts index 56eefc6..f7db918 100644 --- a/icalendar.ts +++ b/icalendar.ts @@ -3,7 +3,7 @@ import { convertIcsCalendar } from "https://esm.sh/ts-ics@2.4.0"; import { RRule, RRuleSet } from "rrule"; import { getUtcOffsetMs, resolveIanaName } from "./timezones.ts"; -const VERSION = "0.4.2"; +const VERSION = "0.4.3"; const CACHE_KEY = "icalendar:lastSync"; console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`); @@ -66,12 +66,12 @@ async function sha256Hash(str: string): Promise { /** * Converts UTC Date to a specific timezone string - * Uses Intl.DateTimeFormat to properly handle timezone conversion + * Uses toLocaleString for better compatibility */ export function dateToTimezoneString(date: Date, timezone: string = "America/Los_Angeles"): string { try { - // Get date components in the target timezone - const formatter = new Intl.DateTimeFormat('en-US', { + // Use toLocaleString which has better worker support + const localeString = date.toLocaleString('en-US', { timeZone: timezone, year: 'numeric', month: '2-digit', @@ -82,17 +82,16 @@ export function dateToTimezoneString(date: Date, timezone: string = "America/Los hour12: false }); - const parts = formatter.formatToParts(date); - const values: Record = {}; + console.log(`[iCalendar] Converting ${date.toISOString()} to ${timezone}: ${localeString}`); - for (const part of parts) { - if (part.type !== 'literal') { - values[part.type] = part.value; - } + // Parse the result: "MM/DD/YYYY, HH:MM:SS" + const match = localeString.match(/(\d{2})\/(\d{2})\/(\d{4}),\s*(\d{2}):(\d{2}):(\d{2})/); + if (match) { + const [_, month, day, year, hour, minute, second] = match; + return `${year}-${month}-${day}T${hour}:${minute}:${second}`; } - // Format as ISO-like string: YYYY-MM-DDTHH:MM:SS - return `${values.year}-${values.month}-${values.day}T${values.hour}:${values.minute}:${values.second}`; + throw new Error("Failed to parse toLocaleString result"); } catch (err) { console.error(`[iCalendar] Error converting to timezone ${timezone}:`, err); // Fallback to UTC @@ -378,6 +377,12 @@ export async function syncCalendars() { if (sources.length === 0) return; console.log(`[iCalendar] Using display timezone: ${displayTimezone}`); + + // Test timezone conversion + const testDate = new Date("2026-02-21T14:00:00.000Z"); // 14:00 UTC + const converted = dateToTimezoneString(testDate, displayTimezone); + console.log(`[iCalendar] Timezone test: ${testDate.toISOString()} → ${converted} (should be 06:00 PST)`); + await editor.flashNotification("Syncing calendars...", "info"); const allEvents: any[] = []; for (const source of sources) {