forked from FoundKeyGang/FoundKey
change rounding for dates/times
This commit is contained in:
parent
2c69cb4a92
commit
0cb4529ed0
1 changed files with 13 additions and 5 deletions
|
@ -37,20 +37,28 @@ let now = $ref(new Date());
|
|||
const relative = $computed(() => {
|
||||
const ago = now.getTime() - _time.getTime();
|
||||
|
||||
function rounded(n: number): string {
|
||||
if (n % 1 >= 0.5) {
|
||||
return Math.floor(n).toString() + "½"
|
||||
} else {
|
||||
return Math.floor(n).toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (ago >= YEAR) {
|
||||
return i18n.t('_ago.yearsAgo', { n: Math.round(ago / YEAR).toString() });
|
||||
return i18n.t('_ago.yearsAgo', { n: rounded(ago / YEAR) });
|
||||
} else if (ago >= MONTH) {
|
||||
return i18n.t('_ago.monthsAgo', { n: Math.round(ago / MONTH).toString() });
|
||||
return i18n.t('_ago.monthsAgo', { n: rounded(ago / MONTH) });
|
||||
} else if (ago >= WEEK) {
|
||||
return i18n.t('_ago.weeksAgo', { n: Math.round(ago / WEEK).toString() });
|
||||
return i18n.t('_ago.weeksAgo', { n: rounded(ago / WEEK) });
|
||||
} else if (ago >= DAY) {
|
||||
return i18n.t('_ago.daysAgo', { n: Math.round(ago / DAY).toString() });
|
||||
return i18n.t('_ago.daysAgo', { n: rounded(ago / DAY) });
|
||||
}
|
||||
|
||||
// if the format is 'date', the relative date precision is no more than days ago
|
||||
if (props.format !== 'date') {
|
||||
if (ago >= HOUR) {
|
||||
return i18n.t('_ago.hoursAgo', { n: Math.round(ago / HOUR).toString() });
|
||||
return i18n.t('_ago.hoursAgo', { n: rounded(ago / HOUR) });
|
||||
} else if (ago >= MINUTE) {
|
||||
return i18n.t('_ago.minutesAgo', { n: Math.floor(ago / MINUTE).toString() });
|
||||
} else if (ago >= 10 * SECOND) {
|
||||
|
|
Loading…
Reference in a new issue