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,14 +128,20 @@ export function calculateAge(
|
||||||
const months = ageDate.getUTCMonth();
|
const months = ageDate.getUTCMonth();
|
||||||
const days = ageDate.getUTCDate() - 1;
|
const days = ageDate.getUTCDate() - 1;
|
||||||
|
|
||||||
if (only) {
|
switch (only) {
|
||||||
return only === 'year' ? years : only === 'months' ? months : days;
|
case 'year':
|
||||||
|
return years;
|
||||||
|
case 'months':
|
||||||
|
return months;
|
||||||
|
case 'days':
|
||||||
|
return days;
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
const { locale } = i18n.global;
|
switch (i18n.global.locale.value) {
|
||||||
if (locale.value === 'tha') {
|
case Lang.Thai:
|
||||||
return `${years} ปี ${months !== 0 ? months + ' เดือน' : ''} ${days !== 0 ? days + ' วัน' : ''}`;
|
return `${years} ปี ${months !== 0 ? months + ' เดือน' : ''} ${days !== 0 ? days + ' วัน' : ''}`;
|
||||||
} else {
|
default:
|
||||||
return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `;
|
return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue