/** * Check a given value * * @param array value * @return string error or NULL on success */ public function check($value) { foreach ($value as $v) { try { DateParser::parse($v); } catch (FormatException $e) { return 'invalid'; } } }
/** * Helper method * * @param string input * @param bool lower whether this is the lower boundary * @return util.Date */ protected function parseDate($input, $lower) { switch ($input) { case '__NOW__': if ($lower) { $r = DateUtil::getMidnight(Date::now()); } else { $r = DateUtil::getMidnight(DateUtil::addDays(Date::now(), 1)); } break; case '__FUTURE__': $r = Date::now(); break; case '__UNLIMITED__': $r = NULL; break; default: $r = DateParser::parse($input); } return $r; }
/** * Umarshall method for deserialize data from wddx message * * @param xml.Node node * @return var[] * @throws lang.IllegalArgumentException if document is not well-formed */ protected function _unmarshall($node) { switch ($node->getName()) { case 'null': return NULL; case 'boolean': return $node->getContent() == 'true' ? TRUE : FALSE; case 'string': return $node->getContent(); case 'dateTime': $parser = new DateParser(); return $parser->parse($node->getContent()); case 'number': if ($node->getContent() == intval($node->getContent())) { return intval($node->getContent()); } return (double) $node->getContent(); case 'char': return chr($node->getAttribute('code')); case 'binary': // TBI return; case 'array': $arr = array(); foreach (array_keys($node->getChildren()) as $idx) { $arr[] = $this->_unmarshall($node->nodeAt($idx)); } return $arr; case 'struct': $struct = array(); foreach (array_keys($node->getChildren()) as $idx) { $struct[$node->nodeAt($idx)->getAttribute('name')] = $this->_unmarshall($node->nodeAt($idx)); } return $struct; } throw new IllegalArgumentException('Cannot unserialize not well-formed WDDX document'); }
/** * Parse dates in a variety of formats and create a Date object. * * @param string|int The date to parse * @param string|int The time to parse (ignored, use the DateTime class for time parsing) * * @return Date */ public static function parse($date, $time = null) { $parser = new DateParser(); $parser->addDefaultParsers(); return $parser->parse($date); }
/** * Set Modified * * @param &lang.Object modified */ public function setModified($modified) { if (is('util.Date', $modified)) { $this->modified = $modified; return; } try { $d = DateParser::parse(urldecode($modified)); } catch (FormatException $e) { // Date could not be parsed, so default to now. $this->modified = Date::now(); } $this->modified = $d; }