|
|
@@ -16,13 +16,14 @@ namespace Cake\Utility;
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
use IntlDateFormatter;
|
|
|
+use JsonSerializable;
|
|
|
|
|
|
/**
|
|
|
* Extends the built-in DateTime class to provide handy methods and locale-aware
|
|
|
* formatting helpers
|
|
|
*
|
|
|
*/
|
|
|
-class Time extends Carbon {
|
|
|
+class Time extends Carbon implements JsonSerializable {
|
|
|
|
|
|
/**
|
|
|
* The format to use when formatting a time using `Cake\Utility\Time::i18nFormat()`
|
|
|
@@ -637,4 +638,26 @@ class Time extends Carbon {
|
|
|
static::$_toStringFormat = $format;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Returns a string that should be serialized when converting this object to json
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function jsonSerialize() {
|
|
|
+ return $this->format(static::ISO8601);
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Returns the data that should be displayed when debugging this object
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function __debugInfo() {
|
|
|
+ return [
|
|
|
+ 'time' => $this->format(static::ISO8601),
|
|
|
+ 'timezone' => $this->getTimezone()->getName(),
|
|
|
+ 'fixedNowTime' => $this->hasTestNow() ? $this->getTestNow()->format(static::ISO8601) : false
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
}
|