diff --git a/packages/extension/entrypoints/github-issues.content/App.vue b/packages/extension/entrypoints/github-issues.content/App.vue index a12114e..a6fe814 100644 --- a/packages/extension/entrypoints/github-issues.content/App.vue +++ b/packages/extension/entrypoints/github-issues.content/App.vue @@ -15,22 +15,48 @@ const { data: issues } = useFetch(issueUrl, { return ctx } }).json() + +const formatter = new Intl.RelativeTimeFormat() + +function formatDate (date: Date) { + const diffInSeconds = (date.getTime() - Date.now()) / 1000 + const units: Array<{ unit: Intl.RelativeTimeFormatUnit, value: number }> = [ + { unit: 'second', value: diffInSeconds }, + { unit: 'minute', value: diffInSeconds / 60 }, + { unit: 'hour', value: diffInSeconds / 3600 }, + { unit: 'day', value: diffInSeconds / 86400 }, + { unit: 'month', value: diffInSeconds / 2592000 }, + { unit: 'year', value: diffInSeconds / 31536000 }, + ] + const { unit, value } = units.find(({ value }) => Math.abs(value) < 60) || units[units.length - 1]! + return formatter.format(Math.round(value), unit) +}