-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathage.js
66 lines (52 loc) · 1.39 KB
/
age.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//console.log("age.js imported")
let BIRTH = new Date(2000, 0, 30);
function _get_now() {
let d = new Date();
return d;
}
function _is_birth_passed(birth) {
let _b = new Date(birth);
let _n = _get_now();
_b.setYear(_n.getYear());
return _n > _b;
}
//console.log ("birth passed", _is_birth_passed(BIRTH))
function _get_last_birth(birth) {
let n = _get_now();
let b = new Date(birth);
if (_is_birth_passed(birth)) {
b.setFullYear(n.getFullYear());
} else {
b.setFullYeat(n.getFullYear() - 1);
}
//console.log("lqst birth", b);
return b;
}
function _get_comming_birth(birth) {
let n = _get_now();
let b = new Date(birth);
if (_is_birth_passed(birth)) {
b.setFullYear(n.getFullYear() + 1);
} else {
b.setFullYear(n.getFullYear());
}
//console.log("comming birth", b)
return b;
}
function _get_year_time(birth) {
return (_get_comming_birth(birth) - _get_last_birth(birth)) / 1000;
}
function _get_spend_time(birth) {
return (_get_now() - _get_last_birth(birth)) / 1000;
}
function _get_age_t(birth) {
return _get_now().getFullYear() - birth.getFullYear();
}
function _get_age_f(birth) {
return _get_spend_time(birth) / _get_year_time(birth);
}
function get_age(birth) {
let age = _get_age_t(birth) + _get_age_f(birth);
//console.log("func, get_age, ret: ", age)
return age;
}