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


PHP DateUtil::getDatetimeDiff方法代码示例

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


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

示例1: smarty_modifier_dateformatHuman

/**
 * Smarty modifier to format datetimes in a more Human Readable form 
 * (like tomorow, 4 days from now, 6 hours ago)
 *
 * Example
 * <!--[$futuredate|dateformatHuman:'%x':'2']-->
 *
 * @author   Erik Spaan
 * @since    05/03/09
 * @param    string   $string   input datetime string
 * @param    string   $format   The format of the regular date output (default %x)
 * @param    string   $niceval  [1|2|3|4] Choose the nice value of the output (default 2)
 *                                    1 = full human readable
 *                                    2 = past date > 1 day with dateformat, otherwise human readable
 *                                    3 = within 1 day human readable, otherwise dateformat
 *                                    4 = only use the specified format
 * @return   string   the modified output
 */
function smarty_modifier_dateformatHuman($string, $format = '%x', $niceval = 2)
{
    $dom = ZLanguage::getModuleDomain('News');
    if (empty($format)) {
        $format = '%x';
    }
    // store the current datetime in a variable
    $now = DateUtil::getDatetime();
    if (empty($string)) {
        return DateUtil::formatDatetime($now, $format);
    }
    if (empty($niceval)) {
        $niceval = 2;
    }
    // now format the date with respect to the current datetime
    $res = '';
    $diff = DateUtil::getDatetimeDiff($now, $string);
    if ($diff['d'] < 0) {
        if ($niceval == 1) {
            $res = _fn('%s day ago', '%s days ago', abs($diff['d']), abs($diff['d']), $dom);
        } elseif ($niceval < 4 && $diff['d'] == -1) {
            $res = __('yesterday', $dom);
        } else {
            $res = DateUtil::formatDatetime($string, $format);
        }
    } elseif ($diff['d'] > 0) {
        if ($niceval > 2) {
            $res = DateUtil::formatDatetime($string, $format);
        } elseif ($diff['d'] == 1) {
            $res = __('tomorrow', $dom);
        } else {
            $res = _fn('%s day from now', '%s days from now', $diff['d'], $diff['d'], $dom);
        }
    } else {
        // no day difference
        if ($diff['h'] < 0) {
            $res = _fn('%s hour ago', '%s hours ago', abs($diff['h']), abs($diff['h']), $dom);
        } elseif ($diff['h'] > 0) {
            $res = _fn('%s hour from now', '%s hours from now', $diff['h'], $diff['h'], $dom);
        } else {
            // no hour difference
            if ($diff['m'] < 0) {
                $res = _fn('%s minute ago', '%s minutes ago', abs($diff['m']), abs($diff['m']), $dom);
            } elseif ($diff['m'] > 0) {
                $res = _fn('%s minute from now', '%s minutes from now', $diff['m'], $diff['m'], $dom);
            } else {
                // no min difference
                if ($diff['s'] < 0) {
                    $res = _fn('%s second ago', '%s seconds ago', abs($diff['s']), abs($diff['s']), $dom);
                } else {
                    $res = _fn('%s second from now', '%s seconds from now', $diff['s'], $diff['s'], $dom);
                }
            }
        }
    }
    return $res;
}
开发者ID:aksiide,项目名称:SuperPlugin-generator,代码行数:75,代码来源:modifier.dateformatHuman.php

示例2: calculate

 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     if ($obj['endDate'] == $obj['startDate']) {
         $out->insert(strtotime($obj['startDate']), $obj);
     } else {
         $diff = DateUtil::getDatetimeDiff($obj['startDate'], $obj['endDate']);
         $timestamp = strtotime($obj['startDate']);
         $timestamp = mktime(0, 0, 0, date('n', $timestamp), date('j', $timestamp), date('Y', $timestamp));
         // add days
         for ($i = 0; $i <= $diff['d']; $i++) {
             $out->insert($timestamp, $obj);
             // next day
             $timestamp += 86400;
         }
     }
 }
开发者ID:planetenkiller,项目名称:TimeIt,代码行数:16,代码来源:Type0.php

