({ value, type, now }: FormatDateProps)
| 319 | } |
| 320 | |
| 321 | export 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 |
no test coverage detected