add unixTimestamp()

This commit is contained in:
ennmichael
2023-02-27 14:11:10 +01:00
parent 289dbcd523
commit 303fa2ff4b
3 changed files with 13 additions and 10 deletions

View File

@ -2,6 +2,7 @@ import { ProtocolError } from "../error"
import { Filters, SubscriptionId } from "."
import { RawEvent, SignedEvent } from "../event"
import WebSocket from "ws"
import { unixTimestamp } from "../util"
/**
* The connection to a relay. This is the lowest layer of the nostr protocol.
@ -241,15 +242,10 @@ function serializeFilters(filters: Filters): RawFilters {
kinds: filters.kinds?.map((kind) => kind),
["#e"]: filters.eventTags?.map((e) => e.toString()),
["#p"]: filters.pubkeyTags?.map((p) => p.toString()),
// TODO The Math.floor has been repeated too many times at this point, have a unix timestamp function in event.ts
since:
filters.since !== undefined
? Math.floor(filters.since.getTime() / 1000)
: undefined,
filters.since !== undefined ? unixTimestamp(filters.since) : undefined,
until:
filters.until !== undefined
? Math.floor(filters.until.getTime() / 1000)
: undefined,
filters.until !== undefined ? unixTimestamp(filters.until) : undefined,
limit: filters.limit,
}
}