diff options
| author | HJ <30-hj@users.noreply.git.pleroma.social> | 2022-06-19 20:28:29 +0000 |
|---|---|---|
| committer | HJ <30-hj@users.noreply.git.pleroma.social> | 2022-06-19 20:28:29 +0000 |
| commit | da022e722ed55de376d6f0475c78405e3f9b0d7e (patch) | |
| tree | c3fd750182b61484187fb0c6d9df593e3433309f /src/services/date_utils/date_utils.js | |
| parent | 2b10fe06fa0f518e61c507f09f6da6df760ffa30 (diff) | |
| parent | 13cff692f0633bfccb7896e774fcf4820ddbb4c2 (diff) | |
Merge branch 'from/develop/tusooa/unit-pl' into 'develop'
Use vue-i18n to determine plural forms of time units
Closes #1164
See merge request pleroma/pleroma-fe!1535
Diffstat (limited to 'src/services/date_utils/date_utils.js')
| -rw-r--r-- | src/services/date_utils/date_utils.js | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/services/date_utils/date_utils.js b/src/services/date_utils/date_utils.js index 32e13bca..677c184c 100644 --- a/src/services/date_utils/date_utils.js +++ b/src/services/date_utils/date_utils.js @@ -10,31 +10,29 @@ export const relativeTime = (date, nowThreshold = 1) => { if (typeof date === 'string') date = Date.parse(date) const round = Date.now() > date ? Math.floor : Math.ceil const d = Math.abs(Date.now() - date) - let r = { num: round(d / YEAR), key: 'time.years' } + let r = { num: round(d / YEAR), key: 'time.unit.years' } if (d < nowThreshold * SECOND) { r.num = 0 r.key = 'time.now' } else if (d < MINUTE) { r.num = round(d / SECOND) - r.key = 'time.seconds' + r.key = 'time.unit.seconds' } else if (d < HOUR) { r.num = round(d / MINUTE) - r.key = 'time.minutes' + r.key = 'time.unit.minutes' } else if (d < DAY) { r.num = round(d / HOUR) - r.key = 'time.hours' + r.key = 'time.unit.hours' } else if (d < WEEK) { r.num = round(d / DAY) - r.key = 'time.days' + r.key = 'time.unit.days' } else if (d < MONTH) { r.num = round(d / WEEK) - r.key = 'time.weeks' + r.key = 'time.unit.weeks' } else if (d < YEAR) { r.num = round(d / MONTH) - r.key = 'time.months' + r.key = 'time.unit.months' } - // Remove plural form when singular - if (r.num === 1) r.key = r.key.slice(0, -1) return r } |
