当前位置: 首页>>代码示例>>PHP>>正文


PHP Date_Calc::weeksInMonth方法代码示例

本文整理汇总了PHP中Date_Calc::weeksInMonth方法的典型用法代码示例。如果您正苦于以下问题:PHP Date_Calc::weeksInMonth方法的具体用法?PHP Date_Calc::weeksInMonth怎么用?PHP Date_Calc::weeksInMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Date_Calc的用法示例。


在下文中一共展示了Date_Calc::weeksInMonth方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  *
  * @global Horde_Prefs $prefs
  * @param Horde_Date $date
  *
  * @return Kronolith_View_Month
  */
 public function __construct(Horde_Date $date)
 {
     global $prefs;
     $this->month = $date->month;
     $this->year = $date->year;
     // Need to calculate the start and length of the view.
     $this->date = new Horde_Date($date);
     $this->date->mday = 1;
     $this->_startday = $this->date->dayOfWeek();
     $this->_daysInView = Date_Calc::weeksInMonth($this->month, $this->year) * 7;
     if (!$prefs->getValue('week_start_monday')) {
         $this->_startOfView = 1 - $this->_startday;
         // We may need to adjust the number of days in the view if
         // we're starting weeks on Sunday.
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_daysInView -= 7;
         }
         $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($this->month, $this->year), 'month' => $this->month, 'year' => $this->year));
         $endday = $endday->dayOfWeek();
         if ($endday == Horde_Date::DATE_SUNDAY) {
             $this->_daysInView += 7;
         }
     } else {
         if ($this->_startday == Horde_Date::DATE_SUNDAY) {
             $this->_startOfView = -5;
         } else {
             $this->_startOfView = 2 - $this->_startday;
         }
     }
     $startDate = new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->_startOfView));
     $endDate = new Horde_Date(array('year' => $this->year, 'month' => $this->month, 'mday' => $this->_startOfView + $this->_daysInView));
     if ($prefs->getValue('show_shared_side_by_side')) {
         $allCalendars = Kronolith::listInternalCalendars();
         $this->_currentCalendars = array();
         foreach ($GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS) as $id) {
             $this->_currentCalendars[$id] = $allCalendars[$id];
         }
     } else {
         $this->_currentCalendars = array('internal_0' => true);
     }
     try {
         $this->_events = Kronolith::listEvents($startDate, $endDate);
     } catch (Exception $e) {
         $GLOBALS['notification']->push($e, 'horde.error');
         $this->_events = array();
     }
     if (!is_array($this->_events)) {
         $this->_events = array();
     }
 }
开发者ID:DSNS-LAB,项目名称:Dmail,代码行数:57,代码来源:Month.php

示例2: getWeeksInMonth

 /**
  * Gets the number of weeks in the month for this date
  *
  * Gets the number of weeks in the month for this date
  *
  * @access public
  * @return int number of weeks in this month
  */
 function getWeeksInMonth()
 {
     return Date_Calc::weeksInMonth($this->month, $this->year);
 }
开发者ID:mickdane,项目名称:zidisha,代码行数:12,代码来源:Date.php

示例3: getCalendarMonth

 /**
  * 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;
 }
开发者ID:noikiy,项目名称:owaspbwa,代码行数:42,代码来源:Calc.php

示例4: define

 */
define('DATE_CALC_BEGIN_WEEKDAY', 1);
require_once "Date/Calc.php";
/**
 * Test dates from 1970 to 2029
 * Data from: http://www.merlyn.demon.co.uk/wknotest.txt
 * Others usefull datas available from:
 * http://www.merlyn.demon.co.uk/#dat
 */
$datapath = dirname(__FILE__);
$failed_test_data = false;
$dates = file($datapath . '/weeksinmonth_4_monday.txt');
$cnt = sizeof($dates);
$valids = array();
for ($i = 0; $i < $cnt; $i++) {
    $parts = explode('/', $dates[$i]);
    $valids[$parts[0]] = array($parts[1] => (int) str_replace("\n", '', $parts[2]));
}
unset($dates);
foreach ($valids as $year => $months) {
    foreach ($months as $month => $valid_weeks) {
        $calc_weeks = Date_Calc::weeksInMonth($month, $year);
        if ($calc_weeks != $valid_weeks) {
            $failed_test_data = true;
            echo "Bug #727, pass 1: {$year}/{$month} failed. Expect:{$valid_weeks} Got:{$calc_weeks}\n";
        }
    }
}
if (!$failed_test_data) {
    echo "Bug #727, pass 1: OK\n";
}
开发者ID:GeekyNinja,项目名称:LifesavingCAD,代码行数:31,代码来源:bug727_1.php

