Merge branch 'develop' into adiDev
This commit is contained in:
commit
823fcb8ea8
6 changed files with 294 additions and 6 deletions
|
|
@ -171,6 +171,78 @@ class Extension {
|
|||
}
|
||||
return citizen;
|
||||
}
|
||||
|
||||
public static CalculateGovAge(appointDate: Date, plusYear: number = 0, subtractYear: number = 0): number {
|
||||
if (appointDate == null || appointDate == undefined) return 0
|
||||
const now = new Date();
|
||||
if (now.getMonth() - appointDate.getMonth() >= 6) {
|
||||
return (now.getFullYear() - appointDate.getFullYear()) + 1 + plusYear - subtractYear;
|
||||
}
|
||||
else {
|
||||
return (now.getFullYear() - appointDate.getFullYear()) + plusYear - subtractYear;
|
||||
}
|
||||
}
|
||||
|
||||
public static CalculateAge(appointDate: Date, plusYear: number = 0, subtractYear: number = 0) {
|
||||
let currentDate = new Date().getTime();
|
||||
let appointDateTime = new Date(appointDate).getTime();
|
||||
let ageInMilliseconds = currentDate - appointDateTime;
|
||||
let ageInDays = ageInMilliseconds / (1000 * 60 * 60 * 24);
|
||||
let years = Math.floor(ageInDays / 365.25) + plusYear - subtractYear;
|
||||
return years;
|
||||
}
|
||||
|
||||
public static CalculateAgeStrV2(date: Date, plusYear: number = 0, subtractYear: number = 0) {
|
||||
if (date == null || date == undefined) return ""
|
||||
const currentDate = new Date();
|
||||
if (date > currentDate) {
|
||||
throw new Error("วันเกิดต้องไม่มากกว่าวันที่ปัจจุบัน");
|
||||
}
|
||||
|
||||
let years = currentDate.getFullYear() - date.getFullYear();
|
||||
let months = 0;
|
||||
let days = 0;
|
||||
|
||||
if (currentDate.getMonth() < date.getMonth() || (currentDate.getMonth() === date.getMonth() && currentDate.getDate() < date.getDate())) {
|
||||
years--;
|
||||
months = 12 - date.getMonth() + currentDate.getMonth();
|
||||
|
||||
if (currentDate.getDate() < date.getDate()) {
|
||||
months--;
|
||||
let lastMonthDays = 0;
|
||||
if (currentDate.getMonth() === 0) {
|
||||
lastMonthDays = new Date(currentDate.getFullYear() - 1, 11, 0).getDate();
|
||||
}
|
||||
else {
|
||||
lastMonthDays = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate();
|
||||
days = lastMonthDays - date.getDate() + currentDate.getDate();
|
||||
}
|
||||
}
|
||||
else {
|
||||
days = currentDate.getDate() - date.getDate();
|
||||
}
|
||||
}
|
||||
else {
|
||||
months = currentDate.getMonth() - date.getMonth();
|
||||
|
||||
if (currentDate.getDate() < date.getDate()) {
|
||||
months--;
|
||||
let lastMonthDays = 0;
|
||||
if (currentDate.getMonth() === 0) {
|
||||
lastMonthDays = new Date(currentDate.getFullYear() - 1, 11, 0).getDate();
|
||||
}
|
||||
else {
|
||||
lastMonthDays = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate();
|
||||
days = lastMonthDays - date.getDate() + currentDate.getDate();
|
||||
}
|
||||
}
|
||||
else {
|
||||
days = currentDate.getDate() - date.getDate();
|
||||
}
|
||||
}
|
||||
years += plusYear - subtractYear;
|
||||
return `${years} ปี ${months} เดือน ${days} วัน`;
|
||||
}
|
||||
}
|
||||
|
||||
export default Extension;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue