Beispiel #1
0
 /**
  * A private method that returns the start and end dates
  * that bound the span, based based on a pre-defined 'friendly'
  * value.
  *
  * See the {@link OA_Admin_DaySpan::setSpanPresetValue()} method
  * for the pre-defined values.
  *
  * @param string $presetValue The preset value string.
  * @return array An array of two elements, "start" and "end",
  *               representing the start and end dates of
  *               the span, respectively.
  */
 function _getSpanDates($presetValue)
 {
     switch ($presetValue) {
         case 'today':
             $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             break;
         case 'yesterday':
             $oDateStart = new Date(Date_Calc::prevDay($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::prevDay($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             break;
         case 'this_week':
             $oDateStart = new Date(Date_Calc::beginOfWeek($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oSixDaySpan = new Date_Span();
             $oSixDaySpan->setFromDays(6);
             $oSevenDaySpan = new Date_Span();
             $oSevenDaySpan->setFromDays(7);
             // Now have week start and end when week starts on Sunday
             // Does the user want to start on a different day?
             $beginOfWeek = OA_Admin_DaySpan::getBeginOfWeek();
             if ($beginOfWeek > 0) {
                 $oRequiredDaysSpan = new Date_Span();
                 $oRequiredDaysSpan->setFromDays($beginOfWeek);
                 $oDateStart->addSpan($oRequiredDaysSpan);
                 $oDateToday = new Date($this->oNowDate->format('%Y-%m-%d'));
                 if ($oDateToday->getDayOfWeek() < $beginOfWeek) {
                     $oDateStart->subtractSpan($oSevenDaySpan);
                 }
             }
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             break;
         case 'last_week':
             $oDateStart = new Date(Date_Calc::beginOfPrevWeek($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oSixDaySpan = new Date_Span();
             $oSixDaySpan->setFromDays(6);
             $oSevenDaySpan = new Date_Span();
             $oSevenDaySpan->setFromDays(7);
             // Now have week start and end when week starts on Sunday
             // Does the user want to start on a different day?
             $beginOfWeek = OA_Admin_DaySpan::getBeginOfWeek();
             if ($beginOfWeek > 0) {
                 $oRequiredDaysSpan = new Date_Span();
                 $oRequiredDaysSpan->setFromDays($beginOfWeek);
                 $oDateStart->addSpan($oRequiredDaysSpan);
                 $oDateToday = new Date($this->oNowDate->format('%Y-%m-%d'));
                 if ($oDateToday->getDayOfWeek() < $beginOfWeek) {
                     $oDateStart->subtractSpan($oSevenDaySpan);
                 }
             }
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd->copy($oDateStart);
             $oDateEnd->addSpan($oSixDaySpan);
             break;
         case 'last_7_days':
             $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oSevenDaySpan = new Date_Span();
             $oSevenDaySpan->setFromDays(7);
             $oDateStart->subtractSpan($oSevenDaySpan);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'this_month':
             $oDateStart = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date($this->oNowDate->format('%Y-%m-%d'));
             break;
         case 'this_month_full':
             $oDateStart = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'this_month_remainder':
             $oDateStart = new Date($this->oNowDate->format('%Y-%m-%d'));
             $oDateEnd = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'next_month':
             $oDateStart = new Date(Date_Calc::beginOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::endOfNextMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             break;
         case 'last_month':
             $oDateStart = new Date(Date_Calc::beginOfPrevMonth($this->oNowDate->format('%d'), $this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oDateEnd = new Date(Date_Calc::beginOfMonth($this->oNowDate->format('%m'), $this->oNowDate->format('%Y')));
             $oOneDaySpan = new Date_Span();
             $oOneDaySpan->setFromDays(1);
             $oDateEnd->subtractSpan($oOneDaySpan);
             break;
         case 'all_stats':
             $oDateStart = null;
             $oDateEnd = null;
             break;
         case 'specific':
             $startDate = MAX_getStoredValue('startDate', date('Y-m-d'));
             $oDateStart = new Date($startDate);
             $endDate = MAX_getStoredValue('endDate', date('Y-m-d'));
             $oDateEnd = new Date($endDate);
             break;
     }
     $this->_setStartDate($oDateStart);
     $this->_setEndDate($oDateEnd);
     $aDates = array('start' => $oDateStart, 'end' => $oDateEnd);
     return $aDates;
 }
Beispiel #2
0
compare('20001126', Date_Calc::endOfWeek(22, 11, 2000), 'endOfWeek');
compare('20001126', Date_Calc::endOfWeek('22', '11', '2000'), 'endOfWeek str');
compare('20001113', Date_Calc::beginOfPrevWeek(22, 11, 2000), 'beginOfPrevWeek');
compare('20001127', Date_Calc::beginOfNextWeek(22, 11, 2000), 'beginOfNextWeek');
compare('20001113', Date_Calc::beginOfPrevWeek('22', '11', '2000'), 'beginOfPrevWeek str');
compare('20001127', Date_Calc::beginOfNextWeek('22', '11', '2000'), 'beginOfNextWeek str');
compare('20001101', Date_Calc::beginOfMonth(11, 2000), 'beginOfMonth');
compare('20001101', Date_Calc::beginOfMonth('11', '2000'), 'beginOfMonth str');
compare('20001001', Date_Calc::beginOfPrevMonth(22, 11, 2000), 'beginOfPrevMonth');
compare('20001031', Date_Calc::endOfPrevMonth(22, 11, 2000), 'endOfPrevMonth');
compare('20001001', Date_Calc::beginOfPrevMonth('22', '11', '2000'), 'beginOfPrevMonth str');
compare('20001031', Date_Calc::endOfPrevMonth('22', '11', '2000'), 'endOfPrevMonth str');
compare('20001201', Date_Calc::beginOfNextMonth(22, 11, 2000), 'beginOfNextMonth');
compare('20001231', Date_Calc::endOfNextMonth(22, 11, 2000), 'endOfNextMonth');
compare('20001201', Date_Calc::beginOfNextMonth('22', '11', '2000'), 'beginOfNextMonth str');
compare('20001231', Date_Calc::endOfNextMonth('22', '11', '2000'), 'endOfNextMonth str');
compare('19991001', Date_Calc::beginOfMonthBySpan(-13, 11, 2000), 'beginOfMonthBySpan 1');
compare('20001001', Date_Calc::beginOfMonthBySpan(-1, 11, 2000), 'beginOfMonthBySpan 2');
compare('20001101', Date_Calc::beginOfMonthBySpan(0, 11, 2000), 'beginOfMonthBySpan 3');
compare('20001201', Date_Calc::beginOfMonthBySpan(1, 11, 2000), 'beginOfMonthBySpan 4');
compare('20011201', Date_Calc::beginOfMonthBySpan(13, 11, 2000), 'beginOfMonthBySpan 5');
compare('19990101', Date_Calc::beginOfMonthBySpan('-13', '02', '2000'), 'beginOfMonthBySpan 6 str');
compare('19990101', Date_Calc::beginOfMonthBySpan(-13, 2, 2000), 'beginOfMonthBySpan 6');
compare('20000101', Date_Calc::beginOfMonthBySpan(-1, 2, 2000), 'beginOfMonthBySpan 7');
compare('20000201', Date_Calc::beginOfMonthBySpan(0, 2, 2000), 'beginOfMonthBySpan 8');
compare('20000301', Date_Calc::beginOfMonthBySpan(1, 2, 2000), 'beginOfMonthBySpan 9');
compare('20010301', Date_Calc::beginOfMonthBySpan(13, 2, 2000), 'beginOfMonthBySpan 10');
compare('20010301', Date_Calc::beginOfMonthBySpan('13', '02', '2000'), 'beginOfMonthBySpan 10 str');
compare('19991031', Date_Calc::endOfMonthBySpan(-13, 11, 2000), 'endOfMonthBySpan 1');
compare('20001031', Date_Calc::endOfMonthBySpan(-1, 11, 2000), 'endOfMonthBySpan 2');
compare('20001130', Date_Calc::endOfMonthBySpan(0, 11, 2000), 'endOfMonthBySpan 3');