示例5: html

 public function html()
 {
     global $prefs;
     $html = '<table id="kronolith-view-year" class="kronolith-minical"><tr>';
     for ($month = 1; $month <= 12; ++$month) {
         $html .= '<td>';
         // Heading for each month.
         $date = new Horde_Date(sprintf('%04d%02d01010101', $this->year, $month));
         $html .= '<table><thead><tr class="kronolith-minical-nav"><th colspan="7">' . Horde::url('month.php')->add('date', $date->dateString())->link() . $date->strftime('%B') . '</a></th></tr><tr><th class="kronolith-minical-empty">&nbsp;</th>';
         if (!$prefs->getValue('week_start_monday')) {
             $html .= '<th>' . _("Su") . '</th>';
         }
         $html .= '<th>' . _("Mo") . '</th>' . '<th>' . _("Tu") . '</th>' . '<th>' . _("We") . '</th>' . '<th>' . _("Th") . '</th>' . '<th>' . _("Fr") . '</th>' . '<th>' . _("Sa") . '</th>';
         if ($prefs->getValue('week_start_monday')) {
             $html .= '<th>' . _("Su") . '</th>';
         }
         $html .= '</tr></thead><tbody><tr><td class="kronolith-minical-week">';
         $startday = new Horde_Date(array('mday' => 1, 'month' => $month, 'year' => $this->year));
         $startday = $startday->dayOfWeek();
         $daysInView = Date_Calc::weeksInMonth($month, $this->year) * 7;
         if (!$prefs->getValue('week_start_monday')) {
             $startOfView = 1 - $startday;
             // We may need to adjust the number of days in the
             // view if we're starting weeks on Sunday.
             if ($startday == Horde_Date::DATE_SUNDAY) {
                 $daysInView -= 7;
             }
             $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $this->year), 'month' => $month, 'year' => $this->year));
             $endday = $endday->dayOfWeek();
             if ($endday == Horde_Date::DATE_SUNDAY) {
                 $daysInView += 7;
             }
         } else {
             if ($startday == Horde_Date::DATE_SUNDAY) {
                 $startOfView = -5;
             } else {
                 $startOfView = 2 - $startday;
             }
         }
         $currentCalendars = array(true);
         foreach ($currentCalendars as $id => $cal) {
             $cell = 0;
             for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) {
                 $date = new Kronolith_Day($month, $day, $this->year);
                 $date->hour = $prefs->getValue('twentyFour') ? 12 : 6;
                 $week = $date->weekOfYear();
                 if ($cell % 7 == 0) {
                     if ($cell != 0) {
                         $html .= "</tr>\n<tr><td class=\"kronolith-minical-week\">";
                     }
                     $html .= (int) $date->weekOfYear() . '</td>';
                 }
                 if ($date->month != $month) {
                     $style = 'kronolith-other-month';
                 } else {
                     $style = '';
                 }
                 /* Set up the link to the day view. */
                 $url = Horde::url('day.php', true)->add('date', $date->dateString());
                 if ($date->month == $month && !empty($this->_events[$date->dateString()])) {
                     /* There are events; create a cell with tooltip to list
                      * them. */
                     $day_events = '';
                     foreach ($this->_events[$date->dateString()] as $event) {
                         if ($event->status == Kronolith::STATUS_CONFIRMED) {
                             /* Set the background color to distinguish the
                              * day */
                             $style = 'year-event';
                         }
                         if ($event->isAllDay()) {
                             $day_events .= _("All day");
                         } else {
                             $day_events .= $event->start->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p') . '-' . $event->end->strftime($prefs->getValue('twentyFour') ? '%R' : '%I:%M%p');
                         }
                         $day_events .= ':' . ($event->getLocation() ? ' (' . $event->getLocation() . ')' : '') . ' ' . $event->getTitle() . "\n";
                     }
                     /* Bold the cell if there are events. */
                     $cellday = '<strong>' . Horde::linkTooltip($url, _("View Day"), '', '', '', $day_events) . $date->mday . '</a></strong>';
                 } else {
                     /* No events, plain link to the day. */
                     $cellday = Horde::linkTooltip($url, _("View Day")) . $date->mday . '</a>';
                 }
                 if ($date->isToday() && $date->month == $month) {
                     $style .= ' kronolith-today';
                 }
                 $html .= '<td align="center" class="' . $style . '" height="10" width="5%" valign="top">' . $cellday . '</td>';
                 ++$cell;
             }
         }
         $html .= '</tr></tbody></table></td>';
         if ($month % 3 == 0 && $month != 12) {
             $html .= '</tr><tr>';
         }
     }
     echo $html . '</tr></table>';
 }
