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

Function formatDate

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

Source from the content-addressed store, hash-verified

293}
294
295export const formatDate = ({ value, type, now }: FormatDateProps): string => {
296 const date = new Date(value);
297
298 if (!isValidDate(date)) {
299 return '';
300 }
301
302 const nowDate = now ? new Date(now) : undefined;
303 if (nowDate && !isValidDate(nowDate)) {
304 return '';
305 }
306
307 if (type === TimeFormatType.Post) {
308 return postDateFormat(date);
309 }
310
311 if (type === TimeFormatType.PostUpdated) {
312 return postUpdatedDateFormat(date);
313 }
314
315 if (type === TimeFormatType.Comment) {
316 return publishTimeRelativeShort(date);
317 }
318
319 if (type === TimeFormatType.ReadHistory) {
320 return getReadHistoryDateFormat(date);
321 }
322
323 if (type === TimeFormatType.TopReaderBadge) {
324 return getTopReaderBadgeDateFormat(date);
325 }
326
327 if (type === TimeFormatType.PlusMember) {
328 return getPlusMemberDateFormat(date);
329 }
330
331 if (type === TimeFormatType.Transaction) {
332 const isCurrentYear = isSameYear(date, new Date());
333
334 return format(date, `MMM dd${isCurrentYear ? ' ' : ', yyyy '}HH:mm`);
335 }
336
337 if (type === TimeFormatType.LastActivity) {
338 return getLastActivityDateFormat(date);
339 }
340
341 if (type === TimeFormatType.LiveTimer) {
342 return publishTimeLiveTimer(date, nowDate);
343 }
344
345 if (type === TimeFormatType.Experience) {
346 return publishExperienceTime(date, nowDate);
347 }
348
349 return postDateFormat(date);
350};
351
352export const formatMonthYearOnly = (date: Date): string =>

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
postDateFormatFunction · 0.85
postUpdatedDateFormatFunction · 0.85
publishTimeRelativeShortFunction · 0.85
getReadHistoryDateFormatFunction · 0.85
getPlusMemberDateFormatFunction · 0.85
publishTimeLiveTimerFunction · 0.85
publishExperienceTimeFunction · 0.85

Tested by

no test coverage detected