public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { return null; } $val = \Psc\DateTime\DateTime::parse($platform->getDateTimeFormatString(), $value); if (!$val) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString()); } return $val; }
protected function init() { if ($this->type == 'atom') { $this->title = (string) $this->xml->title; $this->pubDate = DateTime::parse(DateTime::ATOM, (string) $this->xml->published); $this->link = (string) $this->xml->link['href']; } else { $this->title = (string) $this->xml->title; $this->link = (string) $this->xml->link; $this->description = (string) $this->xml->description; $this->pubDate = DateTime::parse(DateTime::RSS, (string) $this->xml->pubDate); } }
/** * * Empty Data ist NULL * * @return DateTime */ public function validate($data) { if (is_integer($data) && $data > 0) { return new DateTime($data); } if ($data === NULL || !is_array($data) || !array_key_exists('date', $data) || $data['date'] == NULL || !$this->timeIsOptional && (!array_key_exists('time', $data) || $data['time'] == NULL)) { throw EmptyDataException::factory(NULL); } $data['time'] = !isset($data['time']) ? NULL : trim($data['time']); $dateRule = new DateValidatorRule('d.m.Y'); $date = $dateRule->validate($data['date']); // cooler: time validator rule if ($this->timeIsOptional && $data['time'] == NULL) { return new DateTime($date); // sets time to 00:00 } else { return DateTime::parse('d.m.Y H:i', $date->format('d.m.Y') . ' ' . $data['time']); } }
public function testParse() { $this->assertInstanceof('Psc\\DateTime\\DateTime', DateTime::parse(DateTime::RFC1123, 'Thu, 10 Nov 2011 07:28:18 GMT')); }
/** * @return NULL|Psc\DateTime\DateTime */ public function getDate() { $str = $this->getField('Date'); if ($str !== NULL) { //DateTime::COOKIE /* @TODO parseDate in HTTP:: Klasse HTTP applications have historically allowed three different formats for the representation of date/time stamps: Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format */ return DateTime::parse(DateTime::RFC1123, $str); } return NULL; }