fixed TimeAgo abbreviation

This commit is contained in:
Bernt Christian Egeland 2023-07-01 15:01:08 +02:00
parent f3f9b36e07
commit 420079f954

View File

@ -27,7 +27,7 @@ const timeAgo = ({ time, currentTime = new Date(), dense = false }: IProp): stri
const timeUnits: TimeUnit[] = [ const timeUnits: TimeUnit[] = [
{ unit: 'ye', full: 'year', value: 31536000 }, { unit: 'ye', full: 'year', value: 31536000 },
{ unit: 'mo', full: 'month', value: 0 }, { unit: 'mo', full: 'month', value: 0 },
{ unit: 'day', full: 'day', value: 86400 }, { unit: 'd', full: 'day', value: 86400 },
{ unit: 'h', full: 'hour', value: 3600 }, { unit: 'h', full: 'hour', value: 3600 },
{ unit: 'm', full: 'minute', value: 60 }, { unit: 'm', full: 'minute', value: 60 },
{ unit: 's', full: 'second', value: 1 }, { unit: 's', full: 'second', value: 1 },
@ -58,11 +58,11 @@ const timeAgo = ({ time, currentTime = new Date(), dense = false }: IProp): stri
if (monthDiff > 0) { if (monthDiff > 0) {
const unitAmount = monthDiff; const unitAmount = monthDiff;
return `${unitAmount}${dense ? timeUnits[i].unit[0] : ` ${timeUnits[i].full}`}${dense ? '' : 's'} ago`; return `${unitAmount}${dense ? timeUnits[i].unit : ` ${timeUnits[i].full}`}${dense ? '' : 's'} ago`;
} }
} else if (elapsed >= timeUnits[i].value) { } else if (elapsed >= timeUnits[i].value) {
const unitAmount: number = Math.floor(elapsed / timeUnits[i].value); const unitAmount: number = Math.floor(elapsed / timeUnits[i].value);
return `${unitAmount}${dense ? timeUnits[i].unit[0] : ` ${timeUnits[i].full}`}${dense ? '' : 's'} ago`; return `${unitAmount}${dense ? timeUnits[i].unit : ` ${timeUnits[i].full}`}${dense ? '' : 's'} ago`;
} }
} }
return 'Invalid Time'; return 'Invalid Time';