refactor: use switch case for better readability
This commit is contained in:
parent
ed423cfaf7
commit
d8062c9174
1 changed files with 13 additions and 7 deletions
|
|
@ -128,15 +128,21 @@ export function calculateAge(
|
|||
const months = ageDate.getUTCMonth();
|
||||
const days = ageDate.getUTCDate() - 1;
|
||||
|
||||
if (only) {
|
||||
return only === 'year' ? years : only === 'months' ? months : days;
|
||||
switch (only) {
|
||||
case 'year':
|
||||
return years;
|
||||
case 'months':
|
||||
return months;
|
||||
case 'days':
|
||||
return days;
|
||||
default:
|
||||
}
|
||||
|
||||
const { locale } = i18n.global;
|
||||
if (locale.value === 'tha') {
|
||||
return `${years} ปี ${months !== 0 ? months + ' เดือน' : ''} ${days !== 0 ? days + ' วัน' : ''} `;
|
||||
} else {
|
||||
return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `;
|
||||
switch (i18n.global.locale.value) {
|
||||
case Lang.Thai:
|
||||
return `${years} ปี ${months !== 0 ? months + ' เดือน' : ''} ${days !== 0 ? days + ' วัน' : ''}`;
|
||||
default:
|
||||
return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue