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
This commit is contained in:
Claude
2026-01-22 15:55:21 +00:00
parent d4fe884848
commit 326d0f0644
2 changed files with 8 additions and 15 deletions

View File

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

View File

@@ -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;
}
}