switch to ical.js - v4.3
All checks were successful
Build SilverBullet Plug / build (push) Successful in 14s

This commit is contained in:
2026-02-21 15:39:00 -08:00
parent 017afa0f11
commit 4aa8019de1
4 changed files with 20 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
---
name: Library/sstent/icalendar
version: "0.4.2"
version: "0.4.3"
tags: meta/library
files:
- icalendar.plug.js

View File

@@ -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",

View File

@@ -1,5 +1,5 @@
name: icalendar
version: 0.4.2
version: 0.4.3
author: sstent
index: icalendar.ts
# Legacy SilverBullet permission name

View File

@@ -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<string> {
/**
* 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<string, string> = {};
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) {