From cc8395f771d987ab82013a930135f39708ac6c29 Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Wed, 14 Aug 2019 10:52:32 +0300
Subject: [PATCH] Alma: Fix time zone handling when parsing dates and times.

---
 module/VuFind/src/VuFind/ILS/Driver/Alma.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/module/VuFind/src/VuFind/ILS/Driver/Alma.php b/module/VuFind/src/VuFind/ILS/Driver/Alma.php
index 092e3517bc3..e6f195eae04 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Alma.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Alma.php
@@ -1480,8 +1480,8 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
     {
         // Remove trailing Z from end of date
         // e.g. from Alma we get dates like 2012-07-13Z without time, which is wrong)
-        if (strpos($date, 'Z', (strlen($date) - 1))) {
-            $date = preg_replace('/Z{1}$/', '', $date);
+        if (strpos($date, 'T') === false && substr($date, -1) === 'Z') {
+            $date = substr($date, 0, -1);
         }
 
         $compactDate = "/^[0-9]{8}$/"; // e. g. 20120725
@@ -1489,7 +1489,7 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
         $euro = "/^[0-9]+\/[0-9]+\/[0-9]{4}$/"; // e. g. 13/7/2012
         $euroPad = "/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2,4}$/"; // e. g. 13/07/2012
         $datestamp = "/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/"; // e. g. 2012-07-13
-        $timestamp = "/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/";
+        $timestamp = "/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$/";
         // e. g. 2017-07-09T18:00:00
 
         if ($date == null || $date == '') {
@@ -1504,11 +1504,11 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
             return $this->dateConverter->convertToDisplayDate('d/m/y', $date);
         } elseif (preg_match($datestamp, $date) === 1) {
             return $this->dateConverter->convertToDisplayDate('Y-m-d', $date);
-        } elseif (preg_match($timestamp, substr($date, 0, 19)) === 1) {
+        } elseif (preg_match($timestamp, $date) === 1) {
             if ($withTime) {
                 return $this->dateConverter->convertToDisplayDateAndTime(
-                    'Y-m-d\TH:i:s',
-                    substr($date, 0, 19)
+                    'Y-m-d\TH:i:sT',
+                    $date
                 );
             } else {
                 return $this->dateConverter->convertToDisplayDate(
-- 
GitLab