From 326d0f06447f8836cf5b7bcf7a2a2d2840905ccb Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Jan 2026 15:55:21 +0000 Subject: [PATCH] fix: resolve relative time filters in spells at runtime - Export parseTimestamp function from req-parser - Use parseTimestamp in decodeSpell to resolve relative times like "1y", "7d", "30m" - Fixes issue where spells with relative time filters (since/until) were not working - Time values are now properly converted to unix timestamps when spell is applied --- src/lib/req-parser.ts | 2 +- src/lib/spell-conversion.ts | 21 +++++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/lib/req-parser.ts b/src/lib/req-parser.ts index d233572..d5ca744 100644 --- a/src/lib/req-parser.ts +++ b/src/lib/req-parser.ts @@ -520,7 +520,7 @@ function isRelayDomain(value: string): boolean { /** * Parse timestamp - supports unix timestamp, relative time (1s, 30m, 2h, 7d, 2w, 3mo, 1y), or "now" */ -function parseTimestamp(value: string): number | null { +export function parseTimestamp(value: string): number | null { if (!value) return null; // Special keyword: "now" - current timestamp diff --git a/src/lib/spell-conversion.ts b/src/lib/spell-conversion.ts index d41a546..e1ac26b 100644 --- a/src/lib/spell-conversion.ts +++ b/src/lib/spell-conversion.ts @@ -1,4 +1,4 @@ -import { parseReqCommand } from "./req-parser"; +import { parseReqCommand, parseTimestamp } from "./req-parser"; import type { CreateSpellOptions, EncodedSpell, @@ -358,24 +358,17 @@ export function decodeSpell(event: SpellEvent): ParsedSpell { const since = tagMap.get("since")?.[0]; if (since) { - // Check if it's a relative time or unix timestamp - if (/^\d{10}$/.test(since)) { - filter.since = parseInt(since, 10); - } else { - // It's a relative time format - preserve it as a comment - // For actual filtering, we'd need to resolve it at runtime - // For now, skip adding to filter (will be resolved at execution) + const timestamp = parseTimestamp(since); + if (timestamp) { + filter.since = timestamp; } } const until = tagMap.get("until")?.[0]; if (until) { - // Check if it's a relative time or unix timestamp - if (/^\d{10}$/.test(until)) { - filter.until = parseInt(until, 10); - } else { - // It's a relative time format - preserve it as a comment - // For now, skip adding to filter (will be resolved at execution) + const timestamp = parseTimestamp(until); + if (timestamp) { + filter.until = timestamp; } }