开发者ID:DSNS-LAB,项目名称:Dmail,代码行数:96,代码来源:Year.php

示例6: compare

compare(4, Date_Calc::quarterOfYear(22, 11, 2000), 'quarterOfYear');
compare(3, Date_Calc::dayOfWeek('22', '11', '2000'), 'dayOfWeek str');
compare(47, Date_Calc::weekOfYear('22', '11', '2000'), 'weekOfYear str');
compare(4, Date_Calc::quarterOfYear('22', '11', '2000'), 'quarterOfYear str');
compare(28, Date_Calc::daysInMonth(2, 1900), 'daysInMonth 1');
compare(29, Date_Calc::daysInMonth(2, 1996), 'daysInMonth 2');
compare(29, Date_Calc::daysInMonth(2, 2000), 'daysInMonth 3');
compare(28, Date_Calc::daysInMonth(2, 2001), 'daysInMonth 4');
compare(30, Date_Calc::daysInMonth(11, 2000), 'daysInMonth 5');
compare(28, Date_Calc::daysInMonth('02', 1900), 'daysInMonth 1 str');
compare(29, Date_Calc::daysInMonth('02', 1996), 'daysInMonth 2 str');
compare(29, Date_Calc::daysInMonth('02', 2000), 'daysInMonth 3 str');
compare(28, Date_Calc::daysInMonth('02', 2001), 'daysInMonth 4 str');
compare(30, Date_Calc::daysInMonth('11', '2000'), 'daysInMonth 5 str');
compare(5, Date_Calc::weeksInMonth(11, 2000), 'weeksInMonth');
compare(5, Date_Calc::weeksInMonth('11', '2000'), 'weeksInMonth str');
$exp = array('19000226', '19000227', '19000228', '19000301', '19000302', '19000303', '19000304');
compare($exp, Date_Calc::getCalendarWeek(27, 2, 1900), 'getCalendarWeek 1');
$exp = array('20000228', '20000229', '20000301', '20000302', '20000303', '20000304', '20000305');
compare($exp, Date_Calc::getCalendarWeek(28, 2, 2000), 'getCalendarWeek 2');
$exp = array('20001127', '20001128', '20001129', '20001130', '20001201', '20001202', '20001203');
compare($exp, Date_Calc::getCalendarWeek(27, 11, 2000), 'getCalendarWeek 3');
compare($exp, Date_Calc::getCalendarWeek('27', '11', '2000'), 'getCalendarWeek 3 str');
$exp = array(array('20001030', '20001031', '20001101', '20001102', '20001103', '20001104'), array('20001105', '20001106', '20001107', '20001108', '20001109', '20001110', '20001111'), array('20001112', '20001113', '20001114', '20001115', '20001116', '20001117', '20001118'), array('20001119', '20001121', '20001122', '20001123', '20001124', '20001125', '20001126'), array('20001127', '20001128', '20001129', '20001130', '20001201', '20001202', '20001203'));
compare($exp, Date_Calc::getCalendarMonth(11, 2000), 'getCalendarMonth');
compare($exp, Date_Calc::getCalendarMonth('11', '2000'), 'getCalendarMonth str');
// I don't feel like dealing with this right now...
//compare('', Date_Calc::getCalendarYear(2000), 'getCalendarYear');
compare('20001121', Date_Calc::prevDay(22, 11, 2000), 'prevDay');
compare('20001123', Date_Calc::nextDay(22, 11, 2000), 'nextDay');
compare('20001121', Date_Calc::prevDay(22, 11, 2000), 'prevDay str');
开发者ID:MagnusA,项目名称:Date,代码行数:31,代码来源:calc.php

