Beispiel #1
0
 /**
  * Return a set of arrays to construct a calendar month for
  * the given date.
  *
  * @param string year in format CCYY, default current local year
  * @param string month in format MM, default current local month
  * @param string format for returned date
  *
  * @access public
  *
  * @return array $month[$row][$col]
  */
 function getCalendarMonth($month = "", $year = "", $format = "%Y%m%d")
 {
     if (empty($year)) {
         $year = Date_Calc::dateNow("%Y");
     }
     if (empty($month)) {
         $month = Date_Calc::dateNow("%m");
     }
     $month_array = array();
     // date for the first row, first column of calendar month
     if (DATE_CALC_BEGIN_WEEKDAY == 1) {
         if (Date_Calc::firstOfMonthWeekday($month, $year) == 0) {
             $curr_day = Date_Calc::dateToDays("01", $month, $year) - 6;
         } else {
             $curr_day = Date_Calc::dateToDays("01", $month, $year) - Date_Calc::firstOfMonthWeekday($month, $year) + 1;
         }
     } else {
         $curr_day = Date_Calc::dateToDays("01", $month, $year) - Date_Calc::firstOfMonthWeekday($month, $year);
     }
     // number of days in this month
     $daysInMonth = Date_Calc::daysInMonth($month, $year);
     $weeksInMonth = Date_Calc::weeksInMonth($month, $year);
     for ($row_counter = 0; $row_counter < $weeksInMonth; $row_counter++) {
         for ($column_counter = 0; $column_counter <= 6; $column_counter++) {
             $month_array[$row_counter][$column_counter] = Date_Calc::daysToDate($curr_day, $format);
             $curr_day++;
         }
     }
     return $month_array;
 }
 /**
  * Returns the number of weeks in the month
  * @param int year (2003)
  * @param int month (9)
  * @param int first day of the week (default: monday)
  * @return int weeks number
  * @access protected
  */
 function getWeeksInMonth($y, $m, $firstDay = 1)
 {
     $FDOM = Date_Calc::firstOfMonthWeekday($m, $y);
     if ($FDOM > $firstDay) {
         $firstWeekDays = $this->getDaysInWeek() - $FDOM + $firstDay;
         $weeks = 1;
     } else {
         $firstWeekDays = $firstDay - $FDOM;
         $weeks = 0;
     }
     $firstWeekDays %= $this->getDaysInWeek();
     $result = (int) (ceil(($this->getDaysInMonth($y, $m) - $firstWeekDays) / $this->getDaysInWeek()) + $weeks);
     if ($FDOM != 0) {
         return $result;
     } else {
         return $result + 1;
     }
 }
Beispiel #3
0
function lastDateofAllweek($Month, $Year)
{
    $date = new Date();
    $Date_Calc = new Date_Calc();
    $date->setYear($Year);
    $date->setMonth($Month);
    $TotalWeek = $date->getWeeksInMonth();
    $daysMonth = $date->getDaysInMonth();
    $i = 1;
    $PassedDays = 0;
    while ($i <= $TotalWeek) {
        if (strlen($PassedDays) == 1) {
            $PassedDays = "0" . $PassedDays;
        }
        if ($i == 1) {
            $fstdayWeek = $Date_Calc->firstOfMonthWeekday($Month, $Year);
            $lastdayWeek = 7 - $fstdayWeek;
            $PassedDays = $lastdayWeek + 1;
            if (strlen($lastdayWeek) == 1) {
                $lastdayWeek = "0" . $lastdayWeek;
            }
            $Lastdate[$i - 1] = $Year . "-" . $Month . "-" . $lastdayWeek;
        } elseif ($i == $TotalWeek) {
            $remainDays = $daysMonth - $PassedDays;
            if (strlen($remainDays) == 1) {
                $remainDays = "0" . $remainDays;
            }
            $curWeekDays += $daysMonth - $curWeekDays;
            $Lastdate[$i - 1] = $Year . "-" . $Month . "-" . $daysMonth;
        } else {
            $PassedDays += 7;
            $lastdayWeek = $PassedDays - 1;
            if (strlen($lastdayWeek) == 1) {
                $lastdayWeek = "0" . $lastdayWeek;
            }
            $Lastdate[$i - 1] = $Year . "-" . $Month . "-" . $lastdayWeek;
        }
        $i++;
    }
    return $Lastdate;
}
Beispiel #4
0
 /**
  * Returns the number of weeks in the month
  * @param int year (2003)
  * @param int month (9)
  * @param int first day of the week (default: monday)
  * @return int weeks number
  * @access protected
  */
 function getWeeksInMonth($y, $m, $firstDay = 1)
 {
     $FDOM = Date_Calc::firstOfMonthWeekday($m, $y);
     if ($FDOM == 0) {
         $FDOM = $this->getDaysInWeek();
     }
     if ($FDOM > $firstDay) {
         $daysInTheFirstWeek = $this->getDaysInWeek() - $FDOM + $firstDay;
         $weeks = 1;
     } else {
         $daysInTheFirstWeek = $firstDay - $FDOM;
         $weeks = 0;
     }
     $daysInTheFirstWeek %= $this->getDaysInWeek();
     return (int) (ceil(($this->getDaysInMonth($y, $m) - $daysInTheFirstWeek) / $this->getDaysInWeek()) + $weeks);
 }
