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

Function formatDate

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

Source from the content-addressed store, hash-verified

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

Callers 15

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

Calls 11

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

Tested by

no test coverage detected