From 144ca9c5feaf9c7b0a8b9d5523233200e835e842 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 21 Aug 2016 19:17:01 -0700 Subject: [PATCH] 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 --- includes/MWTimestamp.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 ); + } } /** -- 2.20.1