({ value, type, now }: FormatDateProps)
| 293 | } |
| 294 | |
| 295 | export 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 | |
| 352 | export const formatMonthYearOnly = (date: Date): string => |
no test coverage detected