Fix inbox relays, add time functions

This commit is contained in:
Jon Staab
2024-10-02 11:51:14 -07:00
parent b12f4aec4d
commit 7af86f42cf
7 changed files with 126 additions and 10 deletions
+24 -2
View File
@@ -11,8 +11,6 @@ export type Maybe<T> = T | undefined
// Regular old utils
export const now = () => Math.round(Date.now() / 1000)
export const noop = (...args: unknown[]) => undefined
export const first = <T>(xs: T[], ...args: unknown[]) => xs[0]
@@ -511,6 +509,30 @@ export const pushToMapKey = <K, T>(m: Map<K, T[]>, k: K, v: T) => {
export const switcher = <T>(k: string, m: Record<string, T>) =>
m[k] === undefined ? m.default : m[k]
// Time
export const MINUTE = 60
export const HOUR = 60 * MINUTE
export const DAY = 24 * HOUR
export const WEEK = 7 * DAY
export const MONTH = 30 * DAY
export const QUARTER = 90 * DAY
export const YEAR = 365 * DAY
export const int = (unit: number, count = 1) => unit * count
export const now = () => Math.round(Date.now() / 1000)
export const ago = (unit: number, count = 1) => now() - int(unit, count)
export const ms = (seconds: number) => seconds * 1000
// Fetch
type FetchOpts = {