Skip to content

Fix null dates returning as December 31, 1969

JonGold requested to merge JonGold/stripe:dec-31 into master

@laryn @mattwire MR !44 (merged) didn't work for me, so I traced the problem down a bit further. !44 (merged) fixes one of two code paths that call CRM_Core_Payment_StripeIPN::retrieve() on receive_date.

The actual problem is that the statements in retrieve() (or, in master, in CRM_Stripe_Api::getObjectParams()) mostly attempt to retrieve a property of an object, and if the property doesn't exist, the default is NULL.

However, those methods handle dates differently, converting them to a formatted string with date(). Calling date() on NULL results in the string "December 31, 1969".

This MR fixes it. I know I shouldn't have also mixed in the whitespace cleanup, but it's extraordinarily minimal so my apologies!

I could submit a patch against 5.3.2 if 5.3.3 will be released before 5.4. If not, here's the diff for others who need it:

+++ b/sites/all/civicrm-custom/extensions/com.drastikbydesign.stripe/CRM/Core/Payment/StripeIPN.php
@@ -189,7 +189,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
             break;
 
           case 'receive_date':
-            $value = date("Y-m-d H:i:s", $this->_inputParameters->data->object->date);
+            $value = $this->_inputParameters->data->object->date ? date("Y-m-d H:i:s", $this->_inputParameters->data->object->date) : NULL;
             break;
 
           case 'subscription_id':
@@ -221,7 +221,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
             break;
 
           case 'plan_start':
-            $value = date("Y-m-d H:i:s", $this->_inputParameters->data->object->start);
+            $value = $this->_inputParameters->data->object->start ? date("Y-m-d H:i:s", $this->_inputParameters->data->object->start) : NULL;
             break;
 
           case 'subscription_id':

Merge request reports

Loading