]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/DateTimeFormat.php
Date check added for HTTP signatures
[friendica.git] / src / Util / DateTimeFormat.php
index b039ff80a170c4fc504e9f6ac95420ceff7b218c..8eead1d2e51919c2cc84f7444c65a17c70099996 100644 (file)
@@ -6,6 +6,7 @@
 
 namespace Friendica\Util;
 
+use Friendica\Core\Logger;
 use DateTime;
 use DateTimeZone;
 use Exception;
@@ -17,6 +18,7 @@ class DateTimeFormat
 {
        const ATOM = 'Y-m-d\TH:i:s\Z';
        const MYSQL = 'Y-m-d H:i:s';
+       const HTTP = 'D, d M Y H:i:s \G\M\T';
 
        /**
         * convert() shorthand for UTC.
@@ -90,12 +92,12 @@ class DateTimeFormat
        {
                // Defaults to UTC if nothing is set, but throws an exception if set to empty string.
                // Provide some sane defaults regardless.
-               if ($from === '') {
-                       $from = 'UTC';
+               if ($tz_from === '') {
+                       $tz_from = 'UTC';
                }
 
-               if ($to === '') {
-                       $to = 'UTC';
+               if ($tz_to === '') {
+                       $tz_to = 'UTC';
                }
 
                if (($s === '') || (!is_string($s))) {
@@ -109,6 +111,9 @@ class DateTimeFormat
                 * months and days always start with 1.
                 */
                if (substr($s, 0, 10) <= '0001-01-01') {
+                       if ($s < '0000-00-00') {
+                               $s = '0000-00-00';
+                       }
                        $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC'));
                        return str_replace('1', '0', $d->format($format));
                }
@@ -122,7 +127,7 @@ class DateTimeFormat
                try {
                        $d = new DateTime($s, $from_obj);
                } catch (Exception $e) {
-                       logger('DateTimeFormat::convert: exception: ' . $e->getMessage());
+                       Logger::log('DateTimeFormat::convert: exception: ' . $e->getMessage());
                        $d = new DateTime('now', $from_obj);
                }