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 }