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


PHP DateUtil::getDaysInMonth方法代码示例

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


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

示例1: arrayForMonthView

 /**
  * Creates an array for an month.
  *
  * @param array $args Date.
  *
  * @return array 2 dimensional array.
  * e.g.: array[0][YYYY-MM-DD] = NULL;
  *
  */
 function arrayForMonthView($args)
 {
     if (!isset($args['month']) || !isset($args['year'])) {
         return LogUtil::registerError(_MODARGSERROR);
     }
     if (!ModUtil::apiFunc('TimeIt', 'user', 'checkDate', $args)) {
         return LogUtil::registerError(_MODARGSERROR . _TIMEIT_INVALIDDATE);
     }
     $array = array();
     $year = $args['year'];
     $month = $args['month'];
     $firstDayOfWeek = isset($args['firstDayOfWeek']) && (int) $args['firstDayOfWeek'] >= 0 && (int) $args['firstDayOfWeek'] <= 6 ? (int) $args['firstDayOfWeek'] : (int) ModUtil::getVar('TimeIt', 'firstWeekDay');
     // 0 = Sun 1 = Mo ...
     // calc first day of week in the first week of the month
     $timestampFirstDayOfMonth = gmmktime(0, 0, 0, (int) $month, 1, (int) $year);
     $day1 = (gmdate('w', $timestampFirstDayOfMonth) - $firstDayOfWeek) % 7;
     if ($day1 < 0) {
         $day1 += 7;
     }
     $timestamp = strtotime('-' . $day1 . ' days', $timestampFirstDayOfMonth);
     $daysInMonth = DateUtil::getDaysInMonth((int) $month, (int) $year);
     // create array
     $lastDayInMonthFound = false;
     for ($week = 0; $week < 6; $week++) {
         for ($day = 1; $day <= 7; $day++) {
             $dayNum = date('j', $timestamp);
             //$array[$week][DateUtil::getDatetime($timestamp, DATEONLYFORMAT_FIXED)] = NULL;
             $array[$week][gmdate('Y-m-d', $timestamp)] = null;
             if ($dayNum == $daysInMonth && $week > 0) {
                 $lastDayInMonthFound = true;
             }
             $timestamp += 86400;
         }
         if ($lastDayInMonthFound) {
             break;
         }
     }
     return $array;
 }
开发者ID:planetenkiller,项目名称:TimeIt,代码行数:48,代码来源:User.php

示例2: view

 /**
  * Displays all available events.
  *
  * @return string HTML Code
  */
 public function view()
 {
     // check object type
     $objectType = FormUtil::getPassedValue('ot', 'event', 'GET');
     $this->throwNotFoundUnless(in_array($objectType, TimeIt_Util::getObjectTypes('view')), $this->__f('Unkown object type %s.', DataUtil::formatForDisplay($objectType)));
     // load filter
     $filter = TimeIt_Filter_Container::getFilterFormGETPOST($objectType);
     $this->view->assign('modvars', ModUtil::getVar('TimeIt'));
     // vars
     $tpl = null;
     $theme = null;
     $domain = $this->serviceManager->getService('timeit.manager.' . $objectType);
     // load the data
     if ($objectType == 'event') {
         $calendarId = (int) FormUtil::getPassedValue('cid', ModUtil::getVar('TimeIt', 'defaultCalendar'), 'GETPOST');
         $calendar = $this->serviceManager->getService('timeit.manager.calendar')->getObject($calendarId);
         $this->throwNotFoundIf(empty($calendar), $this->__f('Calendar [%s] not found.', $calendarId));
         $year = (int) FormUtil::getPassedValue('year', date("Y"), 'GETPOST');
         $month = (int) FormUtil::getPassedValue('month', date("n"), 'GETPOST');
         $day = (int) FormUtil::getPassedValue('day', date("j"), 'GETPOST');
         $tpl = FormUtil::getPassedValue('viewType', FormUtil::getPassedValue('viewtype', $calendar['config']['defaultView'], 'GETPOST'), 'GETPOST');
         $firstDayOfWeek = (int) FormUtil::getPassedValue('firstDayOfWeek', -1, 'GETPOST');
         $theme = FormUtil::getPassedValue('template', $calendar['config']['defaultTemplate'], 'GETPOST');
         // backward compatibility
         if ($theme == 'default') {
             $theme = 'table';
         }
         // check for a valid $tpl
         if ($tpl != 'year' && $tpl != 'month' && $tpl != 'week' && $tpl != 'day') {
             $tpl = $calendar['config']['defaultView'];
         }
         $tpl = 'month';
         $theme = 'table';
         $this->view->assign('template', $theme);
         $this->view->assign('viewed_day', $day);
         $this->view->assign('viewed_month', $month);
         $this->view->assign('viewed_year', $year);
         $this->view->assign('viewType', $tpl);
         $this->view->assign('calendar', $calendar);
         $this->view->assign('viewed_date', DateUtil::getDatetime(mktime(0, 0, 0, $month, $day, $year), DATEONLYFORMAT_FIXED));
         $this->view->assign('date_today', DateUtil::getDatetime(null, DATEONLYFORMAT_FIXED));
         $this->view->assign('month_startDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, 1, $year), DATEONLYFORMAT_FIXED));
         $this->view->assign('month_endDate', DateUtil::getDatetime(mktime(0, 0, 0, $month, DateUtil::getDaysInMonth($month, $year), $year), DATEONLYFORMAT_FIXED));
         $this->view->assign('filter_obj_url', $filter->toURL());
         $this->view->assign('firstDayOfWeek', $firstDayOfWeek);
         $this->view->assign('selectedCats', array());
         $categories = CategoryRegistryUtil::getRegisteredModuleCategories('TimeIt', 'TimeIt_events');
         foreach ($categories as $property => $cid) {
             $cat = CategoryUtil::getCategoryByID($cid);
             if (isset($cat['__ATTRIBUTES__']['calendarid']) && !empty($cat['__ATTRIBUTES__']['calendarid'])) {
                 if ($cat['__ATTRIBUTES__']['calendarid'] != $calendar['id']) {
                     unset($categories[$property]);
                 }
             }
         }
         $this->view->assign('categories', $categories);
         // load event data
         switch ($tpl) {
             case 'year':
                 $objectData = $domain->getYearEvents($year, $calendar['id'], $firstDayOfWeek);
                 break;
             case 'month':
                 $objectData = $domain->getMonthEvents($year, $month, $day, $calendar['id'], $firstDayOfWeek, $filter);
                 break;
             case 'week':
                 $objectData = $domain->getWeekEvents($year, $month, $day, $calendar['id'], $filter);
                 break;
             case 'day':
                 $objectData = $domain->getDayEvents($year, $month, $day, $calendar['id'], $filter);
                 break;
         }
     }
     // assign the data
     $this->view->assign('objectArray', $objectData);
     // render the html
     return $this->_renderTemplate($this->view, $objectType, 'user', 'view', $theme, $tpl, 'table');
 }
开发者ID:planetenkiller,项目名称:TimeIt,代码行数:82,代码来源:User.php


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