in apps-rendering/src/date.ts [54:92]
function makeRelativeDate(date: Date): string | null {
const then: Date = new Date(date);
const now: Date = new Date();
if (!isValidDate(then)) {
return null;
}
const delta: number = parseInt(
`${(now.valueOf() - then.valueOf()) / 1000}`,
10,
);
if (delta < 0) {
return null;
} else if (delta < 55) {
return `${delta}s`;
} else if (delta < 55 * 60) {
const minutesAgo = Math.round(delta / 60);
if (minutesAgo === 1) {
return 'Now';
} else {
return `${minutesAgo}m ago`;
}
} else if (isToday(then) || isWithin24Hours(then)) {
const hoursAgo = Math.round(delta / 3600);
return `${hoursAgo}h ago`;
} else if (isWithinPastWeek(then)) {
const daysAgo = Math.round(delta / 3600 / 24);
return `${daysAgo}d ago`;
} else if (isWithinPastYear(then)) {
const weeksAgo = Math.round(delta / 3600 / 24 / 7);
return `${weeksAgo}w ago`;
} else {
const yearsAgo = Math.round(delta / 3600 / 24 / 7 / 52);
return `${yearsAgo}y ago`;
}
}