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

Function formatDate

packages/shared/src/lib/dateFormat.ts:310–369  ·  view source on GitHub ↗
({ value, type, now }: FormatDateProps)

Source from the content-addressed store, hash-verified

308}
309
310export const formatDate = ({ value, type, now }: FormatDateProps): string => {
311 const date = new Date(value);
312
313 if (!isValidDate(date)) {
314 return '';
315 }
316
317 const nowDate = now ? new Date(now) : undefined;
318 if (nowDate && !isValidDate(nowDate)) {
319 return '';
320 }
321
322 if (type === TimeFormatType.Elapsed) {
323 return publishTimeRelativeShort(date, nowDate);
324 }
325
326 if (type === TimeFormatType.Post) {
327 return postDateFormat(date);
328 }
329
330 if (type === TimeFormatType.PostUpdated) {
331 return postUpdatedDateFormat(date);
332 }
333
334 if (type === TimeFormatType.Comment) {
335 return publishTimeRelativeShort(date);
336 }
337
338 if (type === TimeFormatType.ReadHistory) {
339 return getReadHistoryDateFormat(date);
340 }
341
342 if (type === TimeFormatType.TopReaderBadge) {
343 return getTopReaderBadgeDateFormat(date);
344 }
345
346 if (type === TimeFormatType.PlusMember) {
347 return getPlusMemberDateFormat(date);
348 }
349
350 if (type === TimeFormatType.Transaction) {
351 const isCurrentYear = isSameYear(date, new Date());
352
353 return format(date, `MMM dd${isCurrentYear ? ' ' : ', yyyy '}HH:mm`);
354 }
355
356 if (type === TimeFormatType.LastActivity) {
357 return getLastActivityDateFormat(date);
358 }
359
360 if (type === TimeFormatType.LiveTimer) {
361 return publishTimeLiveTimer(date, nowDate);
362 }
363
364 if (type === TimeFormatType.Experience) {
365 return publishExperienceTime(date, nowDate);
366 }
367

Callers 15

RepostListItemFunction · 0.90
TopReaderBadgeModalFunction · 0.90
CompareAchievementsModalFunction · 0.90
TopReaderBadgeFunction · 0.90
DateFormatFunction · 0.90
BriefCardReadyFunction · 0.90
BriefCardInternalFunction · 0.90
DigestPostContentRawFunction · 0.90
BriefPostContentRawFunction · 0.90
dateFormat.spec.tsFile · 0.90
AchievementCardFunction · 0.90
KeywordBadgeFunction · 0.90

Calls 10

isValidDateFunction · 0.85
publishTimeRelativeShortFunction · 0.85
postDateFormatFunction · 0.85
postUpdatedDateFormatFunction · 0.85
getReadHistoryDateFormatFunction · 0.85
getPlusMemberDateFormatFunction · 0.85
publishTimeLiveTimerFunction · 0.85
publishExperienceTimeFunction · 0.85

Tested by

no test coverage detected