From 602836ee5c9e2f076b3b681f435f19a8ada1a9f4 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 4 Jul 2019 04:58:18 +1000 Subject: [PATCH] Extract code converting a date object to local timezone object to own function --- CRM/Core/Payment/PayPalIPN.php | 4 +--- CRM/Utils/Date.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CRM/Core/Payment/PayPalIPN.php b/CRM/Core/Payment/PayPalIPN.php index 5e0a1034be..3ad4c74d27 100644 --- a/CRM/Core/Payment/PayPalIPN.php +++ b/CRM/Core/Payment/PayPalIPN.php @@ -398,9 +398,7 @@ class CRM_Core_Payment_PayPalIPN extends CRM_Core_Payment_BaseIPN { * The `payment_date` that Paypal sends back is in their timezone. Example return: 08:23:05 Jan 11, 2019 PST * Subsequently, we need to account for that, otherwise the recieve time will be incorrect for the local system */ - $systemTimeZone = new DateTimeZone(CRM_Core_Config::singleton()->userSystem->getTimeZoneString()); - $receiveDateTime->setTimezone($systemTimeZone); - $input['receive_date'] = $receiveDateTime->format('YmdHis'); + $input['receive_date'] = CRM_Utils_Date::convertDateToLocalTime($receiveDateTime); } } diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index 24b2f73880..fa96fca47f 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -2204,4 +2204,17 @@ class CRM_Utils_Date { } } + /** + * Print out a date object in specified format in local timezone + * + * @param DateTimeObject $dateObject + * @param string $format + * @return string + */ + public static function convertDateToLocalTime($dateObject, $format = 'YmdHis') { + $systemTimeZone = new DateTimeZone(CRM_Core_Config::singleton()->userSystem->getTimeZoneString()); + $dateObject->setTimezone($systemTimeZone); + return $dateObject->format($format); + } + } -- 2.25.1