Bump version to 0.2.14 and simplify date processing to native browser behavior
All checks were successful
Build SilverBullet Plug / build (push) Successful in 26s

This commit is contained in:
2026-02-17 08:26:20 -08:00
parent 0e7e89091d
commit 66f60bc9ae
2 changed files with 12 additions and 35 deletions

View File

@@ -1,6 +1,6 @@
---
name: Library/sstent/icalendar/PLUG
version: 0.2.13
version: 0.2.14
tags: meta/library
files:
- icalendar.plug.js

View File

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