week_start; $this->startDate = new DateAndTime(); $this->startDate->setFormat($date_point->getFormat()); $this->endDate = new DateAndTime(); $this->endDate->setFormat($date_point->getFormat()); $t_arr = localtime($date_point->getTimestamp()); $t_arr[5] = $t_arr[5] + 1900; if ($t_arr[6] < $weekStartDay) { $startWeekBias = $weekStartDay - 7; } else { $startWeekBias = $weekStartDay; } switch ($period_type) { case INTERVAL_THIS_DAY: $this->startDate->setTimestamp($date_point->getTimestamp()); $this->endDate->setTimestamp($date_point->getTimestamp()); break; case INTERVAL_LAST_DAY: $this->startDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,$t_arr[3]-1,$t_arr[5])); $this->endDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,$t_arr[3]-1,$t_arr[5])); break; case INTERVAL_THIS_WEEK: $this->startDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,$t_arr[3]-$t_arr[6]+$startWeekBias,$t_arr[5])); $this->endDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,$t_arr[3]-$t_arr[6]+6+$startWeekBias,$t_arr[5])); break; case INTERVAL_LAST_WEEK: $this->startDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,$t_arr[3]-$t_arr[6]-7+$startWeekBias,$t_arr[5])); $this->endDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,$t_arr[3]-$t_arr[6]-1+$startWeekBias,$t_arr[5])); break; case INTERVAL_THIS_MONTH: $this->startDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,1,$t_arr[5])); $this->endDate->setTimestamp(mktime(0,0,0,$t_arr[4]+2,0,$t_arr[5])); break; case INTERVAL_LAST_MONTH: $this->startDate->setTimestamp(mktime(0,0,0,$t_arr[4],1,$t_arr[5])); $this->endDate->setTimestamp(mktime(0,0,0,$t_arr[4]+1,0,$t_arr[5])); break; case INTERVAL_THIS_YEAR: $this->startDate->setTimestamp(mktime(0, 0, 0, 1, 1, $t_arr[5])); $this->endDate->setTimestamp(mktime(0, 0, 0, 12, 31, $t_arr[5])); break; } } function setPeriod($b_date, $e_date) { $this->startDate = $b_date; $this->endDate = $e_date; } // return date string function getStartDate($format="") { return $this->startDate->toString($format); } // return date string function getEndDate($format="") { return $this->endDate->toString($format); } }