MCPcopy
hub / github.com/fccview/jotty / getTimeUnitSimple

Function getTimeUnitSimple

app/_utils/date-utils.ts:66–76  ·  view source on GitHub ↗
(dateString: string)

Source from the content-addressed store, hash-verified

64};
65
66const getTimeUnitSimple = (dateString: string) => {
67 const diffMs = new Date().getTime() - new Date(dateString).getTime();
68 const diffMins = Math.floor(diffMs / 60000);
69 const diffHours = Math.floor(diffMins / 60);
70 const diffDays = Math.floor(diffHours / 24);
71
72 if (diffMins < 1) return { unit: TimeUnit.JustNow, value: 0 };
73 if (diffMins < 60) return { unit: TimeUnit.Minutes, value: diffMins };
74 if (diffHours < 24) return { unit: TimeUnit.Hours, value: diffHours };
75 return { unit: TimeUnit.Days, value: diffDays };
76};
77
78const formatTimeAgoEnglish = (unit: TimeUnit, value: number): string => {
79 if (unit === TimeUnit.JustNow) return "Just now";

Callers 1

formatTimeAgoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected