From: gggeek Date: Thu, 12 Jan 2023 17:33:52 +0000 (+0000) Subject: allow more DateTime use X-Git-Tag: 4.10.0~165 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=92cc5ee210dc9827b72b9914d7b271e5e17e4845;p=plcapi.git allow more DateTime use --- diff --git a/NEWS.md b/NEWS.md index 24fb32ab..4e82a45e 100644 --- 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 diff --git a/src/Helper/Date.php b/src/Helper/Date.php index 011b7bf4..94b54f70 100644 --- a/src/Helper/Date.php +++ b/src/Helper/Date.php @@ -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 {