示例7: _content

 /**
  */
 protected function _content()
 {
     global $prefs;
     if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
         $calendars = Kronolith::listCalendars();
         if (!isset($calendars[$this->_params['calendar']])) {
             return _("Calendar not found");
         }
         if (!$calendars[$this->_params['calendar']]->hasPermission(Horde_Perms::READ)) {
             return _("Permission Denied");
         }
     }
     $year = date('Y');
     $month = date('m');
     $startday = new Horde_Date(array('mday' => 1, 'month' => $month, 'year' => $year));
     $startday = $startday->dayOfWeek();
     $daysInView = Date_Calc::weeksInMonth($month, $year) * 7;
     if (!$prefs->getValue('week_start_monday')) {
         $startOfView = 1 - $startday;
         // We may need to adjust the number of days in the view if
         // we're starting weeks on Sunday.
         if ($startday == Horde_Date::DATE_SUNDAY) {
             $daysInView -= 7;
         }
         $endday = new Horde_Date(array('mday' => Horde_Date_Utils::daysInMonth($month, $year), 'month' => $month, 'year' => $year));
         $endday = $endday->dayOfWeek();
         if ($endday == Horde_Date::DATE_SUNDAY) {
             $daysInView += 7;
         }
     } else {
         if ($startday == Horde_Date::DATE_SUNDAY) {
             $startOfView = -5;
         } else {
             $startOfView = 2 - $startday;
         }
     }
     $startDate = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => $startOfView));
     $endDate = new Horde_Date(array('year' => $year, 'month' => $month, 'mday' => $startOfView + $daysInView, 'hour' => 23, 'min' => 59, 'sec' => 59));
     /* Table start. and current month indicator. */
     $html = '<table cellspacing="1" class="monthgrid" width="100%"><tr>';
     /* Set up the weekdays. */
     $weekdays = array(_("Mo"), _("Tu"), _("We"), _("Th"), _("Fr"), _("Sa"));
     if (!$prefs->getValue('week_start_monday')) {
         array_unshift($weekdays, _("Su"));
     } else {
         $weekdays[] = _("Su");
     }
     foreach ($weekdays as $weekday) {
         $html .= '<th class="item">' . $weekday . '</th>';
     }
     try {
         if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
             list($type, $calendar) = explode('_', $this->_params['calendar'], 2);
             $driver = Kronolith::getDriver($type, $calendar);
             $all_events = $driver->listEvents($startDate, $endDate, array('show_recurrence' => true));
         } else {
             $all_events = Kronolith::listEvents($startDate, $endDate, $GLOBALS['calendar_manager']->get(Kronolith::DISPLAY_CALENDARS));
         }
     } catch (Exception $e) {
         return '<em>' . $e->getMessage() . '</em>';
     }
     $weekday = 0;
     $week = -1;
     for ($day = $startOfView; $day < $startOfView + $daysInView; ++$day) {
         if ($weekday == 7) {
             $weekday = 0;
         }
         if ($weekday == 0) {
             ++$week;
             $html .= '</tr><tr>';
         }
         $date_ob = new Kronolith_Day($month, $day, $year);
         if ($date_ob->isToday()) {
             $td_class = 'kronolith-today';
         } elseif ($date_ob->month != $month) {
             $td_class = 'kronolith-othermonth';
         } elseif ($date_ob->dayOfWeek() == 0 || $date_ob->dayOfWeek() == 6) {
             $td_class = 'kronolith-weekend';
         } else {
             $td_class = '';
         }
         $html .= '<td align="center" class="' . $td_class . '">';
         /* Set up the link to the day view. */
         $url = Horde::url('day.php', true)->add('date', $date_ob->dateString());
         if (isset($this->_params['calendar']) && $this->_params['calendar'] != '__all') {
             $url->add('display_cal', $this->_params['calendar']);
         }
         $date_stamp = $date_ob->dateString();
         if (empty($all_events[$date_stamp])) {
             /* No events, plain link to the day. */
             $cell = Horde::linkTooltip($url, _("View Day")) . $date_ob->mday . '</a>';
         } else {
             /* There are events; create a cell with tooltip to
              * list them. */
             $day_events = '';
             foreach ($all_events[$date_stamp] as $event) {
                 if ($event->isAllDay()) {
                     $day_events .= _("All day");
//.........这里部分代码省略.........
开发者ID:DSNS-LAB,项目名称:Dmail,代码行数:101,代码来源:Month.php


注:本文中的Date_Calc::weeksInMonth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。