allow more DateTime use
authorgggeek <giunta.gaetano@gmail.com>
Thu, 12 Jan 2023 17:33:52 +0000 (17:33 +0000)
committergggeek <giunta.gaetano@gmail.com>
Thu, 12 Jan 2023 17:33:52 +0000 (17:33 +0000)
NEWS.md
src/Helper/Date.php

diff --git a/NEWS.md b/NEWS.md
index 24fb32a..4e82a45 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -11,6 +11,8 @@
 
 * improved: when calling `Client::multicall()`, the returned `Response` objects did not have any data in their `httpResponse`
 
+* new: method `Helper\Date::iso8601Encode` now accepts a DateTime input beside a timestamp
+
 * improved: added the library version number to the debugger title line
 
 * improved: made sure the test container has at least one locale with comma as decimal separator
index 011b7bf..94b54f7 100644 (file)
@@ -20,12 +20,15 @@ class Date
      * This routine always encodes to local time unless $utc is set to 1, in which case UTC output is produced and an
      * adjustment for the local timezone's offset is made
      *
-     * @param int $timet (timestamp)
+     * @param int|\DateTimeInterface $timet timestamp or datetime
      * @param bool|int $utc (0 or 1)
      * @return string
      */
     public static function iso8601Encode($timet, $utc = 0)
     {
+        if (is_a($timet, 'DateTimeInterface') || is_a($timet, 'DateTime')) {
+            $timet = $timet->getTimestamp();
+        }
         if (!$utc) {
             $t = date('Ymd\TH:i:s', $timet);
         } else {