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

Function postDateFormat

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

Source from the content-addressed store, hash-verified

106}
107
108export function postDateFormat(
109 value: Date | number | string,
110 now = new Date(),
111): string {
112 const date = new Date(value);
113
114 // Calculate time delta in seconds.
115 const dt = (now.getTime() - date.getTime()) / 1000;
116
117 if (dt <= oneMinute) {
118 return 'Now';
119 }
120
121 if (isSameDay(date, now)) {
122 return 'Today';
123 }
124
125 if (isSameDay(date, subDays(now, 1))) {
126 return 'Yesterday';
127 }
128
129 const options: Intl.DateTimeFormatOptions = {
130 month: 'short',
131 day: '2-digit',
132 };
133 if (!isSameYear(date, now)) {
134 options.year = 'numeric';
135 }
136 return date.toLocaleString('en-US', options);
137}
138
139export function postUpdatedDateFormat(
140 value: Date | number | string,

Callers 4

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

Calls

no outgoing calls

Tested by

no test coverage detected