public function setWith($value, $checkType = true) { $phpDate = \dateTime::createFromFormat(self::mysqlDateTimeFormat, $value); if ($phpDate !== false) { parent::setWith($phpDate, $checkType); } else { parent::setWith($value, false); if ($checkType === true) { $this->fail(sprintf($this->getLocale()->_('%s is not in format Y-m-d H:i:s'), $this)); } } return $this; }
public function testHasDateAndTime() { $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) { $asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Instance of \\dateTime is undefined')->if($asserter->setWith($dateTime = new \DateTime('1981-02-13 01:02:03')))->then->exception(function () use(&$line, $asserter) { $line = __LINE__; $asserter->hasDateAndTime(1900, 1, 1, 4, 5, 6); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Datetime is %s instead of %s'), '1981-02-13 01:02:03', '1900-01-01 04:05:06'))->object($asserter->hasDateAndTime('1981', '02', '13', '01', '02', '03'))->isIdenticalTo($asserter)->object($asserter->hasDateAndTime('1981', '2', '13', '1', '2', '3'))->isIdenticalTo($asserter)->object($asserter->hasDateAndTime(1981, 2, 13, 1, 2, 3))->isIdenticalTo($asserter); }
protected function getDates(\dateInterval $interval) { $this->valueIsSet(); $date1 = new \dateTime(); $date2 = clone $date1; return array($date1->add($this->value), $date2->add($interval)); }
public function getValue() { $value = parent::getValue(); return $value instanceof \dateTime === false ? $value : $value->format(self::mysqlDateTimeFormat); }