From 92cc5ee210dc9827b72b9914d7b271e5e17e4845 Mon Sep 17 00:00:00 2001 From: gggeek <giunta.gaetano@gmail.com> Date: Thu, 12 Jan 2023 17:33:52 +0000 Subject: [PATCH] allow more DateTime use --- NEWS.md | 2 ++ src/Helper/Date.php | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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 { -- 2.47.0