Display relative timestamp for threads on the same calendar day (#10399)
* add test cases for <24 different day time formatting * use day instead of <24h ago to format relative date
This commit is contained in:
parent
68fa9aed9d
commit
cd700e20fc
2 changed files with 13 additions and 2 deletions
|
@ -186,6 +186,10 @@ function withinPast24Hours(prevDate: Date, nextDate: Date): boolean {
|
|||
return Math.abs(prevDate.getTime() - nextDate.getTime()) <= MILLIS_IN_DAY;
|
||||
}
|
||||
|
||||
function withinCurrentDay(prevDate: Date, nextDate: Date): boolean {
|
||||
return withinPast24Hours(prevDate, nextDate) && prevDate.getDay() === nextDate.getDay();
|
||||
}
|
||||
|
||||
function withinCurrentYear(prevDate: Date, nextDate: Date): boolean {
|
||||
return prevDate.getFullYear() === nextDate.getFullYear();
|
||||
}
|
||||
|
@ -229,7 +233,7 @@ export function formatFullDateNoDayNoTime(date: Date): string {
|
|||
|
||||
export function formatRelativeTime(date: Date, showTwelveHour = false): string {
|
||||
const now = new Date(Date.now());
|
||||
if (withinPast24Hours(date, now)) {
|
||||
if (withinCurrentDay(date, now)) {
|
||||
return formatTime(date, showTwelveHour);
|
||||
} else {
|
||||
const months = getMonthsArray();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue