Extract code converting a date object to local timezone object to own function
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 3 Jul 2019 18:58:18 +0000 (04:58 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Wed, 3 Jul 2019 18:58:18 +0000 (04:58 +1000)
CRM/Core/Payment/PayPalIPN.php
CRM/Utils/Date.php

index 5e0a1034be1feaba173335be77e25f0e6474da8e..3ad4c74d27597804fffa4dc7c95db0f2dc055270 100644 (file)
@@ -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);
     }
   }
 
index 24b2f7388072276ff11abec6307c7d3a34ba6b84..fa96fca47fa1a0394a2bd4cd7b6c781a3101d498 100644 (file)
@@ -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);
+  }
+
 }