Added relative timestamps to feed objects
ref https://linear.app/tryghost/issue/AP-131/show-nice-relative-timestamps
This commit is contained in:
parent
b2d5304c3c
commit
6ae20a8d32
33
apps/admin-x-activitypub/src/utils/get-relative-timestamp.ts
Normal file
33
apps/admin-x-activitypub/src/utils/get-relative-timestamp.ts
Normal file
@ -0,0 +1,33 @@
|
||||
export const getRelativeTimestamp = (date: Date): string => {
|
||||
const now = new Date();
|
||||
const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
||||
|
||||
let interval = Math.floor(seconds / 31536000);
|
||||
if (interval > 1) {
|
||||
return `${interval}y`;
|
||||
}
|
||||
|
||||
interval = Math.floor(seconds / 2592000);
|
||||
if (interval > 1) {
|
||||
return `${interval}m`;
|
||||
}
|
||||
|
||||
interval = Math.floor(seconds / 86400);
|
||||
if (interval >= 1) {
|
||||
return `${interval}d`;
|
||||
}
|
||||
|
||||
interval = Math.floor(seconds / 3600);
|
||||
if (interval > 1) {
|
||||
return `${interval}h`;
|
||||
}
|
||||
|
||||
interval = Math.floor(seconds / 60);
|
||||
if (interval > 1) {
|
||||
return `${interval}m`;
|
||||
}
|
||||
|
||||
return `${seconds} seconds`;
|
||||
};
|
||||
|
||||
export default getRelativeTimestamp;
|
Loading…
Reference in New Issue
Block a user