MCPcopy Create free account
hub / github.com/dailydotdev/apps / postDateFormat

Function postDateFormat

packages/shared/src/lib/dateFormat.ts:93–122  ·  view source on GitHub ↗
(
  value: Date | number | string,
  now = new Date(),
)

Source from the content-addressed store, hash-verified

91}
92
93export function postDateFormat(
94 value: Date | number | string,
95 now = new Date(),
96): string {
97 const date = new Date(value);
98
99 // Calculate time delta in seconds.
100 const dt = (now.getTime() - date.getTime()) / 1000;
101
102 if (dt <= oneMinute) {
103 return 'Now';
104 }
105
106 if (isSameDay(date, now)) {
107 return 'Today';
108 }
109
110 if (isSameDay(date, subDays(now, 1))) {
111 return 'Yesterday';
112 }
113
114 const options: Intl.DateTimeFormatOptions = {
115 month: 'short',
116 day: '2-digit',
117 };
118 if (!isSameYear(date, now)) {
119 options.year = 'numeric';
120 }
121 return date.toLocaleString('en-US', options);
122}
123
124export function postUpdatedDateFormat(
125 value: Date | number | string,

Callers 3

dateFormat.spec.tsFile · 0.90
postUpdatedDateFormatFunction · 0.85
formatDateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected