本文整理匯總了PHP中DateRange::parseString方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateRange::parseString方法的具體用法?PHP DateRange::parseString怎麽用?PHP DateRange::parseString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DateRange
的用法示例。
在下文中一共展示了DateRange::parseString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setDate
public function setDate($val)
{
if ($val == "0000-00-00 in press") {
//handle non dates
$val = "";
}
$this["published"] = trim($val) == "" ? "in press" : $val;
//we can't really reliably determine this, we should also store it as text
if (empty($val)) {
return $this->published_at = null;
}
if (preg_match("/^\\d{4}\$/", $val)) {
//strtotime can't handle YYYY
$val = "Jan 1, " . $val;
}
$range = DateRange::parseString($val);
if (isset($range)) {
//try date range
return $this->published_at = DTStore::date($range->getStartDate());
} else {
if (strtotime($val) !== false) {
//try regular parse
return $this->published_at = DTStore::date(strtotime($val));
} else {
if (preg_match("/(\\d{4})/", $val, $matches)) {
//try just a year
return $this->published_at = DTSTore::date(strtotime("Jan 1, " . $matches[1]));
} else {
return $this->published_at = null;
}
}
}
//give up
}