Bug 30059: Deal with timezones
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 3 Mar 2022 09:21:48 +0000 (10:21 +0100)
committerFridolin Somers <fridolin.somers@biblibre.com>
Fri, 25 Mar 2022 00:22:10 +0000 (14:22 -1000)
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>
koha-tmpl/intranet-tmpl/prog/en/includes/js-patron-get-age.inc

index c4ab0c0..25d8244 100644 (file)
@@ -1,14 +1,25 @@
 <!-- js-patron-get-age.inc -->
+[% USE KohaDates %]
 <script>
     (function() {
 
+        const tz = '[% KohaDates.tz | html %]';
         window.$get_age = function(dob, options) {
             if(!dob) return '';
 
-            var today = new Date();
+            let today = new Date();
             dob = new Date(dob);
-            var age = today.getFullYear() - dob.getFullYear();
-            var m = today.getMonth() - dob.getMonth();
+            if ( tz ) {
+                let today_tz = new Date(today.toLocaleString('en-US', {timeZone: tz}));
+                let diff = today.getTime() - today_tz.getTime();
+                today = new Date(today.getTime() - diff);
+
+                let dob_tz = new Date(dob.toLocaleString('en-US', {timeZone: tz}));
+                diff = dob.getTime() - dob_tz.getTime();
+                dob = new Date(dob.getTime() - diff);
+            }
+            let age = today.getFullYear() - dob.getFullYear();
+            let m = today.getMonth() - dob.getMonth();
             if (m < 0 || (m === 0 && today.getDate() < dob.getDate())) {
                 age--;
             }