Initial commit

This commit is contained in:
Bethlenfalvi, Lorinc (ext)
2025-01-28 00:28:14 +01:00
parent d154e5b725
commit 0c962c336b
52 changed files with 2958 additions and 1054 deletions

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

@@ -0,0 +1,22 @@
import { Temporal } from "@js-temporal/polyfill";
function lt(one: Temporal.Duration, other: Temporal.DurationLike): boolean {
return Temporal.Duration.compare(one, other) < 0
}
export function printTime(time: Temporal.ZonedDateTime): string {
const delta = time.until(Temporal.Now.zonedDateTimeISO())
if (lt(delta, { minutes: 1 })) return 'now'
if (lt(delta, { hours: 1 })) return `${delta.minutes} minutes ago`
if (lt(delta, { days: 1 })) return `${delta.hours} hours ago`
if (lt(delta, { days: 7 })) return `${delta.round({ smallestUnit: 'days' }).days} days ago`
return `at ${time.toPlainDate().toString()} ${time.toPlainTime().toString({ smallestUnit: 'minutes' })}`
}
export function parseTime(string: string): Temporal.ZonedDateTime {
return Temporal.ZonedDateTime.from(string)
}
export function isValidTime(string: string): boolean {
try { parseTime(string); return true } catch { return false }
}