/** * This method simply compares the two dates input. Basically it works by * trying $d1 - $d2. If the result is negative (aka $d2 is after $d1), * this function returns -1. If the result is positive (aka $d1 is after * $d2), this function returns 1. * * If you're sure the two dates are in different timezones, you can use * the third parameter to convert them both to UTC prior to performing the * check. * * @param $d1 * @param $d2 * @param bool $convertTZ * @return int */ public function compare($d1, $d2, $convertTZ = false) { if ($convertTZ) { $d1->convertTZ(new Date_TimeZone('UTC')); $d2->convertTZ(new Date_TimeZone('UTC')); } $date_calc = new Date_Calc(); $days1 = $date_calc->dateToDays($d1->day, $d1->month, $d1->year); $days2 = $date_calc->dateToDays($d2->day, $d2->month, $d2->year); $comp_value = 0; if ($days1 - $days2) { $comp_value = $days1 - $days2; } else { if ($d1->hour - $d2->hour) { $comp_value = w2Psgn($d1->hour - $d2->hour); } else { if ($d1->minute - $d2->minute) { $comp_value = w2Psgn($d1->minute - $d2->minute); } else { if ($d1->second - $d2->second) { $comp_value = w2Psgn($d1->second - $d2->second); } } } } return w2Psgn($comp_value); }
/** * Overloaded compare method * * The convertTZ calls are time intensive calls. When a compare call is * made in a recussive loop the lag can be significant. */ function compare($d1, $d2, $convertTZ = false) { if (!is_object($d1)) { $d1 = new CDate($d1); } else { if (!is_object($d2)) { $d2 = new CDate($d2); } } if ($convertTZ) { $d1->convertTZ(new Date_TimeZone('UTC')); $d2->convertTZ(new Date_TimeZone('UTC')); } $days1 = Date_Calc::dateToDays($d1->day, $d1->month, $d1->year); $days2 = Date_Calc::dateToDays($d2->day, $d2->month, $d2->year); $comp_value = 0; if ($days1 - $days2) { $comp_value = $days1 - $days2; } else { if ($d1->hour - $d2->hour) { $comp_value = dPsgn($d1->hour - $d2->hour); } else { if ($d1->minute - $d2->minute) { $comp_value = dPsgn($d1->minute - $d2->minute); } else { if ($d1->second - $d2->second) { $comp_value = dPsgn($d1->second - $d2->second); } } } } return dPsgn($comp_value); }
/** * Overloaded compare method * * The convertTZ calls are time intensive calls. When a compare call is * made in a recussive loop the lag can be significant. */ function compare($d1, $d2, $convertTZ = false) { if ($convertTZ) { $d1->convertTZ(new Date_TimeZone('UTC')); $d2->convertTZ(new Date_TimeZone('UTC')); } $days1 = Date_Calc::dateToDays($d1->day, $d1->month, $d1->year); $days2 = Date_Calc::dateToDays($d2->day, $d2->month, $d2->year); if ($days1 < $days2) { return -1; } if ($days1 > $days2) { return 1; } if ($d1->hour < $d2->hour) { return -1; } if ($d1->hour > $d2->hour) { return 1; } if ($d1->minute < $d2->minute) { return -1; } if ($d1->minute > $d2->minute) { return 1; } if ($d1->second < $d2->second) { return -1; } if ($d1->second > $d2->second) { return 1; } return 0; }
/** * Formats the date in the given format, much like * strfmt(). This function is used to alleviate the * problem with 32-bit numbers for dates pre 1970 * or post 2038, as strfmt() has on most systems. * Most of the formatting options are compatible. * * formatting options: * * %a abbreviated weekday name (Sun, Mon, Tue) * %A full weekday name (Sunday, Monday, Tuesday) * %b abbreviated month name (Jan, Feb, Mar) * %B full month name (January, February, March) * %d day of month (range 00 to 31) * %e day of month, single digit (range 0 to 31) * %E number of days since unspecified epoch (integer) * (%E is useful for passing a date in a URL as * an integer value. Then simply use * daysToDate() to convert back to a date.) * %j day of year (range 001 to 366) * %m month as decimal number (range 1 to 12) * %n newline character (\n) * %t tab character (\t) * %w weekday as decimal (0 = Sunday) * %U week number of current year, first sunday as first week * %y year as decimal (range 00 to 99) * %Y year as decimal including century (range 0000 to 9999) * %% literal '%' * * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * @param string format for returned date * * @access public * * @return string date in given format */ function dateFormat($day, $month, $year, $format) { if (!Date_Calc::isValidDate($day, $month, $year)) { $year = Date_Calc::dateNow("%Y"); $month = Date_Calc::dateNow("%m"); $day = Date_Calc::dateNow("%d"); } $output = ""; for ($strpos = 0; $strpos < strlen($format); $strpos++) { $char = substr($format, $strpos, 1); if ($char == "%") { $nextchar = substr($format, $strpos + 1, 1); switch ($nextchar) { case "a": $output .= Date_Calc::getWeekdayAbbrname($day, $month, $year); break; case "A": $output .= Date_Calc::getWeekdayFullname($day, $month, $year); break; case "b": $output .= Date_Calc::getMonthAbbrname($month); break; case "B": $output .= Date_Calc::getMonthFullname($month); break; case "d": $output .= sprintf("%02d", $day); break; case "e": $output .= $day; break; case "E": $output .= Date_Calc::dateToDays($day, $month, $year); break; case "j": $output .= Date_Calc::julianDate($day, $month, $year); break; case "m": $output .= sprintf("%02d", $month); break; case "n": $output .= "\n"; break; case "t": $output .= "\t"; break; case "w": $output .= Date_Calc::dayOfWeek($day, $month, $year); break; case "U": $output .= Date_Calc::weekOfYear($day, $month, $year); break; case "y": $output .= substr($year, 2, 2); break; case "Y": $output .= $year; break; case "%": $output .= "%"; break; default: $output .= $char . $nextchar; } $strpos++; } else { $output .= $char; } } return $output; }
/** * Rounds the date according to the specified precision * * The precision parameter must be one of the following constants: * * <code>DATE_PRECISION_YEAR</code> * <code>DATE_PRECISION_MONTH</code> * <code>DATE_PRECISION_DAY</code> * <code>DATE_PRECISION_HOUR</code> * <code>DATE_PRECISION_10MINUTES</code> * <code>DATE_PRECISION_MINUTE</code> * <code>DATE_PRECISION_10SECONDS</code> * <code>DATE_PRECISION_SECOND</code> * * The precision can also be specified as an integral offset from * one of these constants, where the offset reflects a precision * of 10 to the power of the offset greater than the constant. * For example: * * <code>DATE_PRECISION_YEAR - 1</code> rounds the date to the nearest 10 * years * <code>DATE_PRECISION_YEAR - 3</code> rounds the date to the nearest 1000 * years * <code>DATE_PRECISION_SECOND + 1</code> rounds the date to 1 decimal * point of a second * <code>DATE_PRECISION_SECOND + 1</code> rounds the date to 3 decimal * points of a second * <code>DATE_PRECISION_SECOND + 1</code> rounds the date to the nearest 10 * seconds (thus it is equivalent to * DATE_PRECISION_10SECONDS) * * N.B. This function requires a time in UTC if both the precision is at * least DATE_PRECISION_SECOND and leap seconds are being counted, otherwise * any local time is acceptable. * * @param int $pn_precision a 'DATE_PRECISION_*' constant * @param int $pn_day the day of the month * @param int $pn_month the month * @param int $pn_year the year * @param int $pn_hour the hour * @param int $pn_minute the minute * @param mixed $pn_second the second as integer or float * @param bool $pb_countleap whether to count leap seconds (defaults to * DATE_COUNT_LEAP_SECONDS) * * @return array array of year, month, day, hour, minute, second * @access public * @static * @since Method available since Release 1.5.0 */ function round($pn_precision, $pn_day, $pn_month, $pn_year, $pn_hour = 0, $pn_minute = 0, $pn_second = 0, $pb_countleap = DATE_COUNT_LEAP_SECONDS) { if ($pn_precision <= DATE_PRECISION_YEAR) { $hn_month = 0; $hn_day = 0; $hn_hour = 0; $hn_minute = 0; $hn_second = 0; if ($pn_precision < DATE_PRECISION_YEAR) { $hn_year = round($pn_year, $pn_precision - DATE_PRECISION_YEAR); } else { // Check part-year: // $hn_midyear = (Date_Calc::firstDayOfYear($pn_year + 1) - Date_Calc::firstDayOfYear($pn_year)) / 2; if (($hn_days = Date_Calc::dayOfYear($pn_day, $pn_month, $pn_year)) <= $hn_midyear - 1) { $hn_year = $pn_year; } else { if ($hn_days >= $hn_midyear) { // Round up: // $hn_year = $pn_year + 1; } else { // Take time into account: // $hn_partday = Date_Calc::secondsPastMidnight($pn_hour, $pn_minute, $pn_second) / 86400; if ($hn_partday >= $hn_midyear - $hn_days) { // Round up: // $hn_year = $pn_year + 1; } else { $hn_year = $pn_year; } } } } } else { if ($pn_precision == DATE_PRECISION_MONTH) { $hn_year = $pn_year; $hn_day = 0; $hn_hour = 0; $hn_minute = 0; $hn_second = 0; $hn_firstofmonth = Date_Calc::firstDayOfMonth($pn_month, $pn_year); $hn_midmonth = (Date_Calc::lastDayOfMonth($pn_month, $pn_year) + 1 - $hn_firstofmonth) / 2; if (($hn_days = Date_Calc::dateToDays($pn_day, $pn_month, $pn_year) - $hn_firstofmonth) <= $hn_midmonth - 1) { $hn_month = $pn_month; } else { if ($hn_days >= $hn_midmonth) { // Round up: // list($hn_year, $hn_month) = Date_Calc::nextMonth($pn_month, $pn_year); } else { // Take time into account: // $hn_partday = Date_Calc::secondsPastMidnight($pn_hour, $pn_minute, $pn_second) / 86400; if ($hn_partday >= $hn_midmonth - $hn_days) { // Round up: // list($hn_year, $hn_month) = Date_Calc::nextMonth($pn_month, $pn_year); } else { $hn_month = $pn_month; } } } } else { if ($pn_precision == DATE_PRECISION_DAY) { $hn_year = $pn_year; $hn_month = $pn_month; $hn_hour = 0; $hn_minute = 0; $hn_second = 0; if (Date_Calc::secondsPastMidnight($pn_hour, $pn_minute, $pn_second) >= 43200) { // Round up: // list($hn_year, $hn_month, $hn_day) = explode(" ", Date_Calc::nextDay($pn_day, $pn_month, $pn_year, "%Y %m %d")); } else { $hn_day = $pn_day; } } else { if ($pn_precision == DATE_PRECISION_HOUR) { $hn_year = $pn_year; $hn_month = $pn_month; $hn_day = $pn_day; $hn_minute = 0; $hn_second = 0; if (Date_Calc::secondsPastTheHour($pn_minute, $pn_second) >= 1800) { // Round up: // list($hn_year, $hn_month, $hn_day, $hn_hour) = Date_Calc::addHours(1, $pn_day, $pn_month, $pn_year, $pn_hour); } else { $hn_hour = $pn_hour; } } else { if ($pn_precision <= DATE_PRECISION_MINUTE) { $hn_year = $pn_year; $hn_month = $pn_month; $hn_day = $pn_day; $hn_hour = $pn_hour; $hn_second = 0; if ($pn_precision < DATE_PRECISION_MINUTE) { $hn_minute = round($pn_minute, $pn_precision - DATE_PRECISION_MINUTE); } else { // Check seconds: // if ($pn_second >= 30) { // Round up: // list($hn_year, $hn_month, $hn_day, $hn_hour, $hn_minute) = Date_Calc::addMinutes(1, $pn_day, $pn_month, $pn_year, $pn_hour, $pn_minute); } else { $hn_minute = $pn_minute; } } } else { // Precision is at least (DATE_PRECISION_SECOND - 1): // $hn_year = $pn_year; $hn_month = $pn_month; $hn_day = $pn_day; $hn_hour = $pn_hour; $hn_minute = $pn_minute; $hn_second = round($pn_second, $pn_precision - DATE_PRECISION_SECOND); if (fmod($hn_second, 1) == 0.0) { $hn_second = (int) $hn_second; if ($hn_second != intval($pn_second)) { list($hn_year, $hn_month, $hn_day, $hn_hour, $hn_minute, $hn_second) = Date_Calc::addSeconds($hn_second - intval($pn_second), $pn_day, $pn_month, $pn_year, $pn_hour, $pn_minute, intval($pn_second), $pn_precision >= DATE_PRECISION_SECOND && $pb_countleap); // // (N.B. if rounded to nearest 10 seconds, // user does not expect seconds to be '60') } } } } } } } return array((int) $hn_year, (int) $hn_month, (int) $hn_day, (int) $hn_hour, (int) $hn_minute, $hn_second); }
/** * Compares two dates * * @param int $day1 the day of the month * @param int $month1 the month * @param int $year1 the year. Use the complete year instead of the * abbreviated version. E.g. use 2005, not 05. * Do not add leading 0's for years prior to 1000. * @param int $day2 the day of the month * @param int $month2 the month * @param int $year2 the year. Use the complete year instead of the * abbreviated version. E.g. use 2005, not 05. * Do not add leading 0's for years prior to 1000. * * @return int 0 if the dates are equal. 1 if date 1 is later, -1 if * date 1 is earlier. * * @access public * @static */ function compareDates($day1, $month1, $year1, $day2, $month2, $year2) { $ndays1 = Date_Calc::dateToDays($day1, $month1, $year1); $ndays2 = Date_Calc::dateToDays($day2, $month2, $year2); if ($ndays1 == $ndays2) { return 0; } return $ndays1 > $ndays2 ? 1 : -1; }
/** * Compares two dates * * Suitable for use in sorting functions. * * @param object $od1 the first Date object to compare * @param object $od2 the second Date object to compare * * @return int 0 if the dates are equal, -1 if '$od1' is * before '$od2', 1 if '$od1' is after '$od2' * @access public * @static */ function compare($od1, $od2) { $d1 = new Date($od1); $d2 = new Date($od2); // If the time zones are equivalent, do nothing: // if (!Date::inEquivalentTimeZones($d1, $d2)) { // Only a time zone with a valid time can be converted: // if ($d2->isTimeValid()) { $d2->convertTZByID($d1->getTZID()); } else { if ($d1->isTimeValid()) { $d1->convertTZByID($d2->getTZID()); } else { // No comparison can be made without guessing the time: // return PEAR::raiseError("Both dates have invalid time", DATE_ERROR_INVALIDTIME); } } } $days1 = Date_Calc::dateToDays($d1->getDay(), $d1->getMonth(), $d1->getYear()); $days2 = Date_Calc::dateToDays($d2->getDay(), $d2->getMonth(), $d2->getYear()); if ($days1 < $days2) { return -1; } if ($days1 > $days2) { return 1; } $hn_hour1 = $d1->getStandardHour(); if (PEAR::isError($hn_hour1)) { return $hn_hour1; } $hn_hour2 = $d2->getStandardHour(); if (PEAR::isError($hn_hour2)) { return $hn_hour2; } if ($hn_hour1 < $hn_hour2) { return -1; } if ($hn_hour1 > $hn_hour2) { return 1; } if ($d1->getStandardMinute() < $d2->getStandardMinute()) { return -1; } if ($d1->getStandardMinute() > $d2->getStandardMinute()) { return 1; } if ($d1->getStandardSecond() < $d2->getStandardSecond()) { return -1; } if ($d1->getStandardSecond() > $d2->getStandardSecond()) { return 1; } if ($d1->getStandardPartSecond() < $d2->getStandardPartSecond()) { return -1; } if ($d1->getStandardPartSecond() > $d2->getStandardPartSecond()) { return 1; } return 0; }
/** * Formats the date in the given format, much like * strfmt(). This function is used to alleviate the * problem with 32-bit numbers for dates pre 1970 * or post 2038, as strfmt() has on most systems. * Most of the formatting options are compatible. * * formatting options: * * %a abbreviated weekday name (Sun, Mon, Tue) * %A full weekday name (Sunday, Monday, Tuesday) * %b abbreviated month name (Jan, Feb, Mar) * %B full month name (January, February, March) * %d day of month (range 00 to 31) * %e day of month, single digit (range 0 to 31) * %E number of days since unspecified epoch (integer) * (%E is useful for passing a date in a URL as * an integer value. Then simply use * daysToDate() to convert back to a date.) * %j day of year (range 001 to 366) * %m month as decimal number (range 1 to 12) * %n newline character (\n) * %t tab character (\t) * %w weekday as decimal (0 = Sunday) * %U week number of current year, first sunday as first week * %y year as decimal (range 00 to 99) * %Y year as decimal including century (range 0000 to 9999) * %% literal '%' * * @param string day in format DD * @param string month in format MM * @param string year in format CCYY * @param string format for returned date * * @access public * * @return string date in given format */ function dateFormat($day, $month, $year, $format) { if (!Date_Calc::isValidDate($day, $month, $year)) { $year = Date_Calc::dateNow('%Y'); $month = Date_Calc::dateNow('%m'); $day = Date_Calc::dateNow('%d'); } $output = ''; for ($strpos = 0; $strpos < strlen($format); $strpos++) { $char = substr($format, $strpos, 1); if ($char == '%') { $nextchar = substr($format, $strpos + 1, 1); switch ($nextchar) { case 'a': $output .= Date_Calc::getWeekdayAbbrname($day, $month, $year); break; case 'A': $output .= Date_Calc::getWeekdayFullname($day, $month, $year); break; case 'b': $output .= Date_Calc::getMonthAbbrname($month); break; case 'B': $output .= Date_Calc::getMonthFullname($month); break; case 'd': $output .= sprintf('%02d', $day); break; case 'e': $output .= $day; break; case 'E': $output .= Date_Calc::dateToDays($day, $month, $year); break; case 'j': $output .= Date_Calc::julianDate($day, $month, $year); break; case 'm': $output .= sprintf('%02d', $month); break; case 'n': $output .= "\n"; break; case "t": $output .= "\t"; break; case 'w': $output .= Date_Calc::dayOfWeek($day, $month, $year); break; case 'U': $output .= Date_Calc::weekOfYear($day, $month, $year); break; case 'y': $output .= substr($year, 2, 2); break; case 'Y': $output .= $year; break; case '%': $output .= '%'; break; default: $output .= $char . $nextchar; } $strpos++; } else { $output .= $char; } } return $output; }
/** * Converts the date to the specified no of days from the given date * * To subtract days use a negative value for the '$pn_days' parameter * * @param Date $date Date object * @param int $pn_days days to add * * @return Date * @access protected */ function _addDays($date, $pn_days) { $new_date = new Date($date); list($new_date->year, $new_date->month, $new_date->day) = explode(' ', Date_Calc::daysToDate(Date_Calc::dateToDays($date->day, $date->month, $date->year) + $pn_days, '%Y %m %d')); return $new_date; }
function &postcalendar_userapi_pcGetEvents($args) { $s_keywords = $s_category = $s_topic = ''; extract($args); $date = postcalendar_getDate(); $cy = substr($date, 0, 4); $cm = substr($date, 4, 2); $cd = substr($date, 6, 2); if (isset($start) && isset($end)) { // parse start date list($sm, $sd, $sy) = explode('/', $start); // parse end date list($em, $ed, $ey) = explode('/', $end); $s = (int) "{$sy}{$sm}{$sd}"; if ($s > $date) { $cy = $sy; $cm = $sm; $cd = $sd; } $start_date = Date_Calc::dateFormat($sd, $sm, $sy, '%Y-%m-%d'); $end_date = Date_Calc::dateFormat($ed, $em, $ey, '%Y-%m-%d'); } else { // missing start OR end date, set them to the current date $sm = $em = $cm; $sd = $ed = $cd; $sy = $cy; $ey = $cy + 2; $start_date = $sy . '-' . $sm . '-' . $sd; $end_date = $ey . '-' . $em . '-' . $ed; } if ($faFlag && !isset($events)) { $a = array('faFlag' => true, 'start' => $start_date, 'end' => $end_date, 's_keywords' => $s_keywords, 's_category' => $s_category, 's_topic' => $s_topic, 'viewtype' => $viewtype, 'provider_id' => $provider_id, 'event_status' => $event_status); $events = pnModAPIFunc(__POSTCALENDAR__, 'user', '<strong></strong>pcQueryEventsFA', $a); } elseif ($collideFlag && !isset($events)) { $a = array('collideFlag' => true, 'start' => $start_date, 'end' => $end_date, 'provider_id' => $provider_id, 'collide_stime' => $stime, 'collide_etime' => $etime); $events = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pcQueryEventsFA', $a); } elseif ($listappsFlag && !isset($events)) { $a = array('listappsFlag' => true, 'start' => $start_date, 'end' => $end_date, 'patient_id' => $patient_id, 's_keywords' => $s_keywords); $events = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pcQueryEvents', $a); } else { if (!isset($events)) { if (!isset($s_keywords)) { $s_keywords = ''; } $a = array('start' => $start_date, 'end' => $end_date, 's_keywords' => $s_keywords, 's_category' => $s_category, 's_topic' => $s_topic, 'viewtype' => $viewtype, "sort" => "pc_startTime ASC, a.pc_duration ASC ", 'providerID' => $providerID, 'provider_id' => $provider_id); $events = pnModAPIFunc(__POSTCALENDAR__, 'user', 'pcQueryEvents', $a); } } //============================================================== // Here we build an array consisting of the date ranges // specific to the current view. This array is then // used to build the calendar display. //============================================================== $days = array(); $sday = Date_Calc::dateToDays($sd, $sm, $sy); $eday = Date_Calc::dateToDays($ed, $em, $ey); for ($cday = $sday; $cday <= $eday; $cday++) { $d = Date_Calc::daysToDate($cday, '%d'); $m = Date_Calc::daysToDate($cday, '%m'); $y = Date_Calc::daysToDate($cday, '%Y'); $store_date = Date_Calc::dateFormat($d, $m, $y, '%Y-%m-%d'); $days[$store_date] = array(); } $days = calculateEvents($days, $events, $viewtype); return $days; }
/** * Sloppily compares two date objects (only year, month and day are compared). * Does not take the date's timezone into account. * * @static * @access private * @param Date $d1 a date object * @param Date $d2 another date object * @return int 0 if the dates are equal, -1 if d1 is before d2, 1 if d1 is after d2 * */ function dateSloppyCompare($d1, $d2) { $d1->setTZ(new Date_TimeZone('UTC')); $d2->setTZ(new Date_TimeZone('UTC')); $days1 = Date_Calc::dateToDays($d1->day, $d1->month, $d1->year); $days2 = Date_Calc::dateToDays($d2->day, $d2->month, $d2->year); if ($days1 < $days2) { return -1; } if ($days1 > $days2) { return 1; } return 0; }
/** * Formats the date in the given format, much like * strfmt(). This function is used to alleviate the * problem with 32-bit numbers for dates pre 1970 * or post 2038, as strfmt() has on most systems. * Most of the formatting options are compatible. * * formatting options: * * %a abbreviated weekday name (Sun, Mon, Tue) * %A full weekday name (Sunday, Monday, Tuesday) * %b abbreviated month name (Jan, Feb, Mar) * %B full month name (January, February, March) * %d day of month (range 00 to 31) * %e day of month, single digit (range 0 to 31) * %E number of days since unspecified epoch (integer) * (%E is useful for passing a date in a URL as * an integer value. Then simply use * daysToDate() to convert back to a date.) * %j day of year (range 001 to 366) * %m month as decimal number (range 1 to 12) * %n newline character (\n) * %t tab character (\t) * %w weekday as decimal (0 = Sunday) * %U week number of current year, first sunday as first week * %y year as decimal (range 00 to 99) * %Y year as decimal including century (range 0000 to 9999) * %% literal '%' * * @param string year in format CCYY * @param string month in format MM * @param string day in format DD * @param string format for returned date * * @access public * * @return string date in given format */ public static function dateFormat($day, $month, $year, $format) { if (!Date_Calc::isValidDate($day, $month, $year)) { $year = Date_Calc::dateNow("%Y"); $month = Date_Calc::dateNow("%m"); $day = Date_Calc::dateNow("%d"); } $output = ""; $myTime = mktime(0, 0, 0, $month, $day, $year); for ($strpos = 0; $strpos < strlen($format); $strpos++) { $char = substr($format, $strpos, 1); if ($char == "%") { $nextchar = substr($format, $strpos + 1, 1); switch ($nextchar) { case "a": $output .= date('D', $myTime); break; case "A": $output .= date('l', $myTime); break; case "b": setlocale(LC_TIME, 'en'); $output .= date('M', $myTime); setlocale(LC_ALL, $AppUI->user_lang); break; case "B": $output .= date('F', $myTime); break; case "d": $output .= sprintf("%02d", $day); break; case "e": $output .= $day; break; case "E": $output .= Date_Calc::dateToDays($day, $month, $year); break; case "j": $output .= date('z', $myTime); break; case "m": $output .= sprintf("%02d", $month); break; case "n": $output .= "\n"; break; case "t": $output .= "\t"; break; case "w": $output .= date('w', $myTime); break; case "U": $output .= date('W', $myTime); break; case "y": $output .= date('y', $myTime); break; case "Y": $output .= $year; break; case "%": $output .= "%"; break; default: $output .= $char . $nextchar; } $strpos++; } else { $output .= $char; } } return $output; }
if ($expect != $actual) { echo "{$test_name} failed. Expect: {$expect}. Actual: {$actual}\n"; } } } if (php_sapi_name() != 'cli') { echo "<pre>\n"; } compare('20001122', Date_Calc::dateFormat(22, 11, 2000, '%Y%m%d'), 'dateFormat'); compare('20001122', Date_Calc::dateFormat('22', '11', '2000', '%Y%m%d'), 'dateFormat str'); compare('2001', Date_Calc::defaultCentury('1'), 'defaultCentury 1 str'); compare('2001', Date_Calc::defaultCentury(1), 'defaultCentury 1'); compare('1960', Date_Calc::defaultCentury(60), 'defaultCentury 2'); compare('2010', Date_Calc::defaultCentury(10), 'defaultCentury 3'); compare(2451871, Date_Calc::dateToDays('22', '11', '2000'), 'dateToDays str'); compare(2451871, Date_Calc::dateToDays(22, 11, 2000), 'dateToDays'); compare('20001122', Date_Calc::daysToDate(2451871), 'daysToDate'); compare('2000-47-3', Date_Calc::gregorianToISO('22', '11', '2000'), 'gregorianToISO str'); compare('2000-47-3', Date_Calc::gregorianToISO(22, 11, 2000), 'gregorianToISO'); compare(2451716.56767, Date_Calc::dateSeason('SUMMERSOLSTICE', 2000), 'dateSeason'); compare(date('Ymd'), Date_Calc::dateNow(), 'dateNow'); compare(date('Y'), Date_Calc::getYear(), 'getYear'); compare(date('m'), Date_Calc::getMonth(), 'getMonth'); compare(date('d'), Date_Calc::getDay(), 'getDay'); compare(327, Date_Calc::dayOfYear(22, 11, 2000), 'dayOfYear'); compare('November', Date_Calc::getMonthFullname(11), 'getMonthFullname'); compare('Nov', Date_Calc::getMonthAbbrname(11), 'getMonthAbbrname'); compare('Saturday', Date_Calc::getWeekdayFullname(1, 1, 2005), 'getWeekdayFullname'); compare('Sat', Date_Calc::getWeekdayAbbrname(1, 1, 2005), 'getWeekdayAbbrname'); compare(11, Date_Calc::getMonthFromFullName('November'), 'getMonthFromFullName'); compare(327, Date_Calc::dayOfYear('22', '11', '2000'), 'dayOfYear str');
/** * Converts the Week number and Day-of-Week to Date * * Calculation algorithm taken from * {@link http://www.merlyn.demon.co.uk/weekcalc.htm}. * * @param int $dow day of week from 1 (Monday) to 7 (Sunday) * @param int $week number of week from 1 to 53 * @param int $year four digits of year * @param string $format the output format * * @return string formatted date * @access public * @static * @since Method available since Release 1.5.0a2 */ function isoWeekToDate($dow, $week, $year, $format = DATE_CALC_FORMAT) { // validates the week number list(, $nweeks) = Date_Calc::isoWeekDate(28, 12, $year); if ($week > $nweeks) { return PEAR::raiseError("ISO week number for {$year} cannot be greater than {$nweeks}", DATE_ERROR_INVALIDDATE); } // validates the day of week if ($dow < 1 || $dow > 7) { return PEAR::raiseError("ISO day of week must be between 1 and 7", DATE_ERROR_INVALIDDATE); } // finds the day of week of January 4th. $jan4th = Date_Calc::dayOfWeek(4, 1, $year); if ($jan4th == 0) { $jan4th = 7; } // offset to the monday of that week $offset = -($jan4th - 1); // increment the days starting from january 4th. $days = Date_Calc::dateToDays(1, 1, $year) + $offset + 7 * ($week - 1) + ($dow - 1) + 3; return Date_Calc::daysToDate($days, $format); }