Fixed time not being converted properly

ref https://linear.app/tryghost/issue/AP-131/show-nice-relative-timestamps
This commit is contained in:
Djordje Vlaisavljevic 2024-08-17 17:25:36 +01:00
parent 2a212bfff4
commit 366d683d7b

View File

@ -3,12 +3,12 @@ export const getRelativeTimestamp = (date: Date): string => {
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
let interval = Math.floor(seconds / 31536000);
if (interval > 1) {
if (interval >= 1) {
return `${interval}y`;
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
if (interval >= 1) {
return `${interval}m`;
}
@ -18,12 +18,12 @@ export const getRelativeTimestamp = (date: Date): string => {
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
if (interval >= 1) {
return `${interval}h`;
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
if (interval >= 1) {
return `${interval}m`;
}