Skip to content
Myr

time.tsx

This file

Path

apps/web/src/features/shared/time.tsx

43 lines · 857 bytes · TypeScript

Last changed by

Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–43why, one step back
1import { DateTime } from "effect";
23const MINUTE = 60_000;45const HOUR = 60 * MINUTE;67const DAY = 24 * HOUR;89const span = (millis: number) => {10 if (millis < HOUR) {11 return `${Math.floor(millis / MINUTE)} min`;12 }1314 return millis < DAY15 ? `${Math.floor(millis / HOUR)} h`16 : `${Math.floor(millis / DAY)} d`;17};1819export const distanceInWords = (at: DateTime.Utc, now: DateTime.Utc) => {20 const millis = DateTime.toEpochMillis(at) - DateTime.toEpochMillis(now);2122 if (Math.abs(millis) < MINUTE) {23 return "now";24 }2526 return millis > 0 ? `in ${span(millis)}` : `${span(-millis)} ago`;27};2829export const When = ({30 at,31 now,32}: {33 readonly at: DateTime.Utc;34 readonly now: DateTime.Utc;35}) => {36 const iso = DateTime.formatIso(at);3738 return (39 <time dateTime={iso} title={iso}>40 {distanceInWords(at, now)}41 </time>42 );43};