2024-03-08 16:37:30 +07:00
|
|
|
export function calculateAge(start: Date, end = new Date()) {
|
2024-05-17 15:34:21 +07:00
|
|
|
if (start.getTime() > end.getTime()) return null;
|
2024-03-08 16:37:30 +07:00
|
|
|
|
|
|
|
|
let year = end.getFullYear() - start.getFullYear();
|
|
|
|
|
let month = end.getMonth() - start.getMonth();
|
|
|
|
|
let day = end.getDate() - start.getDate();
|
|
|
|
|
|
2024-07-01 17:27:01 +07:00
|
|
|
// if (month < 0) {
|
|
|
|
|
// month += 12;
|
|
|
|
|
// year -= 1;
|
|
|
|
|
// }
|
|
|
|
|
// if (day < 0) {
|
|
|
|
|
// month -= 1;
|
|
|
|
|
// day =
|
|
|
|
|
// new Date(start.getFullYear(), start.getMonth(), 0).getDate() -
|
|
|
|
|
// start.getDate() +
|
|
|
|
|
// end.getDate();
|
|
|
|
|
// }
|
|
|
|
|
|
2024-07-03 00:36:23 +07:00
|
|
|
if (day < 0) {
|
|
|
|
|
month -= 1;
|
|
|
|
|
day += new Date(end.getFullYear(), end.getMonth(), 0).getDate();
|
|
|
|
|
}
|
2024-07-01 17:27:01 +07:00
|
|
|
|
2024-07-03 00:36:23 +07:00
|
|
|
if (month < 0) {
|
|
|
|
|
month += 12;
|
|
|
|
|
year -= 1;
|
|
|
|
|
}
|
2024-03-08 16:37:30 +07:00
|
|
|
|
|
|
|
|
return { year, month, day };
|
|
|
|
|
}
|
2024-03-08 17:20:39 +07:00
|
|
|
|
|
|
|
|
export function calculateRetireDate(birthDate: Date) {
|
2024-07-03 00:36:23 +07:00
|
|
|
// let _birthDate = birthDate;
|
|
|
|
|
|
|
|
|
|
// _birthDate.setFullYear(_birthDate.getFullYear() + 60); var year = d.getFullYear();
|
|
|
|
|
var d = birthDate;
|
|
|
|
|
var year = d.getFullYear();
|
|
|
|
|
var month = d.getMonth();
|
|
|
|
|
var day = d.getDate();
|
|
|
|
|
var c = new Date(year + 60, month, day);
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
export function calculateRetireLaw(birthDate: Date) {
|
2024-03-08 17:20:39 +07:00
|
|
|
let dd = birthDate.getDate();
|
|
|
|
|
let mm = birthDate.getMonth();
|
|
|
|
|
let yy = birthDate.getFullYear();
|
|
|
|
|
|
|
|
|
|
let flag = true;
|
|
|
|
|
|
|
|
|
|
switch (mm) {
|
2024-07-03 00:36:23 +07:00
|
|
|
case 9:
|
2024-03-08 17:20:39 +07:00
|
|
|
if (dd >= 2) flag = false;
|
|
|
|
|
break;
|
2024-07-03 00:36:23 +07:00
|
|
|
case 10:
|
|
|
|
|
flag = false;
|
2024-03-26 09:47:17 +07:00
|
|
|
break;
|
2024-07-03 00:36:23 +07:00
|
|
|
case 11:
|
|
|
|
|
flag = false;
|
2024-03-08 17:20:39 +07:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-03 00:36:23 +07:00
|
|
|
if (flag == true) return new Date(`${yy + 60}-09-30T00:00:00.000+07:00`);
|
2024-03-08 17:20:39 +07:00
|
|
|
|
2024-03-11 10:45:40 +07:00
|
|
|
return new Date(`${yy + 61}-09-30T00:00:00.000+07:00`);
|
2024-03-08 17:20:39 +07:00
|
|
|
}
|
2024-03-26 09:47:17 +07:00
|
|
|
|
|
|
|
|
export function calculateRetireYear(birthDate: Date) {
|
|
|
|
|
let dd = birthDate.getDate();
|
|
|
|
|
let mm = birthDate.getMonth();
|
|
|
|
|
let yy = birthDate.getFullYear();
|
|
|
|
|
|
|
|
|
|
let flag = true;
|
|
|
|
|
|
|
|
|
|
switch (mm) {
|
|
|
|
|
case 10:
|
|
|
|
|
if (dd >= 2) flag = false;
|
|
|
|
|
break;
|
|
|
|
|
case 11:
|
|
|
|
|
break;
|
|
|
|
|
case 12:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flag) return yy + 60;
|
|
|
|
|
|
|
|
|
|
return yy + 61;
|
|
|
|
|
}
|