From: Kunal Mehta Date: Mon, 22 Aug 2016 02:17:01 +0000 (-0700) Subject: MWTimestamp: Allow providing a DateTime object directly X-Git-Tag: 1.31.0-rc.0~5977 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=144ca9c5feaf9c7b0a8b9d5523233200e835e842;p=lhc%2Fweb%2Fwiklou.git MWTimestamp: Allow providing a DateTime object directly For cases where you already have a DateTime object on hand and want to use MWTimestamp's formatting code. Since MWTimestamp stores DateTime objects internally, just set it to the $timestamp member variable. Change-Id: Ie60392e32743d4d082d2c9347ef68418d5eb86ad --- diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php index 4964fe6cb4..defdc96777 100644 --- a/includes/MWTimestamp.php +++ b/includes/MWTimestamp.php @@ -56,10 +56,14 @@ class MWTimestamp { * * @since 1.20 * - * @param bool|string|int|float $timestamp Timestamp to set, or false for current time + * @param bool|string|int|float|DateTime $timestamp Timestamp to set, or false for current time */ public function __construct( $timestamp = false ) { - $this->setTimestamp( $timestamp ); + if ( $timestamp instanceof DateTime ) { + $this->timestamp = $timestamp; + } else { + $this->setTimestamp( $timestamp ); + } } /**