tweeper.php: make date handling functions a little more robust
authorAntonio Ospite <ao2@ao2.it>
Tue, 5 May 2015 07:21:48 +0000 (09:21 +0200)
committerAntonio Ospite <ao2@ao2.it>
Tue, 5 May 2015 07:21:48 +0000 (09:21 +0200)
Provide at least _some_ error checking and a fall-back value for invalid
dates.

tweeper.php

index 37b73f5..81f5f85 100644 (file)
@@ -32,12 +32,20 @@ class Tweeper {
 
   public static function epoch_to_gmdate($timestamp)
   {
 
   public static function epoch_to_gmdate($timestamp)
   {
+    if (!is_numeric($timestamp) || is_nan($timestamp)) {
+      $timestamp = 0;
+    }
+
     return gmdate('D, d M Y H:i:s', $timestamp) . ' GMT';
   }
 
   public static function str_to_gmdate($date)
   {
     $timestamp = strtotime($date);
     return gmdate('D, d M Y H:i:s', $timestamp) . ' GMT';
   }
 
   public static function str_to_gmdate($date)
   {
     $timestamp = strtotime($date);
+    if (FALSE === $timestamp) {
+      $timestamp = 0;
+    }
+
     return Tweeper::epoch_to_gmdate($timestamp);
   }
 
     return Tweeper::epoch_to_gmdate($timestamp);
   }