fix: calculate age function
This commit is contained in:
parent
422cad2046
commit
b3f04aa6cf
1 changed files with 12 additions and 4 deletions
|
|
@ -14,6 +14,7 @@ import {
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import useBranchStore from '../branch';
|
import useBranchStore from '../branch';
|
||||||
import { Branch } from '../branch/types';
|
import { Branch } from '../branch/types';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const branchStore = useBranchStore();
|
const branchStore = useBranchStore();
|
||||||
|
|
||||||
|
|
@ -66,17 +67,24 @@ const useUserStore = defineStore('api-user', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = ref<Pagination<User[]>>();
|
const data = ref<Pagination<User[]>>();
|
||||||
|
const { locale } = useI18n();
|
||||||
|
|
||||||
function calculateAge(birthDate: Date | null): string {
|
function calculateAge(birthDate: Date | null | string) {
|
||||||
if (!birthDate) return '';
|
if (!birthDate) return null;
|
||||||
const birthDateTimeStamp = new Date(birthDate).getTime();
|
const birthDateTimeStamp = new Date(birthDate).getTime();
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diff = now.getTime() - birthDateTimeStamp;
|
const diff = now.getTime() - birthDateTimeStamp;
|
||||||
|
|
||||||
const ageDate = new Date(diff);
|
const ageDate = new Date(diff);
|
||||||
const years = ageDate.getUTCFullYear() - 1970;
|
const years = ageDate.getUTCFullYear() - 1970;
|
||||||
const result = `${years} ปี`;
|
const months = ageDate.getUTCMonth();
|
||||||
return result;
|
const days = ageDate.getUTCDate() - 1;
|
||||||
|
|
||||||
|
if (locale.value === 'th-th') {
|
||||||
|
return `${years} ปี ${months !== 0 ? months + ' เดือน' : ''} ${days !== 0 ? days + ' วัน' : ''} `;
|
||||||
|
} else {
|
||||||
|
return `${years} years ${months !== 0 ? months + ' months' : ''} ${days !== 0 ? days + ' days' : ''} `;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchHqOption() {
|
async function fetchHqOption() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue