mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-06-17 18:18:49 +02:00
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user