diff --git a/includes/class-PageYearMonthDay.php b/includes/class-PageYearMonthDay.php index db43ba5..379d4ba 100644 --- a/includes/class-PageYearMonthDay.php +++ b/includes/class-PageYearMonthDay.php @@ -1,64 +1,89 @@ . namespace itwikidelbot; +use DateTime; + /** * Abstraction of a page related to a day (in a certain month of a certain year) */ abstract class PageYearMonthDay extends PageYearMonth { /** * Day * * @var int 1-31 */ private $day; /** * Constructor * * @param $year int * @param $month int 1-12 * @param $day int 1-31 * @see PageYearMonth::__construct() */ public function __construct( $year, $month, $day ) { $this->day = $day; parent::__construct( $year, $month ); } + /** + * Static constructor + * + * @param $date_time DateTime + */ + public static function createFromDateTime( DateTime $datetime ) { + return new self( $datetime->format('Y'), $datetime->format('m'), $datetime->format('d') ); + } + /** * Get the day * * @return int 1-13 */ public function getDay() { return $this->day; } + /** + * Get a DateTime object + * + * @return DateTime + */ + public function getDateTime() { + return DateTime::createFromFormat( 'Y-m-d', sprintf( + '%d-%d-%d', + $this->getYear(), + $this->getMonth(), + $this->getDay() + ) ); + } + /** * Template arguments * * @override PageYearMonth::getTemplateArguments() */ public function getTemplateArguments() { return array_merge( parent::getTemplateArguments(), [ $this->getDay() ] ); } }