fix
This commit is contained in:
parent
54a743532b
commit
928d806313
1 changed files with 22 additions and 11 deletions
|
|
@ -5,17 +5,28 @@ export function calculateAge(start: Date, end = new Date()) {
|
|||
let month = end.getMonth() - start.getMonth();
|
||||
let day = end.getDate() - start.getDate();
|
||||
|
||||
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();
|
||||
}
|
||||
// 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();
|
||||
// }
|
||||
|
||||
if (day < 0) {
|
||||
month -= 1;
|
||||
day += new Date(end.getFullYear(), end.getMonth(), 0).getDate();
|
||||
}
|
||||
|
||||
if (month < 0) {
|
||||
month += 12;
|
||||
year -= 1;
|
||||
}
|
||||
|
||||
|
||||
return { year, month, day };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue