Пример #1
0
function efFormatDate($text, $args, &$parser)
{
    global $wgUseDynamicDates, $wgContLang;
    if ($wgUseDynamicDates) {
        $dp = new DateParser($wgContLang, DateParser::convertPref($parser->getOptions()->getDateFormat()));
        return $dp->reformat($text);
    } else {
        return $text;
    }
}
 /**
  * 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';
         }
     }
 }
Пример #3
0
 public function check()
 {
     if (!$this->separator) {
         return false;
     }
     if (DateParser::contains_ambiguous_keyword($this->raw_date)) {
         $this->is_ambiguous = true;
     }
     $month_name = DateParser::contains_a_month_name($this->parts);
     if (!$month_name) {
         return false;
     }
     $this->parts = \DateParser::strip_invalid_parts($this->parts);
     return parent::check();
 }
 /**
  * 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;
 }
Пример #5
0
 public function testParseIso8601()
 {
     $currentTimeStamp = time();
     $curentIsoDate = date('c', $currentTimeStamp);
     $this->assertEqual($currentTimeStamp, DateParser::parseIso8601($curentIsoDate));
     $date1 = "20001201T0154+0100";
     $date2 = "2000-12-01T02:54+0200";
     $date3 = "2000-12-01T00:54:00Z";
     $date4 = "20001201T02:54+0200";
     //$ts = 975632040;
     $ts = gmmktime(0, 54, 0, 12, 1, 2000);
     $this->assertEqual(DateParser::parseIso8601($date1), $ts);
     $this->assertEqual(DateParser::parseIso8601($date2), $ts);
     $this->assertEqual(DateParser::parseIso8601($date3), $ts);
     $this->assertEqual(DateParser::parseIso8601($date4), $ts);
     $this->assertEqual(DateParser::parseIso8601($date1), DateParser::parseIso8601($date2));
     $this->assertEqual(DateParser::parseIso8601($date1), DateParser::parseIso8601($date3));
     $this->assertEqual(DateParser::parseIso8601($date1), DateParser::parseIso8601($date4));
     $this->assertEqual(DateParser::parseIso8601($date2), DateParser::parseIso8601($date3));
     $this->assertEqual(DateParser::parseIso8601($date2), DateParser::parseIso8601($date4));
     $this->assertEqual(DateParser::parseIso8601($date3), DateParser::parseIso8601($date4));
 }
Пример #6
0
 /**
  * Parses a single date from a string.
  */
 protected static function parseSingleDate($string, $parseFormats)
 {
     $parsedDate = null;
     foreach ($parseFormats as $a) {
         $dp = new DateParser($a);
         if ($dp->strptime($string)) {
             $parsedDate = $dp;
             break;
         }
     }
     return $parsedDate;
 }
Пример #7
0
 /**
  * Parse a date given as an ISO8601 date or a timestamp
  * @return The corresponding timestamp
  */
 private function parseDate($s)
 {
     if (is_numeric($s)) {
         return $s;
     } else {
         return DateParser::parseIso8601($s);
     }
 }
 /**
  * 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');
 }
Пример #9
0
 /**
  * Gets events from database
  */
 function _get_events($p_fetch_sources = true)
 {
     global $db;
     $this->events = array();
     $sql = 'SELECT * FROM ' . TBL_FACT . ' WHERE indfamkey=' . $db->qstr($this->famkey);
     $rs = $db->Execute($sql);
     while ($row = $rs->FetchRow()) {
         $event =& new event($row, $p_fetch_sources);
         if ($event->type == $this->beginstatus) {
             $this->beginstatus_factkey = $row['factkey'];
             $dp = new DateParser();
             $this->date = $dp->FormatDateStr($row);
             $this->sort_date = $row['date1'];
             $this->place = $row['place'];
             $this->begin_event = $event;
         } elseif ($event->type == $this->endstatus) {
             $this->endstatus_factkey = $row['factkey'];
             $dp =& new DateParser();
             $this->enddate = $dp->FormatDateStr($row);
             $this->endplace = $row['place'];
             $this->end_event = $event;
         } else {
             array_push($this->events, $event);
         }
     }
     $this->event_count = count($this->events);
 }
Пример #10
0
 /**
  * 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);
 }
Пример #11
0
 /**
  * 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;
 }