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


PHP Date_Calc类代码示例

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


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

示例1: compare

 /**
 * 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;
 }
开发者ID:juliogallardo1326,项目名称:proc,代码行数:40,代码来源:date.class.php

示例2: _hours

 protected function _hours()
 {
     $hours_html = '';
     $dayWidth = round(100 / $this->_days);
     $week = Date_Calc::weekOfYear(1, $this->_start->month, $this->_start->year);
     $span = (7 - $week) % 7 + 1;
     $span_left = $this->_days;
     $t = new Horde_Date($this->_start);
     while ($span_left > 0) {
         $span_left -= $span;
         $week_label = Horde::url('#')->link(array('onclick' => 'return switchDateView(\'Week\',' . $t->dateString() . ');')) . "Week" . ' ' . $week . '</a>';
         $hours_html .= sprintf('<th colspan="%d" width="%s%%">%s</th>', $span, $dayWidth, $week_label);
         $week++;
         $t->mday += 7;
         $span = min($span_left, 7);
     }
     $hours_html .= '</tr><tr><td width="100" class="label">&nbsp;</td>';
     for ($i = 0; $i < $this->_days; $i++) {
         $t = new Horde_Date(array('month' => $this->_start->month, 'mday' => $this->_start->mday + $i, 'year' => $this->_start->year));
         $day_label = Horde::url('#')->link(array('onclick' => 'return switchDateView(\'Day\',' . $t->dateString() . ');')) . ($i + 1) . '.</a>';
         $hours_html .= sprintf('<th width="%s%%">%s</th>', $dayWidth, $day_label);
     }
     for ($i = 0; $i < $this->_days; $i++) {
         $start = new Horde_Date(array('hour' => $this->_startHour, 'month' => $this->_start->month, 'mday' => $this->_start->mday + $i, 'year' => $this->_start->year));
         $end = new Horde_Date(array('hour' => $this->_endHour, 'month' => $this->_start->month, 'mday' => $this->_start->mday + $i, 'year' => $this->_start->year));
         $this->_timeBlocks[] = array($start, $end);
     }
     return $hours_html;
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:29,代码来源:Month.php

示例3: MAX_getDatesByPeriodLimitStart

function MAX_getDatesByPeriodLimitStart($period, $limit, $start)
{
    $begin = $limit + $start - 1;
    $end = $start;
    switch ($period) {
        case 'daily':
            $dayBegin = new Date();
            $dayBegin->subtractSpan(new Date_Span("{$begin}, 0, 0, 0"));
            $dayEnd = new Date();
            $dayBegin->subtractSpan(new Date_Span("{$end}, 0, 0, 0"));
            break;
        case 'weekly':
            $dayBegin = new Date(Date_Calc::prevDay());
            $dayEnd = new Date(Date_Calc::prevDay());
            break;
        case 'monthly':
            $dayBegin = new Date();
            $dayBegin->subtractSpan(new Date_Span('6, 0, 0, 0'));
            $dayEnd = new Date();
            break;
        case 'allstats':
        default:
            $dayBegin = null;
            $dayEnd = null;
    }
    $aDates = array();
    $aDates['day_begin'] = is_object($dayBegin) ? $dayBegin->format('%Y-%m-%d') : '';
    $aDates['day_end'] = is_object($dayEnd) ? $dayEnd->format('%Y-%m-%d') : '';
    return $aDates;
}
开发者ID:Jaree,项目名称:revive-adserver,代码行数:30,代码来源:stats.php

示例4: compare

 /**
 * 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);
     $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);
 }
开发者ID:magsilva,项目名称:dotproject,代码行数:32,代码来源:date.class.php

示例5: _render

 protected function _render(Horde_Date $day = null)
 {
     $this->_start = new Horde_Date(Date_Calc::beginOfWeek($day->mday, $day->month, $day->year, '%Y%m%d000000'));
     $this->_end = new Horde_Date($this->_start);
     $this->_end->hour = 23;
     $this->_end->min = $this->_end->sec = 59;
     $this->_end->mday += $this->_days - 1;
 }
开发者ID:DSNS-LAB,项目名称:Dmail,代码行数:8,代码来源:Week.php

示例6: isbatchingmaintenancecurrent

function isbatchingmaintenancecurrent($batching_expiration_date)
{
    $bedate = $batching_expiration_date ? new CDate($batching_expiration_date) : null;
    $now = new CDate();
    if (Date_Calc::compareDates($bedate->day, $bedate->month, $bedate->year, $now->day, $now->month, $now->year) < 0) {
        return "No";
    } else {
        return "Yes";
    }
}
开发者ID:srinivasulurao,项目名称:jonel,代码行数:10,代码来源:vw_depts.php

示例7: cal_work_day_conv

function cal_work_day_conv($val)
{
    global $locale_char_set;
    $wk = Date_Calc::getCalendarWeek(null, null, null, "%a", LOCALE_FIRST_DAY);
    $day_name = $wk[($val - LOCALE_FIRST_DAY) % 7];
    if ($locale_char_set == "utf-8" && function_exists("utf8_encode")) {
        $day_name = utf8_encode($day_name);
    }
    return htmlentities($day_name, ENT_COMPAT, $locale_char_set);
}
开发者ID:slawekmikula,项目名称:dotproject,代码行数:10,代码来源:ae_dates.php

示例8: cal_work_day_conv

function cal_work_day_conv($val)
{
    global $locale_char_set, $AppUI;
    setlocale(LC_TIME, 'en');
    $wk = Date_Calc::getCalendarWeek(null, null, null, '%a', LOCALE_FIRST_DAY);
    setlocale(LC_ALL, $AppUI->user_lang);
    $day_name = $AppUI->_($wk[($val - LOCALE_FIRST_DAY) % 7]);
    if ($locale_char_set == 'utf-8' && function_exists('utf8_encode')) {
        $day_name = utf8_encode($day_name);
    }
    return htmlspecialchars($day_name, ENT_COMPAT, $locale_char_set);
}
开发者ID:joly,项目名称:web2project,代码行数:12,代码来源:ae_dates.php

示例9: cal_work_day_conv

function cal_work_day_conv($val)
{
    global $locale_char_set;
    setlocale(LC_ALL, 'en_AU' . ($locale_char_set ? '.' . $locale_char_set : '.utf8'));
    $wk = Date_Calc::getCalendarWeek(null, null, null, "%a", LOCALE_FIRST_DAY);
    setlocale(LC_ALL, $AppUI->user_lang);
    $day_name = $wk[($val - LOCALE_FIRST_DAY) % 7];
    if ($locale_char_set == "utf-8" && function_exists("utf8_encode")) {
        $day_name = utf8_encode($day_name);
    }
    return htmlentities($day_name, ENT_COMPAT, $locale_char_set);
}
开发者ID:hoodoogurus,项目名称:dotprojecteap,代码行数:12,代码来源:ae_dates.php

示例10: __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

示例11: getAgo

 public static function getAgo($timestamp)
 {
     if ($timestamp === null) {
         return '';
     }
     $diffdays = Date_Calc::dateDiff(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y'));
     /* An error occured. */
     if ($diffdays == -1) {
         return;
     }
     $ago = $diffdays * Date_Calc::compareDates(date('j', $timestamp), date('n', $timestamp), date('Y', $timestamp), date('j'), date('n'), date('Y'));
     if ($ago < -1) {
         return sprintf(Horde_Model_Translation::t(" (%s days ago)"), $diffdays);
     } elseif ($ago == -1) {
         return Horde_Model_Translation::t(" (yesterday)");
     } elseif ($ago == 0) {
         return Horde_Model_Translation::t(" (today)");
     } elseif ($ago == 1) {
         return Horde_Model_Translation::t(" (tomorrow)");
     } else {
         return sprintf(Horde_Model_Translation::t(" (in %s days)"), $diffdays);
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:23,代码来源:Date.php

示例12: date


//.........这里部分代码省略.........
                         if ($day < 1 || $day > 31) {
                             return false;
                         }
                         break;
                     case 'm':
                     case 'n':
                         if ($next == 'm') {
                             $month = (int) Validate::_substr($date, 0, 2);
                         } else {
                             $month = (int) Validate::_substr($date, 1, 2);
                         }
                         if ($month < 1 || $month > 12) {
                             return false;
                         }
                         break;
                     case 'Y':
                     case 'y':
                         if ($next == 'Y') {
                             $year = Validate::_substr($date, 4);
                             $year = (int) $year ? $year : '';
                         } else {
                             $year = (int) (substr(date('Y'), 0, 2) . Validate::_substr($date, 2));
                         }
                         if (strlen($year) != 4 || $year < 0 || $year > 9999) {
                             return false;
                         }
                         break;
                     case 'g':
                     case 'h':
                         if ($next == 'g') {
                             $hour = Validate::_substr($date, 1, 2);
                         } else {
                             $hour = Validate::_substr($date, 2);
                         }
                         if (!preg_match('/^\\d+$/', $hour) || $hour < 0 || $hour > 12) {
                             return false;
                         }
                         break;
                     case 'G':
                     case 'H':
                         if ($next == 'G') {
                             $hour = Validate::_substr($date, 1, 2);
                         } else {
                             $hour = Validate::_substr($date, 2);
                         }
                         if (!preg_match('/^\\d+$/', $hour) || $hour < 0 || $hour > 24) {
                             return false;
                         }
                         break;
                     case 's':
                     case 'i':
                         $t = Validate::_substr($date, 2);
                         if (!preg_match('/^\\d+$/', $t) || $t < 0 || $t > 59) {
                             return false;
                         }
                         break;
                     default:
                         trigger_error("Not supported char `{$next}' after % in offset " . ($i + 2), E_USER_WARNING);
                 }
                 $i++;
             } else {
                 //literal
                 if (Validate::_substr($date, 1) != $c) {
                     return false;
                 }
             }
         }
     }
     // there is remaing data, we don't want it
     if (strlen($date) && strtolower($format) != 'rfc822_compliant') {
         return false;
     }
     if (isset($day) && isset($month) && isset($year)) {
         if (!checkdate($month, $day, $year)) {
             return false;
         }
         if (strtolower($format) == 'rfc822_compliant') {
             if ($weekday != date("D", mktime(0, 0, 0, $month, $day, $year))) {
                 return false;
             }
         }
         if ($min) {
             include_once 'Date/Calc.php';
             if (is_a($min, 'Date') && Date_Calc::compareDates($day, $month, $year, $min->getDay(), $min->getMonth(), $min->getYear()) < 0) {
                 return false;
             } elseif (is_array($min) && Date_Calc::compareDates($day, $month, $year, $min[0], $min[1], $min[2]) < 0) {
                 return false;
             }
         }
         if ($max) {
             include_once 'Date/Calc.php';
             if (is_a($max, 'Date') && Date_Calc::compareDates($day, $month, $year, $max->getDay(), $max->getMonth(), $max->getYear()) > 0) {
                 return false;
             } elseif (is_array($max) && Date_Calc::compareDates($day, $month, $year, $max[0], $max[1], $max[2]) > 0) {
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:ljarray,项目名称:dbpedia,代码行数:101,代码来源:Validate.php

示例13: getPrevWeekday

 /**
  * Get a Date object for the weekday before this one
  *
  * Get a Date object for the weekday before this one.
  * The time of the returned Date object is the same as this time.
  *
  * @access public
  * @return object Date Date representing the previous weekday
  */
 function getPrevWeekday()
 {
     $day = Date_Calc::prevWeekday($this->day, $this->month, $this->year, "%Y-%m-%d");
     $date = sprintf("%s %02d:%02d:%02d", $day, $this->hour, $this->minute, $this->second);
     $newDate = new Date();
     $newDate->setDate($date);
     return $newDate;
 }
开发者ID:mickdane,项目名称:zidisha,代码行数:17,代码来源:Date.php

示例14: showDays

function showDays()
{
    global $allocated_hours_sum, $end_date, $start_date, $AppUI, $user_list, $user_names, $user_usage, $hideNonWd, $table_header, $table_rows, $df, $working_days_count, $total_hours_capacity, $total_hours_capacity_all;
    $days_difference = $end_date->dateDiff($start_date);
    $actual_date = $start_date;
    $working_days_count = 0;
    $allocated_hours_sum = 0;
    $table_header = "<tr><th>" . $AppUI->_("User") . "</th>";
    for ($i = 0; $i <= $days_difference; $i++) {
        if ($actual_date->isWorkingDay() || !$actual_date->isWorkingDay() && !$hideNonWd) {
            $table_header .= "<th>" . utf8_encode(Date_Calc::getWeekdayAbbrname($actual_date->day, $actual_date->month, $actual_date->year, 3)) . "<br>" . $actual_date->format('%d/%m') . "</th>";
        }
        if ($actual_date->isWorkingDay()) {
            $working_days_count++;
        }
        $actual_date->addDays(1);
    }
    $table_header .= "<th nowrap='nowrap' colspan='2'>" . $AppUI->_("Allocated") . "</th></tr>";
    $table_rows = "";
    foreach ($user_list as $user_id => $user_data) {
        @($user_names[$user_id] = $user_data["user_username"]);
        if (isset($user_usage[$user_id])) {
            $table_rows .= "<tr><td nowrap='nowrap'>(" . $user_data["user_username"] . ") " . $user_data["contact_first_name"] . " " . $user_data["contact_last_name"] . "</td>";
            $actual_date = $start_date;
            for ($i = 0; $i <= $days_difference; $i++) {
                if ($actual_date->isWorkingDay() || !$actual_date->isWorkingDay() && !$hideNonWd) {
                    $table_rows .= "<td>";
                    if (isset($user_usage[$user_id][$actual_date->format("%Y%m%d")])) {
                        $hours = number_format($user_usage[$user_id][$actual_date->format("%Y%m%d")], 2);
                        $table_rows .= $hours;
                        $percentage_used = round($hours / dPgetConfig("daily_working_hours") * 100);
                        $bar_color = "blue";
                        if ($percentage_used > 100) {
                            $bar_color = "red";
                            $percentage_used = 100;
                        }
                        $table_rows .= "<div style='height:2px;width:{$percentage_used}%; background-color:{$bar_color}'>&nbsp;</div>";
                    } else {
                        $table_rows .= "&nbsp;";
                    }
                    $table_rows .= "</td>";
                }
                $actual_date->addDays(1);
            }
            $array_sum = array_sum($user_usage[$user_id]);
            $average_user_usage = number_format($array_sum / ($working_days_count * dPgetConfig("daily_working_hours")) * 100, 2);
            $allocated_hours_sum += $array_sum;
            $bar_color = "blue";
            if ($average_user_usage > 100) {
                $bar_color = "red";
                $average_user_usage = 100;
            }
            $table_rows .= "<td ><div align='left'>" . round($array_sum, 2) . " " . $AppUI->_("hours") . "</td> <td align='right'> " . $average_user_usage;
            $table_rows .= "%</div>";
            $table_rows .= "<div align='left' style='height:2px;width:{$average_user_usage}%; background-color:{$bar_color}'>&nbsp;</div></td>";
            $table_rows .= "</tr>";
        }
    }
    $total_hours_capacity = $working_days_count * dPgetConfig("daily_working_hours") * count($user_usage);
    $total_hours_capacity_all = $working_days_count * dPgetConfig("daily_working_hours") * count($user_list);
}
开发者ID:n2i,项目名称:xvnkb,代码行数:61,代码来源:allocateduserhours.php

示例15: getDuration

 public function getDuration()
 {
     if (isset($this->_duration)) {
         return $this->_duration;
     }
     if ($this->start && $this->end) {
         $dur_day_match = Date_Calc::dateDiff($this->start->mday, $this->start->month, $this->start->year, $this->end->mday, $this->end->month, $this->end->year);
         $dur_hour_match = $this->end->hour - $this->start->hour;
         $dur_min_match = $this->end->min - $this->start->min;
         while ($dur_min_match < 0) {
             $dur_min_match += 60;
             --$dur_hour_match;
         }
         while ($dur_hour_match < 0) {
             $dur_hour_match += 24;
             --$dur_day_match;
         }
     } else {
         $dur_day_match = 0;
         $dur_hour_match = 1;
         $dur_min_match = 0;
     }
     $this->_duration = new stdClass();
     $this->_duration->day = $dur_day_match;
     $this->_duration->hour = $dur_hour_match;
     $this->_duration->min = $dur_min_match;
     $this->_duration->wholeDay = $this->isAllDay();
     return $this->_duration;
 }
开发者ID:DSNS-LAB,项目名称:Dmail,代码行数:29,代码来源:Event.php


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