Prevent cyclical import of Time module

This commit is contained in:
Alex Gleason 2023-07-08 20:01:10 -05:00
parent 028ff27c49
commit 4e68e3868f
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 15 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import { TTLCache, z } from '@/deps.ts';
import { Time } from '@/utils.ts';
import { Time } from '@/utils/time.ts';
const nip05Cache = new TTLCache<string, Promise<string | null>>({ ttl: Time.hours(1), max: 5000 });

View File

@ -106,17 +106,6 @@ function eventAge(event: Event): number {
return new Date().getTime() - nostrDate(event.created_at).getTime();
}
const Time = {
milliseconds: (ms: number) => ms,
seconds: (s: number) => s * 1000,
minutes: (m: number) => m * Time.seconds(60),
hours: (h: number) => h * Time.minutes(60),
days: (d: number) => d * Time.hours(24),
weeks: (w: number) => w * Time.days(7),
months: (m: number) => m * Time.days(30),
years: (y: number) => y * Time.days(365),
};
function findTag(tags: string[][], name: string): string[] | undefined {
return tags.find((tag) => tag[0] === name);
}
@ -150,5 +139,6 @@ export {
parseBody,
parseNip05,
sha256,
Time,
};
export { Time } from './utils/time.ts';

12
src/utils/time.ts Normal file
View File

@ -0,0 +1,12 @@
const Time = {
milliseconds: (ms: number) => ms,
seconds: (s: number) => s * 1000,
minutes: (m: number) => m * Time.seconds(60),
hours: (h: number) => h * Time.minutes(60),
days: (d: number) => d * Time.hours(24),
weeks: (w: number) => w * Time.days(7),
months: (m: number) => m * Time.days(30),
years: (y: number) => y * Time.days(365),
};
export { Time };