From cfd391c0761be7846b2f24ef75007dfd92fdb51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de> Date: Mon, 5 Sep 2016 16:23:02 +0200 Subject: [PATCH] refs #7971: * implemented helper function to add time in FincILS --- module/finc/src/finc/ILS/Driver/FincILS.php | 43 ++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/module/finc/src/finc/ILS/Driver/FincILS.php b/module/finc/src/finc/ILS/Driver/FincILS.php index a94509ffe5c..6226f8facf6 100644 --- a/module/finc/src/finc/ILS/Driver/FincILS.php +++ b/module/finc/src/finc/ILS/Driver/FincILS.php @@ -30,7 +30,8 @@ use VuFind\Exception\ILS as ILSException, VuFindSearch\Query\Query, VuFindSearch\Service as SearchService, ZfcRbac\Service\AuthorizationServiceAwareInterface, ZfcRbac\Service\AuthorizationServiceAwareTrait, - Zend\Log\LoggerAwareInterface as LoggerAwareInterface; + Zend\Log\LoggerAwareInterface as LoggerAwareInterface, + DateTime, DateInterval, DateTimeZone; /** * Finc specific ILS Driver for VuFind, using PAIA and DAIA services. @@ -709,6 +710,46 @@ class FincILS extends PAIA implements LoggerAwareInterface } return $total / 100; } + + /** + * FincILS specific helper function to add time period + * + * @param string $date Date in DateTime format to used as base. + * @param null|int $years Years to be added to DateTime. + * @param null|int $months Months to be added to DateTime. + * @param null|int $days Days to be added to DateTime. + * @param null|int $hours Hours to be added to DateTime. + * @param null|int $minutes Minutes to be added to DateTime. + * @param null|int $seconds Seconds to be added to DateTime. + * + * @return string + */ + protected function addTime($date, $years = null, $months = null, $days = null, + $hours = null, $minutes = null, $seconds = null) + { + try { + // Get time zone + $timezone = isset($this->mainConfig->Site->timezone) + ? $this->mainConfig->Site->timezone : 'America/New_York'; + + // create DateTime object + $dateObj = new DateTime($date, new DateTimeZone($timezone)); + + $intervalSpec = 'P' . + ($years != null ? $years . 'Y' : '') . + ($months != null ? $months . 'M' : '') . + ($days != null ? $days . 'D' : '') . + ($hours != null ? $hours . 'H' : '') . + ($minutes != null ? 'T' . $minutes . 'M' : '') . + ($seconds != null ? $seconds . 'S' : ''); + $dateInterval = new DateInterval($intervalSpec); + + return $dateObj->add($dateInterval)->format('Y-m-d\TH:i:s'); + } catch (\Exception $e) { + $this->debug('Date adition failed: ' . $e->getMessage()); + return ''; + } + } /** * Helper function to create static ils response -- GitLab