Lines 1-14
Link Here
|
1 |
<!-- js-patron-get-age.inc --> |
1 |
<!-- js-patron-get-age.inc --> |
|
|
2 |
[% USE KohaDates %] |
2 |
<script> |
3 |
<script> |
3 |
(function() { |
4 |
(function() { |
4 |
|
5 |
|
|
|
6 |
const tz = '[% KohaDates.tz | html %]'; |
5 |
window.$get_age = function(dob, options) { |
7 |
window.$get_age = function(dob, options) { |
6 |
if(!dob) return ''; |
8 |
if(!dob) return ''; |
7 |
|
9 |
|
8 |
var today = new Date(); |
10 |
let today = new Date(); |
9 |
dob = new Date(dob); |
11 |
dob = new Date(dob); |
10 |
var age = today.getFullYear() - dob.getFullYear(); |
12 |
if ( tz ) { |
11 |
var m = today.getMonth() - dob.getMonth(); |
13 |
let today_tz = new Date(today.toLocaleString('en-US', {timeZone: tz})); |
|
|
14 |
let diff = today.getTime() - today_tz.getTime(); |
15 |
today = new Date(today.getTime() - diff); |
16 |
|
17 |
let dob_tz = new Date(dob.toLocaleString('en-US', {timeZone: tz})); |
18 |
diff = dob.getTime() - dob_tz.getTime(); |
19 |
dob = new Date(dob.getTime() - diff); |
20 |
} |
21 |
let age = today.getFullYear() - dob.getFullYear(); |
22 |
let m = today.getMonth() - dob.getMonth(); |
12 |
if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) { |
23 |
if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) { |
13 |
age--; |
24 |
age--; |
14 |
} |
25 |
} |
15 |
- |
|
|