示例3: calculate

 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     $time = $start;
     $diff = DateUtil::getDatetimeDiff($obj['startDate'], $time);
     // weekly?
     if ($obj['repeatSpec'] == "week") {
         $weeks = (int) date('W', strtotime($start)) - (int) date('W', strtotime($obj['startDate']));
         $weeks = (int) floor($weeks / $obj['repeatFrec']);
         if ($weeks < 0) {
             $weeks = 0;
         }
         $date = DateUtil::getDatetime(strtotime('+' . $weeks * $obj['repeatFrec'] . ' week', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
         while ($date <= $end && $date <= $obj['endDate']) {
             // in requested range?
             if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                 $temp = getDate(strtotime($date));
                 $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $temp['year']);
                 $out->insert($temp, $obj);
             }
             // next occurence
             $weeks++;
             $date = DateUtil::getDatetime(strtotime('+' . $weeks * $obj['repeatFrec'] . ' week', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
         }
         // monthly?
     } else {
         if ($obj['repeatSpec'] == "month") {
             // calc start
             $years = (int) date('Y', strtotime($end)) - (int) date('Y', strtotime($obj['startDate']));
             $months = $years * 12;
             $monthsTemp = (int) date('n', strtotime($start)) - (int) date('n', strtotime($obj['startDate']));
             $months = $months + $monthsTemp;
             $months = (int) floor($months / $obj['repeatFrec']);
             $date = DateUtil::getDatetime(strtotime('+' . $months * $obj['repeatFrec'] . ' month', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
             //print_r($monthsTemp);exit();
             while ($date <= $end && $date <= $obj['endDate']) {
                 // in requested range?
                 if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                     $temp = getDate(strtotime($date));
                     $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $temp['year']);
                     $out->insert($temp, $obj);
                 }
                 // next occurence
                 $months++;
                 $date = DateUtil::getDatetime(strtotime('+' . $months * $obj['repeatFrec'] . ' month', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
             }
             // yearly
         } else {
             if ($obj['repeatSpec'] == "year") {
                 $years_start = (int) date('Y', strtotime($obj['startDate']));
                 $years_ende = (int) date('Y', strtotime($obj['endDate']));
                 for ($year = $years_start; $year <= $years_ende; $year += $obj['repeatFrec']) {
                     // calc timestamp
                     $temp = getDate(strtotime($obj['startDate']));
                     $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $year);
                     $date = DateUtil::getDatetime($temp, DATEONLYFORMAT_FIXED);
                     // in requested range?
                     if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                         $out->insert($temp, $obj);
                     }
                 }
                 // daily
             } else {
                 $repeats = (int) floor($diff['d'] / $obj['repeatFrec']);
                 $repeats--;
                 if ($repeats < 0) {
                     $daysToLastUnusedRepeat = (int) -$obj['repeatFrec'];
                     /* } else if($repeats == 0)
                        {
                                $daysToLastUnusedRepeat = 0 - $obj['repeatFrec'];*/
                 } else {
                     $daysToLastUnusedRepeat = $repeats * $obj['repeatFrec'];
                 }
                 $timestamp = strtotime($obj['startDate']);
                 $timestampEnd = strtotime($end);
                 $counter = $obj['repeatFrec'];
                 while (true) {
                     $temp = mktime(0, 0, 0, date('n', $timestamp), date('j', $timestamp) + $daysToLastUnusedRepeat + $counter, date('Y', $timestamp));
                     $counter += $obj['repeatFrec'];
                     // end reached?
                     if ($temp > strtotime($obj['endDate']) || $temp > $timestampEnd) {
                         break;
                     }
                     $out->insert($temp, $obj);
                 }
             }
         }
     }
 }
开发者ID:planetenkiller,项目名称:TimeIt,代码行数:88,代码来源:Type1.php

示例4: getStateOfEditOfIssue

 /**
  * This method checks if user must edit this posting - creater of the issue
  */
 public static function getStateOfEditOfIssue($postingid)
 {
     $dom = ZLanguage::getModuleDomain('MUBoard');
     //get repository for Postings
     $repository = MUBoard_Util_Model::getPostingRepository();
     // get posting
     $posting = $repository->selectById($postingid);
     // check if issue or anser
     $parent = $posting->getParent();
     // get forum of posting
     $forum = $posting->getForum();
     $forumid = $forum->getId();
     // get userid of user created this posting
     $createdUserId = $posting->getCreatedUserId();
     // get created Date
     $createdDate = $posting->getCreatedDate();
     $createdDate = $createdDate->getTimestamp();
     // get the actual time
     $actualTime = DateUtil::getDatetime();
     // get modvar editTime
     $editTime = ModUtil::getVar('MUBoard', 'editTime');
     $diffTime = DateUtil::getDatetimeDiff($createdDate, $actualTime);
     $diffTimeHours = $diffTime['d'] * 24 + $diffTime['h'];
     if (UserUtil::isLoggedIn() == true) {
         $userid = UserUtil::getVar('uid');
     } else {
         $out = '';
     }
     if ($createdUserId == $userid && ($diffTimeHours < $editTime || $parent == NULL)) {
         $serviceManager = ServiceUtil::getManager();
         // generate an auth key to use in urls
         //$csrftoken = SecurityUtil::generateCsrfToken($serviceManager, true); we do not use token at the moment TODO, 'token' => $csrftoken
         $url = ModUtil::url('MUBoard', 'user', 'edit', array('ot' => 'posting', 'id' => $postingid, 'forum' => $forumid));
         $title = __('You have permissions to edit this posting!', $dom);
         $out = "<a title='{$title}' id='muboard-user-posting-header-infos-edit-creater' href='{$url}'>\n            <img src='/images/icons/extrasmall/xedit.png' />\n            </a>";
     } else {
         $out = '';
     }
     return $out;
 }
开发者ID:rmaiwald,项目名称:MUBoard,代码行数:43,代码来源:View.php

示例5: assigna

    /**
     * Generates the main page for book, cancel and consult bookings
     * @author	Albert Pérez Monfort (aperezm@xtec.cat)
     * @author	Josep Ferràndiz Farré (jferran6@xtec.cat)
     * @return	the page
     */
    public function assigna($args) {
        // Security check
        if (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_READ)) {
            throw new Zikula_Exception_Forbidden();
        }

        $sid = FormUtil::getPassedValue('sid', isset($args['sid']) ? $args['sid'] : null, 'REQUEST');
        $dow = FormUtil::getPassedValue('dow', isset($args['dow']) ? $args['dow'] : 0, 'GET');
        $showontop = FormUtil::getPassedValue('sot', isset($args['sot']) ? $args['sot'] : 0, 'GET');
        $date = FormUtil::getPassedValue('d', isset($args['d']) ? $args['d'] : null, 'GET'); //User selects a cell in the booking table
        $mensual = FormUtil::getPassedValue('mensual', isset($args['mensual']) ? $args['mensual'] : null, 'REQUEST');
        $inc = FormUtil::getPassedValue('m', isset($args['m']) ? $args['m'] : null, 'GET');

        $currentDate = FormUtil::getPassedValue('date', isset($args['date']) ? $args['date'] : null, 'POST'); //User selects a date in the calendar
        $month = FormUtil::getPassedValue('month', isset($args['month']) ? $args['month'] : null, 'REQUEST');
        $year = FormUtil::getPassedValue('year', isset($args['year']) ? $args['year'] : null, 'REQUEST');

        $calendari = '';
        $formulari = '';

        // Si l'usuari selecciona una data de la taula
        if (empty($currentDate) and (!empty($date))) {
            $dateParts = explode('-', $date);
            $currentDate = DateUtil::buildDatetime($dateParts[2], $dateParts[1], $dateParts[0], 0, 0, 0, '%Y-%m-%d');
        }

        if ($sid <> -1) {
            $nom = ModUtil::apiFunc('IWbookings', 'user', 'get', array('sid' => $sid));
            $marc = $nom['mdid'];
            if ($marc != 0) {
                $n = ModUtil::apiFunc('IWbookings', 'user', 'checktimeframe', $marc);
                if ((ModUtil::apiFunc('IWbookings', 'user', 'checktimeframe', $marc) < 2)) {
                    LogUtil::registerError($this->__('No hi ha franges'));
                }
            }

            //Per si falla la c�rrega de les dades
            if ($nom == false) {
                LogUtil::registerError($this->__('The room or equipment was not found'));
                return System::redirect(ModUtil::url('IWbookings', 'user', 'main'));
            }
        } else {
            $nom['space_name'] = $this->__('All rooms and equipments');
        }

        // Get date difference in days to limit backtracking
        $diff = DateUtil::getDatetimeDiff($currentDate, DateUtil::getDatetime());

        // Weeks before actual week are not allowed
        if ($diff['d'] > 0) {
            $currentDate = DateUtil::getDatetime();
        }

        if (!SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_ADMIN)) {
            // Weeks beyond num. weeks limit are not allowed
            $weekslimit = ModUtil::getVar('IWbookings', 'weeks');
            if (($weekslimit > 0 ) and ($diff['d'] < -7 * $weekslimit)) {
                $currentDate = DateUtil::getDatetime(DateUtil::makeTimestamp() + $weekslimit * 7 * 24 * 60 * 60, '%Y-%m-%d');
                LogUtil::registerError($this->__('Bookings can only be made for the following ') . $weekslimit . $this->__(' week(s). Booking date is not valid'));
            }
        }
        $canbook = SecurityUtil::checkPermission('IWbookings::', "::", ACCESS_ADD);

        if ($mensual) {
            $taula = ModUtil::func('IWbookings', 'user', 'monthlyview', array('sid' => $sid,
                        'mensual' => $mensual,
                        'm' => $inc,
                        'month' => $month,
                        'year' => $year));
        } else {
            $week = ModUtil::apiFunc('IWbookings', 'user', 'getWeek', array('date' => $currentDate,
                        'format' => 'dmy'));

            $jumpDates = ModUtil::apiFunc('IWbookings', 'user', 'getJumpDates', array('date' => $currentDate));
            if ($canbook) {
                //Creem el formulari per fer reserves temporals
                $formulari = ModUtil::func('IWbookings', 'user', 'formulari_assigna', array('sid' => $sid,
                            'dow' => $dow,
                            'cdate' => $currentDate,
                            'sot' => $showontop));
            } else {
                $formulari = '.';
            }
            //Creem la taula de l'estat de les reserves
            $taula = ModUtil::func('IWbookings', 'user', 'taula', array('sid' => $sid,
                        'currentDate' => $currentDate,
                        'bookingDate' => $date,
                        'mensual' => $mensual,
                        'canbook' => $canbook));
            // Creem el formulari per seleccionar la data
            $calendari = ModUtil::func('IWbookings', 'user', 'selectDate', array('sid' => $sid,
                        'date' => $currentDate,
                        'start' => $week['start'],
                        'end' => $week['end'],
//.........这里部分代码省略.........
开发者ID:projectesIF,项目名称:Sirius,代码行数:101,代码来源:User.php


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