/** * Calculates the date of the Nth weekday of the month, * such as the second Saturday of January 2000. * * @param string occurance: 1=first, 2=second, 3=third, etc. * @param string dayOfWeek: 0=Sunday, 1=Monday, etc. * @param string year in format CCYY * @param string month in format MM * @param string format for returned date * * @access public * * @return string date in given format */ function NWeekdayOfMonth($occurance, $dayOfWeek, $month, $year, $format = "%Y%m%d") { $year = sprintf("%04d", $year); $month = sprintf("%02d", $month); $DOW1day = sprintf("%02d", ($occurance - 1) * 7 + 1); $DOW1 = Date_Calc::dayOfWeek($DOW1day, $month, $year); $wdate = ($occurance - 1) * 7 + 1 + (7 + $dayOfWeek - $DOW1) % 7; if ($wdate > Date_Calc::daysInMonth($month, $year)) { return -1; } else { return Date_Calc::dateFormat($wdate, $month, $year, $format); } }
/** * Gets number of days in the month for this date * * Gets number of days in the month for this date * * @access public * @return int number of days in this month */ function getDaysInMonth() { return Date_Calc::daysInMonth($this->month, $this->year); }
/** * Calculates the date of the Nth weekday of the month, * such as the second Saturday of January 2000 * * @param int $week the number of the week to get * (1 = first, etc. Also can be 'last'.) * @param int $dow the day of the week (0 = Sunday) * @param int $month the month * @param int $year the year. Use the complete year instead of the * abbreviated version. E.g. use 2005, not 05. * @param string $format the string indicating how to format the output * * @return string the date in the desired format * @access public * @static */ function nWeekdayOfMonth($week, $dow, $month, $year, $format = DATE_CALC_FORMAT) { if (is_numeric($week)) { $DOW1day = ($week - 1) * 7 + 1; $DOW1 = Date_Calc::dayOfWeek($DOW1day, $month, $year); $wdate = ($week - 1) * 7 + 1 + (7 + $dow - $DOW1) % 7; if ($wdate > Date_Calc::daysInMonth($month, $year)) { return -1; } else { return Date_Calc::dateFormat($wdate, $month, $year, $format); } } elseif ($week == 'last' && $dow < 7) { $lastday = Date_Calc::daysInMonth($month, $year); $lastdow = Date_Calc::dayOfWeek($lastday, $month, $year); $diff = $dow - $lastdow; if ($diff > 0) { return Date_Calc::dateFormat($lastday - (7 - $diff), $month, $year, $format); } else { return Date_Calc::dateFormat($lastday + $diff, $month, $year, $format); } } else { return -1; } }
/** * Returns the number of days in a month, given year and month * @param int year (2003) * @param int month (9) * @return int days in month * @access protected */ function getDaysInMonth($y, $m) { return (int) Date_Calc::daysInMonth($m, $y); }
/** * Returns day on which Summer time starts or ends for given year * * The limit (start or end) code can take the following forms: * 5 the fifth of the month * lastSun the last Sunday in the month * lastMon the last Monday in the month * Sun>=8 first Sunday on or after the 8th * Sun<=25 last Sunday on or before the 25th * * @param string $ps_summertimelimitcode code which specifies Summer time * limit day * @param int $pn_month start or end month * @param int $pn_year year for which to calculate Summer * time limit day * * @return int * @access private * @since Method available since Release 1.5.0 */ function getSummerTimeLimitDay($ps_summertimelimitcode, $pn_month, $pn_year) { if (preg_match('/^[0-9]+$/', $ps_summertimelimitcode)) { $hn_day = $ps_summertimelimitcode; } else { if (!isset($ha_daysofweek)) { static $ha_daysofweek = array("Sun" => 0, "Mon" => 1, "Tue" => 2, "Wed" => 3, "Thu" => 4, "Fri" => 5, "Sat" => 6); } if (preg_match('/^last(Sun|Mon|Tue|Wed|Thu|Fri|Sat)$/', $ps_summertimelimitcode, $ha_matches)) { list($hn_nmyear, $hn_nextmonth, $hn_nmday) = explode(" ", Date_Calc::beginOfMonthBySpan(1, $pn_month, $pn_year, "%Y %m %d")); list($hn_year, $hn_month, $hn_day) = explode(" ", Date_Calc::prevDayOfWeek($ha_daysofweek[$ha_matches[1]], $hn_nmday, $hn_nextmonth, $hn_nmyear, "%Y %m %d", false)); // not including // this day if ($hn_month != $pn_month) { // This code happen legitimately if the calendar jumped some days // e.g. in a calendar switch, or the limit day is badly defined: // $hn_day = Date_Calc::getFirstDayOfMonth($pn_month, $pn_year); } } else { if (preg_match('/^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)([><]=)([0-9]+)$/', $ps_summertimelimitcode, $ha_matches)) { if ($ha_matches[2] == "<=") { list($hn_year, $hn_month, $hn_day) = explode(" ", Date_Calc::prevDayOfWeek($ha_daysofweek[$ha_matches[1]], $ha_matches[3], $pn_month, $pn_year, "%Y %m %d", true)); // including // this day if ($hn_month != $pn_month) { $hn_day = Date_Calc::getFirstDayOfMonth($pn_month, $pn_year); } } else { list($hn_year, $hn_month, $hn_day) = explode(" ", Date_Calc::nextDayOfWeek($ha_daysofweek[$ha_matches[1]], $ha_matches[3], $pn_month, $pn_year, "%Y %m %d", true)); // including // this day if ($hn_month != $pn_month) { $hn_day = Date_Calc::daysInMonth($pn_month, $pn_year); } } } } } return $hn_day; }
/** * Calculates the date of the Nth weekday of the month, * such as the second Saturday of January 2000. * * @param string occurance: 1=first, 2=second, 3=third, etc. * @param string dayOfWeek: 0=Sunday, 1=Monday, etc. * @param string year in format CCYY * @param string month in format MM * @param string format for returned date * * @access public * * @return string date in given format */ public function NWeekdayOfMonth($occurance, $dayOfWeek, $month, $year, $format = "%Y-%m-%d") { $year = sprintf("%04d", $year); $month = sprintf("%02d", $month); $DOW1day = sprintf("%02d", ($occurance - 1) * 7 + 1); $DOW1 = Date_Calc::dayOfWeek($DOW1day, $month, $year); $wdate = ($occurance - 1) * 7 + 1 + (7 + $dayOfWeek - $DOW1) % 7; if ($wdate > Date_Calc::daysInMonth($month, $year)) { if ($occurance == 5) { // Getting the last day overshot the month, go back a week $wdate -= 7; return Date_Calc::dateFormat($wdate, $month, $year, $format); } else { // For $occurance === 1 through 4 this is an error return -1; } } else { return Date_Calc::dateFormat($wdate, $month, $year, $format); } }
/** * display block */ function postcalendar_calendarblock_display($blockinfo) { // You supposed to be here? if (!pnSecAuthAction(0, 'PostCalendar:calendarblock:', "{$blockinfo['title']}::", ACCESS_OVERVIEW)) { return false; } // find out what view we're using $template_view = pnVarCleanFromInput('tplview'); if (!isset($template_view)) { $template_view = 'default'; } // find out what template we're using $template_name = _SETTING_TEMPLATE; if (!isset($template_name) || empty($template_name)) { $template_name = 'default'; } // What is today's correct date $Date =& postcalendar_getDate(); // Get variables from content block $vars = unserialize($blockinfo['content']); $showcalendar = $vars['pcbshowcalendar']; $showevents = $vars['pcbeventoverview']; $eventslimit = $vars['pcbeventslimit']; $nextevents = $vars['pcbnextevents']; $pcbshowsslinks = $vars['pcbshowsslinks']; $pcbeventsrange = $vars['pcbeventsrange']; // Let's setup the info to build this sucka! $the_year = substr($Date, 0, 4); $the_month = substr($Date, 4, 2); $the_day = substr($Date, 6, 2); $uid = pnUserGetVar('uid'); $cacheid1 = $cacheid2 = $cacheid3 = ''; $theme = pnUserGetTheme(); pnThemeLoad($theme); global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5; global $textcolor1, $textcolor2; // 20021125 - rraymond :: we have to do this to make it work with envolution $pcModInfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); $pcDir = pnVarPrepForOS($pcModInfo['directory']); require_once "modules/{$pcDir}/pnincludes/Smarty/Config_File.class.php"; unset($pcModInfo); // set up Smarty $tpl =& new pcSmarty(); // setup the Smarty cache id $templates_cached = true; if ($showcalendar) { $cacheid1 = md5($Date . 'M' . $template_view . $template_name . $showcalendar . $showevents . $nextevents . $uid . $theme); if (!$tpl->is_cached($template_name . '/views/calendarblock/month_view.html', $cacheid1)) { $templates_cached = false; } } if ($showevents) { $cacheid2 = md5($Date . 'T' . $template_view . $template_name . $showcalendar . $showevents . $nextevents . $uid . $theme); if (!$tpl->is_cached($template_name . '/views/calendarblock/todays_events.html', $cacheid2)) { $templates_cached = false; } } if ($nextevents) { $cacheid3 = md5($Date . 'U' . $template_view . $template_name . $showcalendar . $showevents . $nextevents . $uid . $theme); if (!$tpl->is_cached($template_name . '/views/calendarblock/upcoming_events.html', $cacheid3)) { $templates_cached = false; } } // start the output container $output = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pageSetup'); // if one of the templates is not cached, we need to run the following if (!$templates_cached) { // set up the next and previous months to move to $prev_month = Date_Calc::beginOfPrevMonth(1, $the_month, $the_year, '%Y%m%d'); $next_month = Date_Calc::beginOfNextMonth(1, $the_month, $the_year, '%Y%m%d'); $last_day = Date_Calc::daysInMonth($the_month, $the_year); $pc_prev = pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview' => $template_view, 'viewtype' => 'month', 'Date' => $prev_month)); $pc_next = pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview' => $template_view, 'viewtype' => 'month', 'Date' => $next_month)); $pc_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', array('Date' => mktime(0, 0, 0, $the_month, $the_day, $the_year))); $month_link_url = pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview' => $template_view, 'viewtype' => 'month', 'Date' => date('Ymd', mktime(0, 0, 0, $the_month, 1, $the_year)))); $month_link_text = $pc_month_name . ' ' . $the_year; //******************************************************************* // Here we get the events for the current month view //******************************************************************* $day_of_week = 1; $pc_month_names = array(_CALJAN, _CALFEB, _CALMAR, _CALAPR, _CALMAY, _CALJUN, _CALJUL, _CALAUG, _CALSEP, _CALOCT, _CALNOV, _CALDEC); $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT, _CALTUESDAYSHORT, _CALWEDNESDAYSHORT, _CALTHURSDAYSHORT, _CALFRIDAYSHORT, _CALSATURDAYSHORT); $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY, _CALTUESDAY, _CALWEDNESDAY, _CALTHURSDAY, _CALFRIDAY, _CALSATURDAY); switch (_SETTING_FIRST_DAY_WEEK) { case _IS_MONDAY: $pc_array_pos = 1; $first_day = date('w', mktime(0, 0, 0, $the_month, 0, $the_year)); $end_dow = date('w', mktime(0, 0, 0, $the_month, $last_day, $the_year)); if ($end_dow != 0) { $the_last_day = $last_day + (7 - $end_dow); } else { $the_last_day = $last_day; } break; case _IS_SATURDAY: $pc_array_pos = 6; $first_day = date('w', mktime(0, 0, 0, $the_month, 2, $the_year)); $end_dow = date('w', mktime(0, 0, 0, $the_month, $last_day, $the_year)); if ($end_dow == 6) { $the_last_day = $last_day + 6; } elseif ($end_dow != 5) { $the_last_day = $last_day + (5 - $end_dow); } else { $the_last_day = $last_day; } break; case _IS_SUNDAY: default: $pc_array_pos = 0; $first_day = date('w', mktime(0, 0, 0, $the_month, 1, $the_year)); $end_dow = date('w', mktime(0, 0, 0, $the_month, $last_day, $the_year)); if ($end_dow != 6) { $the_last_day = $last_day + (6 - $end_dow); } else { $the_last_day = $last_day; } break; } $month_view_start = date('Y-m-d', mktime(0, 0, 0, $the_month, 1, $the_year)); $month_view_end = date('Y-m-t', mktime(0, 0, 0, $the_month, 1, $the_year)); $today_date = postcalendar_today('%Y-%m-%d'); $starting_date = date('m/d/Y', mktime(0, 0, 0, $the_month, 1 - $first_day, $the_year)); $ending_date = date('m/t/Y', mktime(0, 0, 0, $the_month + $pcbeventsrange, 1, $the_year)); $eventsByDate =& pnModAPIFunc(__POSTCALENDAR__, 'user', 'pcGetEvents', array('start' => $starting_date, 'end' => $ending_date)); $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d'); $sdaynames = array(); $numDays = count($pc_short_day_names); for ($i = 0; $i < $numDays; $i++) { if ($pc_array_pos >= $numDays) { $pc_array_pos = 0; } array_push($sdaynames, $pc_short_day_names[$pc_array_pos]); $pc_array_pos++; } $daynames = array(); $numDays = count($pc_long_day_names); for ($i = 0; $i < $numDays; $i++) { if ($pc_array_pos >= $numDays) { $pc_array_pos = 0; } array_push($daynames, $pc_long_day_names[$pc_array_pos]); $pc_array_pos++; } $dates = array(); while ($starting_date <= $ending_date) { array_push($dates, $starting_date); list($m, $d, $y) = explode('/', $starting_date); $starting_date = Date_Calc::nextDay($d, $m, $y, '%m/%d/%Y'); } $categories =& pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories'); if (isset($calendarView)) { $tpl->assign_by_ref('CAL_FORMAT', $calendarView); } $tpl->assign_by_ref('A_MONTH_NAMES', $pc_month_names); $tpl->assign_by_ref('A_LONG_DAY_NAMES', $pc_long_day_names); $tpl->assign_by_ref('A_SHORT_DAY_NAMES', $pc_short_day_names); $tpl->assign_by_ref('S_LONG_DAY_NAMES', $daynames); $tpl->assign_by_ref('S_SHORT_DAY_NAMES', $sdaynames); $tpl->assign_by_ref('A_EVENTS', $eventsByDate); $tpl->assign_by_ref('A_CATEGORY', $categories); $tpl->assign_by_ref('PREV_MONTH_URL', $pc_prev); $tpl->assign_by_ref('NEXT_MONTH_URL', $pc_next); $tpl->assign_by_ref('MONTH_START_DATE', $month_view_start); $tpl->assign_by_ref('MONTH_END_DATE', $month_view_end); $tpl->assign_by_ref('TODAY_DATE', $today_date); $tpl->assign_by_ref('DATE', $Date); $tpl->assign_by_ref('DISPLAY_LIMIT', $eventslimit); $tpl->assign('TODAYS_EVENTS_TITLE', _PC_TODAYS_EVENTS); $tpl->assign('UPCOMING_EVENTS_TITLE', _PC_UPCOMING_EVENTS); $tpl->assign('NO_EVENTS', _PC_BLOCK_NO_EVENTS); } if ($showcalendar) { // we need to create a unique ID for caching purposes $output .= $tpl->fetch($template_name . '/views/calendarblock/month_view.html', $cacheid1); } if ($showevents) { if ($showcalendar) { $tpl->assign('SHOW_TITLE', 1); } else { $tpl->assign('SHOW_TITLE', 0); } // we need to create a unique ID for caching purposes $output .= $tpl->fetch($template_name . '/views/calendarblock/todays_events.html', $cacheid2); } if ($nextevents) { if ($showcalendar || $showevents) { $tpl->assign('SHOW_TITLE', 1); } else { $tpl->assign('SHOW_TITLE', 0); } // we need to create a unique ID for caching purposes $output .= $tpl->fetch($template_name . '/views/calendarblock/upcoming_events.html', $cacheid3); } if ($pcbshowsslinks) { $output .= '<br /><br />'; $submit_event_url = pnModURL(__POSTCALENDAR__, 'user', 'submit'); $search_event_url = pnModURL(__POSTCALENDAR__, 'user', 'search'); $output .= '<center>'; if (PC_ACCESS_ADD) { $output .= '[ <a href="' . $submit_event_url . '">' . _PC_SUBMIT_EVENT . '</a> ] '; } $output .= '[ <a href="' . $search_event_url . '">' . _PC_SEARCH_EVENT . '</a> ]'; $output .= '</center>'; } // Populate block info and pass to theme $blockinfo['content'] = $output; return themesideblock($blockinfo); }
/** * @param $start * @param $startNext * @param string $view * @param int $firstWeekDay * @return array */ function getTableViewCells($start, $startNext, $view = 'month', $firstWeekDay = 0) { // start of the view $viewStart = $start; $nbBackDays = $start['weekDay'] < $firstWeekDay ? 6 : $start['weekDay'] - $firstWeekDay; if ($nbBackDays == 0) { $viewStart['daysInMonth'] = Date_Calc::daysInMonth($viewStart['month'], $viewStart['year']); } elseif ($start['day'] - $nbBackDays < 0) { $viewStart['month'] = $start['month'] == 1 ? 12 : $start['month'] - 1; $viewStart['year'] = $start['month'] == 1 ? $start['year'] - 1 : $start['year']; $viewStart['daysInMonth'] = Date_Calc::daysInMonth($viewStart['month'], $viewStart['year']); $viewStart['day'] = $viewStart['daysInMonth'] - $nbBackDays + 1; $viewStart['date'] = TikiLib::make_time(0, 0, 0, $viewStart['month'], $viewStart['day'], $viewStart['year']); } else { $viewStart['daysInMonth'] = Date_Calc::daysInMonth($viewStart['month'], $viewStart['year']); $viewStart['day'] = $viewStart['day'] - $nbBackDays; $viewStart['date'] = TikiLib::make_time(0, 0, 0, $viewStart['month'], $viewStart['day'], $viewStart['year']); } // echo '<br/>VIEWSTART'; print_r($viewStart); // end of the period $cell = array(); for ($ilign = 0, $icol = 0, $loop = $viewStart, $weekDay = $viewStart['weekDay'];;) { if ($loop['date'] >= $startNext['date'] && $icol == 0) { break; } $cell[$ilign][$icol] = $loop; $cell[$ilign][$icol]['focus'] = $loop['date'] < $start['date'] || $loop['date'] >= $startNext['date'] ? false : true; $cell[$ilign][$icol]['weekDay'] = $weekDay; $weekDay = ($weekDay + 1) % 7; if ($icol >= 6) { ++$ilign; $icol = 0; } else { ++$icol; } if ($loop['day'] >= $loop['daysInMonth']) { $loop['day'] = 1; if ($loop['month'] == 12) { $loop['month'] = 1; $loop['year'] += 1; } else { $loop['month'] += 1; } $loop['daysInMonth'] = Date_Calc::daysInMonth($loop['month'], $loop['year']); } else { $loop['day'] = $loop['day'] + 1; } $loop['date'] = TikiLib::make_time(0, 0, 0, $loop['month'], $loop['day'], $loop['year']); } //echo '<pre>CELL'; print_r($cell); echo '</pre>'; return $cell; }
/** * postcalendar_userapi_buildView * * Builds the calendar display * @param string $Date mm/dd/yyyy format (we should use timestamps) * @return string generated html output * @access public */ function postcalendar_userapi_buildView($args) { $print = pnVarCleanFromInput('print'); $show_days = pnVarCleanFromInput('show_days'); extract($args); unset($args); $schedule_start = $GLOBALS[schedule_start]; $schedule_end = $GLOBALS[schedule_end]; // $times is an array of associative arrays, where each sub-array // has keys 'hour', 'minute' and 'mer'. // $times = array(); // For each hour in the schedule... // for ($blocknum = $schedule_start; $blocknum <= $schedule_end; $blocknum++) { $mer = $blocknum >= 12 ? 'pm' : 'am'; // $minute is an array of time slot strings within this hour. $minute = array('00'); for ($minutes = $GLOBALS['calendar_interval']; $minutes <= 60; $minutes += $GLOBALS['calendar_interval']) { if ($minutes <= '9') { $under_ten = "0" . $minutes; array_push($minute, "{$under_ten}"); } else { if ($minutes >= '60') { break; } else { array_push($minute, "{$minutes}"); } } } foreach ($minute as $m) { array_push($times, array("hour" => $blocknum, "minute" => $m, "mer" => $mer)); } } //================================================================= // get the module's information //================================================================= $modinfo = pnModGetInfo(pnModGetIDFromName(__POSTCALENDAR__)); $pcDir = $modinfo['directory']; unset($modinfo); //================================================================= // grab the for post variable //================================================================= // $pc_username = pnVarCleanFromInput('pc_username'); $pc_username = $_SESSION['pc_username']; // from Michael Brinson 2006-09-19 $category = pnVarCleanFromInput('pc_category'); $topic = pnVarCleanFromInput('pc_topic'); //================================================================= // set the correct date //================================================================= $Date = postcalendar_getDate(); //================================================================= // get the current view //================================================================= if (!isset($viewtype)) { $viewtype = 'month'; } //================================================================= // Find out what Template we're using //================================================================= $template_name = _SETTING_TEMPLATE; if (!isset($template_name)) { $template_name = 'default'; } //================================================================= // Find out what Template View to use //================================================================= $template_view = pnVarCleanFromInput('tplview'); if (!isset($template_view)) { $template_view = 'default'; } //================================================================= // See if the template view exists //================================================================= if (!file_exists("modules/{$pcDir}/pntemplates/{$template_name}/views/{$viewtype}/{$template_view}.html")) { $template_view_load = 'default'; } else { $template_view_load = pnVarPrepForOS($template_view); } //================================================================= // Grab the current theme information //================================================================= pnThemeLoad(pnUserGetTheme()); global $bgcolor1, $bgcolor2, $bgcolor3, $bgcolor4, $bgcolor5, $bgcolor6, $textcolor1, $textcolor2; //================================================================= // Insert necessary JavaScript into the page //================================================================= $output = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pageSetup'); //================================================================= // Setup Smarty Template Engine //================================================================= $tpl = new pcSmarty(); //if(!$tpl->is_cached("$template_name/views/$viewtype/$template_view_load.html",$cacheid)) { //diable caching completely if (true) { //================================================================= // Let's just finish setting things up //================================================================= $the_year = substr($Date, 0, 4); $the_month = substr($Date, 4, 2); $the_day = substr($Date, 6, 2); $last_day = Date_Calc::daysInMonth($the_month, $the_year); //================================================================= // populate the template object with information for // Month Names, Long Day Names and Short Day Names // as translated in the language files // (may be adding more here soon - based on need) //================================================================= $pc_month_names = array(_CALJAN, _CALFEB, _CALMAR, _CALAPR, _CALMAY, _CALJUN, _CALJUL, _CALAUG, _CALSEP, _CALOCT, _CALNOV, _CALDEC); $pc_short_day_names = array(_CALSUNDAYSHORT, _CALMONDAYSHORT, _CALTUESDAYSHORT, _CALWEDNESDAYSHORT, _CALTHURSDAYSHORT, _CALFRIDAYSHORT, _CALSATURDAYSHORT); $pc_long_day_names = array(_CALSUNDAY, _CALMONDAY, _CALTUESDAY, _CALWEDNESDAY, _CALTHURSDAY, _CALFRIDAY, _CALSATURDAY); //================================================================= // here we need to set up some information for later // variable creation. This helps us establish the correct // date ranges for each view. There may be a better way // to handle all this, but my brain hurts, so your comments // are very appreciated and welcomed. //================================================================= switch (_SETTING_FIRST_DAY_WEEK) { case _IS_MONDAY: $pc_array_pos = 1; $first_day = date('w', mktime(0, 0, 0, $the_month, 0, $the_year)); $week_day = date('w', mktime(0, 0, 0, $the_month, $the_day - 1, $the_year)); $end_dow = date('w', mktime(0, 0, 0, $the_month, $last_day, $the_year)); if ($end_dow != 0) { $the_last_day = $last_day + (7 - $end_dow); } else { $the_last_day = $last_day; } break; case _IS_SATURDAY: $pc_array_pos = 6; $first_day = date('w', mktime(0, 0, 0, $the_month, 2, $the_year)); $week_day = date('w', mktime(0, 0, 0, $the_month, $the_day + 1, $the_year)); $end_dow = date('w', mktime(0, 0, 0, $the_month, $last_day, $the_year)); if ($end_dow == 6) { $the_last_day = $last_day + 6; } elseif ($end_dow != 5) { $the_last_day = $last_day + (5 - $end_dow); } else { $the_last_day = $last_day; } break; case _IS_SUNDAY: default: $pc_array_pos = 0; $first_day = date('w', mktime(0, 0, 0, $the_month, 1, $the_year)); $week_day = date('w', mktime(0, 0, 0, $the_month, $the_day, $the_year)); $end_dow = date('w', mktime(0, 0, 0, $the_month, $last_day, $the_year)); if ($end_dow != 6) { $the_last_day = $last_day + (6 - $end_dow); } else { $the_last_day = $last_day; } break; } // passing the times array to the tpl the times array is for the days schedule $tpl->assign_by_ref("times", $times); // load the table width to the template // $tpl->assign("day_td_width",$GLOBALS['day_view_td_width']); //================================================================= // Week View is a bit of a pain in the ass, so we need to // do some extra setup for that view. This section will // find the correct starting and ending dates for a given // seven day period, based on the day of the week the // calendar is setup to run under (Sunday, Saturday, Monday) //================================================================= $first_day_of_week = sprintf('%02d', $the_day - $week_day); $week_first_day = date('m/d/Y', mktime(0, 0, 0, $the_month, $first_day_of_week, $the_year)); list($week_first_day_month, $week_first_day_date, $week_first_day_year) = explode('/', $week_first_day); $week_first_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', array('Date' => mktime(0, 0, 0, $week_first_day_month, $week_first_day_date, $week_first_day_year))); $week_last_day = date('m/d/Y', mktime(0, 0, 0, $the_month, $first_day_of_week + 6, $the_year)); list($week_last_day_month, $week_last_day_date, $week_last_day_year) = explode('/', $week_last_day); $week_last_day_month_name = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getmonthname', array('Date' => mktime(0, 0, 0, $week_last_day_month, $week_last_day_date, $week_last_day_year))); $week_view_start = date('Y-m-d', mktime(0, 0, 0, $the_month, $first_day_of_week, $the_year)); $week_view_end = date('Y-m-d', mktime(0, 0, 0, $the_month, $first_day_of_week + 6, $the_year)); //================================================================= // Setup some information so we know the actual month's dates // also get today's date for later use and highlighting //================================================================= $month_view_start = date('Y-m-d', mktime(0, 0, 0, $the_month, 1, $the_year)); $month_view_end = date('Y-m-t', mktime(0, 0, 0, $the_month, 1, $the_year)); $today_date = postcalendar_today('%Y-%m-%d'); //================================================================= // Setup the starting and ending date ranges for pcGetEvents() //================================================================= switch ($viewtype) { case 'day': $starting_date = date('m/d/Y', mktime(0, 0, 0, $the_month, $the_day, $the_year)); $ending_date = date('m/d/Y', mktime(0, 0, 0, $the_month, $the_day, $the_year)); break; case 'week': $starting_date = "{$week_first_day_month}/{$week_first_day_date}/{$week_first_day_year}"; $ending_date = "{$week_last_day_month}/{$week_last_day_date}/{$week_last_day_year}"; $calendarView = Date_Calc::getCalendarWeek($week_first_day_date, $week_first_day_month, $week_first_day_year, '%Y-%m-%d'); break; case 'month': $starting_date = date('m/d/Y', mktime(0, 0, 0, $the_month, 1 - $first_day, $the_year)); $ending_date = date('m/d/Y', mktime(0, 0, 0, $the_month, $the_last_day, $the_year)); $calendarView = Date_Calc::getCalendarMonth($the_month, $the_year, '%Y-%m-%d'); break; case 'year': $starting_date = date('m/d/Y', mktime(0, 0, 0, 1, 1, $the_year)); $ending_date = date('m/d/Y', mktime(0, 0, 0, 1, 1, $the_year + 1)); $calendarView = Date_Calc::getCalendarYear($the_year, '%Y-%m-%d'); break; } //================================================================= // Identify the Providers whose schedules we should load //================================================================= //================================== //FACILITY FILTERING (CHEMED) if ($_SESSION['pc_facility']) { $provinfo = getProviderInfo('%', true, $_SESSION['pc_facility']); } else { $provinfo = getProviderInfo(); } //EOS FACILITY FILTERING (CHEMED) //================================== $single = array(); $provIDs = array(); // array of numeric provider IDs // filter the display on the requested username, the provinfo array is // used to build columns in the week view. foreach ($provinfo as $provider) { if (is_array($pc_username)) { foreach ($pc_username as $uname) { if (!empty($pc_username) && $provider['username'] == $uname) { array_push($single, $provider); array_push($provIDs, $provider['id']); } } } else { if (!empty($pc_username) && $provider['username'] == $pc_username) { array_push($single, $provider); array_push($provIDs, $provider['id']); } } } if ($single != null) { $provinfo = $single; } //================================================================= // Load the events //================================================================= if ($viewtype != 'year') { $eventsByDate =& postcalendar_userapi_pcGetEvents(array('start' => $starting_date, 'end' => $ending_date, 'viewtype' => $viewtype, 'provider_id' => $provIDs)); } else { $eventsByDate = array(); } //================================================================= // Create an array with the day names in the correct order //================================================================= $daynames = array(); $numDays = count($pc_long_day_names); for ($i = 0; $i < $numDays; $i++) { if ($pc_array_pos >= $numDays) { $pc_array_pos = 0; } array_push($daynames, $pc_long_day_names[$pc_array_pos]); $pc_array_pos++; } unset($numDays); $sdaynames = array(); $numDays = count($pc_short_day_names); for ($i = 0; $i < $numDays; $i++) { if ($pc_array_pos >= $numDays) { $pc_array_pos = 0; } array_push($sdaynames, $pc_short_day_names[$pc_array_pos]); $pc_array_pos++; } unset($numDays); //================================================================= // Prepare some values for the template //================================================================= $prev_month = Date_Calc::beginOfPrevMonth(1, $the_month, $the_year, '%Y%m%d'); $next_month = Date_Calc::beginOfNextMonth(1, $the_month, $the_year, '%Y%m%d'); $pc_prev = pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview' => $template_view, 'viewtype' => 'month', 'Date' => $prev_month, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); $pc_next = pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview' => $template_view, 'viewtype' => 'month', 'Date' => $next_month, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); $prev_day = Date_Calc::prevDay($the_day, $the_month, $the_year, '%Y%m%d'); $next_day = Date_Calc::nextDay($the_day, $the_month, $the_year, '%Y%m%d'); $pc_prev_day = pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview' => $template_view, 'viewtype' => 'day', 'Date' => $prev_day, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); $pc_next_day = pnModURL(__POSTCALENDAR__, 'user', 'view', array('tplview' => $template_view, 'viewtype' => 'day', 'Date' => $next_day, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); $prev_week = date('Ymd', mktime(0, 0, 0, $week_first_day_month, $week_first_day_date - 7, $week_first_day_year)); $next_week = date('Ymd', mktime(0, 0, 0, $week_last_day_month, $week_last_day_date + 1, $week_last_day_year)); $pc_prev_week = pnModURL(__POSTCALENDAR__, 'user', 'view', array('viewtype' => 'week', 'Date' => $prev_week, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); $pc_next_week = pnModURL(__POSTCALENDAR__, 'user', 'view', array('viewtype' => 'week', 'Date' => $next_week, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); $prev_year = date('Ymd', mktime(0, 0, 0, 1, 1, $the_year - 1)); $next_year = date('Ymd', mktime(0, 0, 0, 1, 1, $the_year + 1)); $pc_prev_year = pnModURL(__POSTCALENDAR__, 'user', 'view', array('viewtype' => 'year', 'Date' => $prev_year, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); $pc_next_year = pnModURL(__POSTCALENDAR__, 'user', 'view', array('viewtype' => 'year', 'Date' => $next_year, 'pc_username' => $pc_username, 'pc_category' => $category, 'pc_topic' => $topic)); //================================================================= // Populate the template //================================================================= $all_categories = pnModAPIFunc(__POSTCALENDAR__, 'user', 'getCategories'); if (isset($calendarView)) { $tpl->assign_by_ref('CAL_FORMAT', $calendarView); } if ($viewtype == "week") { $last_blocks = array(); foreach ($eventsByDate as $cdate => $day) { $tblock = array_reverse($day['blocks']); $last_blocks[$cdate] = count($tblock) - 1; for ($i = 0; $i < count($tblock); $i++) { if (!empty($tblock[$i])) { $last_blocks[$cdate] = count($tblock) - $i; break; } } } $tpl->assign("last_blocks", $last_blocks); } $tpl->assign('STYLE', $GLOBALS['style']); $tpl->assign('show_days', $show_days); //$provinfo[count($provinfo) +1] = array("id" => "","lname" => "Other"); $tpl->assign_by_ref('providers', $provinfo); if (pnVarCleanFromInput("show_days") != 1) { $tpl->assign('showdaysurl', "index.php?" . $_SERVER['QUERY_STRING'] . "&show_days=1"); } $tpl->assign('interval', $GLOBALS['calendar_interval']); $tpl->assign_by_ref('VIEW_TYPE', $viewtype); $tpl->assign_by_ref('A_MONTH_NAMES', $pc_month_names); $tpl->assign_by_ref('A_LONG_DAY_NAMES', $pc_long_day_names); $tpl->assign_by_ref('A_SHORT_DAY_NAMES', $pc_short_day_names); $tpl->assign_by_ref('S_LONG_DAY_NAMES', $daynames); $tpl->assign_by_ref('S_SHORT_DAY_NAMES', $sdaynames); $tpl->assign_by_ref('A_EVENTS', $eventsByDate); $tpl->assign_by_ref('A_CATEGORY', $all_categories); $tpl->assign_by_ref('PREV_MONTH_URL', $pc_prev); $tpl->assign_by_ref('NEXT_MONTH_URL', $pc_next); $tpl->assign_by_ref('PREV_DAY_URL', $pc_prev_day); $tpl->assign_by_ref('NEXT_DAY_URL', $pc_next_day); $tpl->assign_by_ref('PREV_WEEK_URL', $pc_prev_week); $tpl->assign_by_ref('NEXT_WEEK_URL', $pc_next_week); $tpl->assign_by_ref('PREV_YEAR_URL', $pc_prev_year); $tpl->assign_by_ref('NEXT_YEAR_URL', $pc_next_year); $tpl->assign_by_ref('WEEK_START_DATE', $week_view_start); $tpl->assign_by_ref('WEEK_END_DATE', $week_view_end); $tpl->assign_by_ref('MONTH_START_DATE', $month_view_start); $tpl->assign_by_ref('MONTH_END_DATE', $month_view_end); $tpl->assign_by_ref('TODAY_DATE', $today_date); $tpl->assign_by_ref('DATE', $Date); $tpl->assign('SCHEDULE_BASE_URL', pnModURL(__POSTCALENDAR__, 'user', 'submit')); $tpl->assign_by_ref('intervals', $intervals); } //================================================================= // Parse the template //================================================================= $template = "{$template_name}/views/{$viewtype}/{$template_view_load}.html"; if (!$print) { $output .= "\n\n<!-- START POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n"; $output .= $tpl->fetch($template, $cacheid); // cache id $output .= "\n\n<!-- END POSTCALENDAR OUTPUT [-: HTTP://POSTCALENDAR.TV :-] -->\n\n"; } else { $theme = pnUserGetTheme(); echo "<html><head>"; echo "<LINK REL=\"StyleSheet\" HREF=\"themes/{$theme}/style/styleNN.css\" TYPE=\"text/css\">\n\n\n"; echo "<style type=\"text/css\">\n"; echo "@import url(\"themes/{$theme}/style/style.css\"); "; echo "</style>\n"; echo "</head><body>\n"; echo $output; $tpl->display($template, $cacheid); echo postcalendar_footer(); echo "\n</body></html>"; session_write_close(); exit; } //================================================================= // Return the output //================================================================= return $output; }
if ($wd > 0 and $viewlist != 'list') { $viewstart_d = TikiLib::date_format("%d", $viewstart); $viewstart_m = TikiLib::date_format("%m", $viewstart); $viewstart_y = TikiLib::date_format("%Y", $viewstart); // Start in previous month if $wd is greater than the current day (relative to th current month) if ($viewstart_d <= $wd) { // $tikilib->make_time() used with timezones doesn't support month = 0 if ($viewstart_m == 1) { $viewstart_m = 12; $viewstart_y--; } else { $viewstart_m--; } // $tikilib->make_time() used with timezones doesn't support day = 0 // This supposes that $viewstart's day == 1, as defined above $viewstart_d = Date_Calc::daysInMonth($viewstart_m, $viewstart_y) - ($wd - $viewstart_d); } else { $viewstart_d -= $wd; } $viewstart = $tikilib->make_time(0, 0, 0, $viewstart_m, $viewstart_d, $viewstart_y); } $daystart = $viewstart; // then go to the end of the week for $viewend // $viewend = $viewstart + (7 * $d) - 1; $viewend = $tikilib->make_time(0, 0, 0, TikiLib::date_format("%m", $daystart), TikiLib::date_format("%d", $daystart) + 7, TikiLib::date_format("%Y", $daystart)) - 1; $dayend = $viewend; $numberofweeks = 0; } else { $firstweek = $currentweek; $lastweek = $currentweek; // $viewend = $viewstart + ($d - 1);
/** * @private * Caculate the correct article date period */ function _getArticleCorrectedDatePeriod() { $blogSettings = $this->_blogInfo->getSettings(); $serverTimeOffset = $blogSettings->getValue("time_offset"); if ($serverTimeOffset == 0) { $this->_maxDate = -1; } else { if (strlen($this->_date) == 4) { $year = $this->_date; $this->_date = Timestamp::getDateWithOffset($year . "0101000000", -$serverTimeOffset); $this->_maxDate = Timestamp::getDateWithOffset($year . "1231235959", -$serverTimeOffset); } elseif (strlen($this->_date) == 6) { $year = substr($this->_date, 0, 4); $month = substr($this->_date, 4, 2); $dayOfMonth = Date_Calc::daysInMonth($month, $year); $this->_date = Timestamp::getDateWithOffset($year . $month . "01000000", -$serverTimeOffset); $this->_maxDate = Timestamp::getDateWithOffset($year . $month . $dayOfMonth . "235959", -$serverTimeOffset); } elseif (strlen($this->_date) == 8) { $year = substr($this->_date, 0, 4); $month = substr($this->_date, 4, 2); $day = substr($this->_date, 6, 2); $this->_date = Timestamp::getDateWithOffset($year . $month . $day . "000000", -$serverTimeOffset); $this->_maxDate = Timestamp::getDateWithOffset($year . $month . $day . "235959", -$serverTimeOffset); } else { $this->_maxDate = -1; } } }
public function MakeRecurrences() { global $_EV_CONF; $days_on = $this->event->rec_data['listdays']; if (!is_array($days_on)) { return $this->events; } $occurrence = $this->dt_start; $num_intervals = count($days_on); $last_interval = $days_on[$num_intervals - 1]; // Start by reducing the starting date by one day. Then the for // loop can handle all the events. list($y, $m, $d) = explode('-', $occurrence); //$occurrence = Date_Calc::prevDay($d, $m, $y); //$count = 1; $count = 0; while ($occurrence <= $this->event->rec_data['stop'] && $count < $_EV_CONF['max_repeats']) { $lastday = Date_Calc::daysInMonth($m, $y); // last day in month foreach ($days_on as $dom) { if ($dom == 32) { $dom = $lastday; } elseif ($dom > $lastday) { break; } $occurrence = sprintf("%d-%02d-%02d", $y, $m, $dom); // We might pick up some earlier instances, skip them if ($occurrence < $this->dt_start) { continue; } // Stop when we hit the stop date if ($occurrence > $this->event->rec_data['stop']) { break; } if ($this->skip > 0) { $occurrence = $this->SkipWeekend($occurrence); } if ($occurrence != NULL) { $this->storeEvent($occurrence); $count++; } if ($count > $_EV_CONF['max_repeats']) { break; } //list($y, $m, $d) = explode('-', $occurrence); } // foreach days_on // Increment the month $m += $this->event->rec_data['freq']; if ($m > 12) { // Roll over to next year $y += 1; $m = $m - 12; } } // while not at stop date return $this->events; }
/** * Specifically handle month recurrence * * This method will take care of parsing the month * recurrence data and correctly rescheduling a * scan if the recurrence time has been met * * @param array $parameters Array of the parameters * from the database entry for this recurrence * setting */ private function handle_month_recurrence($parameters) { $the_interval = $parameters['the_interval']; $profile_id = $parameters['profile_id']; $date_scheduled = $parameters['date_scheduled']; $rules_string = $parameters['rules_string']; $specific_time = $this->specific_time($parameters['specific_time']); // The monthly rules string is colon delimited with a max of 3 items $tmp = explode(':', $rules_string); // The type of monthly recursion will be 'day' or 'gen' $type = $tmp[0]; // This is either the day of the month, or a relative day of the week $day = $tmp[1]; /** * Take the date the scan was scheduled, and only return the * year and month because my calculations are based off of the 0th * day of the month at midnight. Using 0th day because of how * strtotime determines it's offset */ $month_time = strtotime($date_scheduled); $month_time = strftime("%Y-%m-00 00:00:00", $month_time); /** * Get X months in the future from the last date scheduled * Because the remaining date calculations will be based * off of that future time. */ $time = strtotime("+{$the_interval} month", strtotime($month_time)); /** * Turn the future date into PEAR object so I can use * the PEAR object's methods. */ $future_date = new Date($time); $future_month = $future_date->getMonth(); $future_year = $future_date->getYear(); switch ($type) { case "gen": // Get the weekday that was specified $weekday = $this->get_weekday_fullname($tmp[2]); // Get the number of days in the month $days_in_month = Date_Calc::daysInMonth($future_month, $future_year); /** * Turn the above into an array where the day of the * month is the value. The last value will be the last * day of the month */ for ($day = 1; $day <= $days_in_month; $day++) { $days[] = $day; } $days_in_month = $days; switch ($day) { case "1st": $day = $this->get_relative_day($days_in_month, $future_month, $future_year, $weekday); $future_date->setDay($day); break; case "2nd": $day = $this->get_relative_day($days_in_month, $future_month, $future_year, $weekday, 2); $future_date->setDay($day); break; case "3rd": $day = $this->get_relative_day($days_in_month, $future_month, $future_year, $weekday, 3); $future_date->setDay($day); break; case "4th": $day = $this->get_relative_day($days_in_month, $future_month, $future_year, $weekday, 4); $future_date->setDay($day); break; case "last": $days_in_month = array_reverse($days_in_month); /** * I reversed the array above, so in essence we're * starting from the end of the month, therefore the * "last" day of the month will, in this case, be * the first match */ $day = $this->get_relative_day($days_in_month, $future_month, $future_year, $weekday); $future_date->setDay($day); break; case "2_last": $days_in_month = array_reverse($days_in_month); /** * I reversed the array above, so in essence we're * starting from the end of the month, therefore the * "2nd to last" day of the month will, in this case, be * the second match */ $day = $this->get_relative_day($days_in_month, $future_month, $future_year, $weekday, 2); $future_date->setDay($day); break; } break; default: $future_date->setDay($day); break; } $future_date = $this->set_new_time($future_date, $specific_time); // Compare the dates if ($this->today->after($future_date)) { // Update the date scheduled field $this->reschedule_scan($profile_id, $this->today->getDate()); // Reschedule the scan $this->update_scan_status($profile_id, 'F', 'P'); } }
compare(3, Date_Calc::dayOfWeek(22, 11, 2000), 'dayOfWeek'); compare(47, Date_Calc::weekOfYear(22, 11, 2000), 'weekOfYear'); 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');
/** * Calculates the date of the Nth weekday of the month, * such as the second Saturday of January 2000 * * @param int $week the number of the week to get * (1 to 5. Also can be 'last'.) * @param int $dow the day of the week (0 = Sunday) * @param int $month the month * @param int $year the year. Use the complete year instead of the * abbreviated version. E.g. use 2005, not 05. * @param string $format the string indicating how to format the output * * @return string the date in the desired format * @access public * @static */ function nWeekDayOfMonth($week, $dow, $month, $year, $format = DATE_CALC_FORMAT) { if (is_numeric($week) && ($week < 1 || $week > 5) || !is_numeric($week) && $week != "last") { return PEAR::raiseError("Invalid week value '{$week}', only 1-5 or 'last' accepted"); } if ($dow < 0 || $dow > 6) { return PEAR::raiseError("Invalid dow value '{$dow}', only 0-6 accepted"); } if ($month < 1 || $month > 12) { return PEAR::raiseError("Invalid month value '{$month}'"); } if (is_numeric($week)) { // the weekday of first day of month "1" $DOW1 = Date_Calc::dayOfWeek(1, $month, $year); // finds the sunday $sunday = ($week - 1) * 7 + 1; if ($DOW1 > 0) { $sunday += 7 - $DOW1; } // adjust the sunday with dow addition $wdate = $sunday + $dow; if ($wdate > Date_Calc::daysInMonth($month, $year)) { return -1; } else { return Date_Calc::dateFormat($wdate, $month, $year, $format); } } elseif ($week == 'last' && $dow < 7) { $lastday = Date_Calc::daysInMonth($month, $year); $lastdow = Date_Calc::dayOfWeek($lastday, $month, $year); $diff = $dow - $lastdow; if ($diff > 0) { return Date_Calc::dateFormat($lastday - (7 - $diff), $month, $year, $format); } else { return Date_Calc::dateFormat($lastday + $diff, $month, $year, $format); } } else { return -1; } }