forked from GitHubMirrors/silverbullet-icalendar
switch to ical.js - v4.3
All checks were successful
Build SilverBullet Plug / build (push) Successful in 14s
All checks were successful
Build SilverBullet Plug / build (push) Successful in 14s
This commit is contained in:
2
PLUG.md
2
PLUG.md
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: Library/sstent/icalendar
|
name: Library/sstent/icalendar
|
||||||
version: "0.4.2"
|
version: "0.4.3"
|
||||||
tags: meta/library
|
tags: meta/library
|
||||||
files:
|
files:
|
||||||
- icalendar.plug.js
|
- icalendar.plug.js
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "icalendar-plug",
|
"name": "icalendar-plug",
|
||||||
"version": "0.4.2",
|
"version": "0.4.3",
|
||||||
"nodeModulesDir": "auto",
|
"nodeModulesDir": "auto",
|
||||||
"tasks": {
|
"tasks": {
|
||||||
"sync-version": "deno run -A scripts/sync-version.ts",
|
"sync-version": "deno run -A scripts/sync-version.ts",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: icalendar
|
name: icalendar
|
||||||
version: 0.4.2
|
version: 0.4.3
|
||||||
author: sstent
|
author: sstent
|
||||||
index: icalendar.ts
|
index: icalendar.ts
|
||||||
# Legacy SilverBullet permission name
|
# Legacy SilverBullet permission name
|
||||||
|
|||||||
29
icalendar.ts
29
icalendar.ts
@@ -3,7 +3,7 @@ import { convertIcsCalendar } from "https://esm.sh/ts-ics@2.4.0";
|
|||||||
import { RRule, RRuleSet } from "rrule";
|
import { RRule, RRuleSet } from "rrule";
|
||||||
import { getUtcOffsetMs, resolveIanaName } from "./timezones.ts";
|
import { getUtcOffsetMs, resolveIanaName } from "./timezones.ts";
|
||||||
|
|
||||||
const VERSION = "0.4.2";
|
const VERSION = "0.4.3";
|
||||||
const CACHE_KEY = "icalendar:lastSync";
|
const CACHE_KEY = "icalendar:lastSync";
|
||||||
|
|
||||||
console.log(`[iCalendar] Plug script executing at top level (Version ${VERSION})`);
|
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
|
* 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 {
|
export function dateToTimezoneString(date: Date, timezone: string = "America/Los_Angeles"): string {
|
||||||
try {
|
try {
|
||||||
// Get date components in the target timezone
|
// Use toLocaleString which has better worker support
|
||||||
const formatter = new Intl.DateTimeFormat('en-US', {
|
const localeString = date.toLocaleString('en-US', {
|
||||||
timeZone: timezone,
|
timeZone: timezone,
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: '2-digit',
|
month: '2-digit',
|
||||||
@@ -82,17 +82,16 @@ export function dateToTimezoneString(date: Date, timezone: string = "America/Los
|
|||||||
hour12: false
|
hour12: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const parts = formatter.formatToParts(date);
|
console.log(`[iCalendar] Converting ${date.toISOString()} to ${timezone}: ${localeString}`);
|
||||||
const values: Record<string, string> = {};
|
|
||||||
|
|
||||||
for (const part of parts) {
|
// Parse the result: "MM/DD/YYYY, HH:MM:SS"
|
||||||
if (part.type !== 'literal') {
|
const match = localeString.match(/(\d{2})\/(\d{2})\/(\d{4}),\s*(\d{2}):(\d{2}):(\d{2})/);
|
||||||
values[part.type] = part.value;
|
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
|
throw new Error("Failed to parse toLocaleString result");
|
||||||
return `${values.year}-${values.month}-${values.day}T${values.hour}:${values.minute}:${values.second}`;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[iCalendar] Error converting to timezone ${timezone}:`, err);
|
console.error(`[iCalendar] Error converting to timezone ${timezone}:`, err);
|
||||||
// Fallback to UTC
|
// Fallback to UTC
|
||||||
@@ -378,6 +377,12 @@ export async function syncCalendars() {
|
|||||||
if (sources.length === 0) return;
|
if (sources.length === 0) return;
|
||||||
|
|
||||||
console.log(`[iCalendar] Using display timezone: ${displayTimezone}`);
|
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");
|
await editor.flashNotification("Syncing calendars...", "info");
|
||||||
const allEvents: any[] = [];
|
const allEvents: any[] = [];
|
||||||
for (const source of sources) {
|
for (const source of sources) {
|
||||||
|
|||||||
Reference in New Issue
Block a user