corrected = false; $from = sfDate::getInstance($from); $to = sfDate::getInstance($to); if (!($to->get())) { $to->set(time()); } if (!$from->get()) { $from->set($to->get())->subtractYear(1); } if ($from->cmp($to) > 0) { $tmp = $from; $from = $to; $to = $tmp; $this->corrected = true; } $this->from = $from->setHour(0)->setMinute(0)->setSecond(0); $this->to = $to->setHour(23)->setMinute(59)->setSecond(59); } public static function fromArray($date) { $from = $to = null; if ($date) { if (isset($date['from'])) { if (is_array($date['from'])) { $from = $date['from']['year'].'/'.$date['from']['month'].'/'.$date['from']['day']; } else { $from = $date['from']; } } if (isset($date['to'])) { if (is_array($date['to'])) { $to = $date['to']['year'].'/'.$date['to']['month'].'/'.$date['to']['day']; } else { $to = $date['to']; } } } else { $to = sfDate::getInstance(time())->setHour(23)->setMinute(59)->setSecond(59); $from = sfDate::getInstance($to)->subtractYear(1)->setHour(0)->setMinute(0)->setSecond(0); } return new SiwappDateRange($from, $to); } public function isCorrected() { return $this->corrected; } public function getFrom() { return $this->from; } public function getTo() { return $this->to; } public function toArray() { return array( 'from' => array( 'year' => date('Y', $this->getFrom()->get()), 'month' => date('m', $this->getFrom()->get()), 'day' => date('d', $this->getFrom()->get()) ), 'to' => array( 'year' => date('Y', $this->getTo()->get()), 'month' => date('m', $this->getTo()->get()), 'day' => date('d', $this->getTo()->get()) ) ); } }