|
|
@@ -52,7 +52,7 @@ trait DateFormatTrait
|
|
|
* will be used for formatting the date part of the object and the second position
|
|
|
* will be used to format the time part.
|
|
|
*
|
|
|
- * @var string|array|int
|
|
|
+ * @var string|array|int|callable
|
|
|
* @see \Cake\I18n\Time::i18nFormat()
|
|
|
*/
|
|
|
protected static $_jsonEncodeFormat = "yyyy-MM-dd'T'HH':'mm':'ssxxx";
|
|
|
@@ -284,8 +284,11 @@ trait DateFormatTrait
|
|
|
* will be used for formatting the date part of the object and the second position
|
|
|
* will be used to format the time part.
|
|
|
*
|
|
|
+ * Alternatively, the format can provide a callback. In this case, the callback
|
|
|
+ * can receive this datetime object and return a formatted string.
|
|
|
+ *
|
|
|
* @see \Cake\I18n\Time::i18nFormat()
|
|
|
- * @param string|array|int $format Format.
|
|
|
+ * @param string|array|int|callable $format Format.
|
|
|
* @return void
|
|
|
*/
|
|
|
public static function setJsonEncodeFormat($format)
|
|
|
@@ -422,6 +425,10 @@ trait DateFormatTrait
|
|
|
*/
|
|
|
public function jsonSerialize()
|
|
|
{
|
|
|
+ if (is_callable(static::$_jsonEncodeFormat)) {
|
|
|
+ return call_user_func(static::$_jsonEncodeFormat, $this);
|
|
|
+ }
|
|
|
+
|
|
|
return $this->i18nFormat(static::$_jsonEncodeFormat);
|
|
|
}
|
|
|
|