adds time string to comment card
This commit is contained in:
@@ -48,3 +48,31 @@ export function formatElevation(meters?: number) {
|
||||
return `${Math.round(feet)} ft`;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTimeSince(date: Date) {
|
||||
|
||||
var seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
|
||||
|
||||
var interval = seconds / 31536000;
|
||||
|
||||
if (interval > 1) {
|
||||
return { unit: "years", value: Math.floor(interval) };
|
||||
}
|
||||
interval = seconds / 2592000;
|
||||
if (interval > 1) {
|
||||
return { unit: "months", value: Math.floor(interval) };
|
||||
}
|
||||
interval = seconds / 86400;
|
||||
if (interval > 1) {
|
||||
return { unit: "days", value: Math.floor(interval) };
|
||||
}
|
||||
interval = seconds / 3600;
|
||||
if (interval > 1) {
|
||||
return { unit: "hours", value: Math.floor(interval) };
|
||||
}
|
||||
interval = seconds / 60;
|
||||
if (interval > 1) {
|
||||
return { unit: "minutes", value: Math.floor(interval) };
|
||||
}
|
||||
return { unit: "seconds", value: Math.floor(interval) };
|
||||
}
|
||||
Reference in New Issue
Block a user