/** * Create a new Date. * * @param Year $year * @param Month $month * @param MonthDay $day * * @throws InvalidDateException */ public function __construct(Year $year, Month $month, MonthDay $day) { \DateTime::createFromFormat('Y-F-j', \sprintf('%d-%s-%d', $year->toNative(), $month, $day->toNative())); $nativeDateErrors = \DateTime::getLastErrors(); if ($nativeDateErrors['warning_count'] > 0 || $nativeDateErrors['error_count'] > 0) { throw new InvalidDateException($year->toNative(), $month->toNative(), $day->toNative()); } $this->year = $year; $this->month = $month; $this->day = $day; }
public function testNow() { $year = Year::now(); $this->assertEquals(date('Y'), $year->toNative()); }
public function testGetYear() { $date = new Date(new Year(2013), Month::DECEMBER(), new MonthDay(3)); $year = new Year(2013); $this->assertTrue($year->sameValueAs($date->getYear())); }