blowater/time.ts
2023-11-25 22:29:50 +08:00

24 lines
506 B
TypeScript

import { NostrEvent } from "./lib/nostr-ts/nostr.ts";
import { getTags } from "./nostr.ts";
export class LamportTime {
private time = 0;
fromEvents(events: Iterable<NostrEvent>) {
for (const event of events) {
const ts = getTags(event).lamport_timestamp;
if (ts) {
this.set(ts);
}
}
}
now() {
this.time++;
return this.time;
}
set(t: number) {
this.time = Math.max(this.time, t);
}
}