Bug 30059: Add JS equivalent for Koha::Patron->get_age
On bug 30055 we are going to use the REST API to display the patron search result, we will then need to calculate patron's age client-side. This is moved to its own bug report in case we need to reuse it somewhere else. Test plan: Copy/paste the JS function in your browser's console then call it and confirm that the result is correct For instance: $get_age('2000-01-01') Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
b752522a19
commit
81160bc1ae
1 changed files with 20 additions and 0 deletions
|
@ -0,0 +1,20 @@
|
|||
<!-- js-patron-get-age.inc -->
|
||||
<script>
|
||||
(function() {
|
||||
|
||||
window.$get_age = function(dob, options) {
|
||||
if(!dob) return '';
|
||||
|
||||
var today = new Date();
|
||||
dob = new Date(dob);
|
||||
var age = today.getFullYear() - dob.getFullYear();
|
||||
var m = today.getMonth() - dob.getMonth();
|
||||
if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) {
|
||||
age--;
|
||||
}
|
||||
return age;
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
<!-- / js-patron-get-age.inc -->
|
Loading…
Reference in a new issue