Beispiel #5
0
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');
compare('20001231', Date_Calc::endOfMonthBySpan(1, 11, 2000), 'endOfMonthBySpan 4');
compare('20011231', Date_Calc::endOfMonthBySpan(13, 11, 2000), 'endOfMonthBySpan 5');
compare('19990131', Date_Calc::endOfMonthBySpan('-13', '02', '2000'), 'endOfMonthBySpan 6 str');
compare('19990131', Date_Calc::endOfMonthBySpan(-13, 2, 2000), 'endOfMonthBySpan 6');
compare('20000131', Date_Calc::endOfMonthBySpan(-1, 2, 2000), 'endOfMonthBySpan 7');
compare('20000229', Date_Calc::endOfMonthBySpan(0, 2, 2000), 'endOfMonthBySpan 8');
compare('20000331', Date_Calc::endOfMonthBySpan(1, 2, 2000), 'endOfMonthBySpan 9');
compare('20010331', Date_Calc::endOfMonthBySpan(13, 2, 2000), 'endOfMonthBySpan 10');
compare('20010331', Date_Calc::endOfMonthBySpan('13', '02', '2000'), 'endOfMonthBySpan 10 str');
compare(3, Date_Calc::firstOfMonthWeekday(11, 2000), 'firstOfMonthWeekday');
compare(3, Date_Calc::firstOfMonthWeekday('11', '2000'), 'firstOfMonthWeekday str');
compare('20050101', Date_Calc::NWeekdayOfMonth(1, 6, 1, 2005), 'NWeekdayOfMonth 161');
compare('20050102', Date_Calc::NWeekdayOfMonth(1, 0, 1, 2005), 'NWeekdayOfMonth 101');
compare('20050103', Date_Calc::NWeekdayOfMonth(1, 1, 1, 2005), 'NWeekdayOfMonth 111');
compare('20050104', Date_Calc::NWeekdayOfMonth(1, 2, 1, 2005), 'NWeekdayOfMonth 121');
compare('20050105', Date_Calc::NWeekdayOfMonth(1, 3, 1, 2005), 'NWeekdayOfMonth 131');
compare('20050106', Date_Calc::NWeekdayOfMonth(1, 4, 1, 2005), 'NWeekdayOfMonth 141');
compare('20050107', Date_Calc::NWeekdayOfMonth(1, 5, 1, 2005), 'NWeekdayOfMonth 151');
compare('20050108', Date_Calc::NWeekdayOfMonth('2', '6', '01', '2005'), 'NWeekdayOfMonth 261');
compare('20050109', Date_Calc::NWeekdayOfMonth('2', '0', '01', '2005'), 'NWeekdayOfMonth 201');
compare('20050110', Date_Calc::NWeekdayOfMonth('2', '1', '01', '2005'), 'NWeekdayOfMonth 211');
compare('20050111', Date_Calc::NWeekdayOfMonth('2', '2', '01', '2005'), 'NWeekdayOfMonth 221');
compare('20050112', Date_Calc::NWeekdayOfMonth('2', '3', '01', '2005'), 'NWeekdayOfMonth 231');
compare('20050113', Date_Calc::NWeekdayOfMonth('2', '4', '01', '2005'), 'NWeekdayOfMonth 241');
compare('20050114', Date_Calc::NWeekdayOfMonth('2', '5', '01', '2005'), 'NWeekdayOfMonth 251');
compare('20050131', Date_Calc::NWeekdayOfMonth('last', 1, 1, 2005), 'NWeekdayOfMonth l11');