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


PHP DateInterval类代码示例

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


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

示例1: __construct

 /**
  * Constructor
  *
  * @param   string       $start     The start date of the period 'YYYY-mm-dd'
  * @param   string       $end       optional End date
  * @param   string       $timezone  optional Timezone
  * @throws  \InvalidArgumentException
  */
 public function __construct($start, $end = null, $timezone = 'UTC')
 {
     $this->mode = 'day';
     $this->timezone = new DateTimeZone($timezone);
     $this->today = $this->getTodayDate();
     $this->start = new DateTime($start instanceof DateTime ? $start->format('Y-m-d 00:00:00') : $start, $this->timezone);
     $this->end = !empty($end) ? new DateTime($end instanceof DateTime ? $end->format('Y-m-d 00:00:00') : $end, $this->timezone) : null;
     //Difference in days between Start and End dates
     $diffdays = $this->start->diff($this->end, true)->days;
     //Difference in days between Start and Today dates
     $diffTodayDays = $this->start->diff($this->today, true)->days;
     //Previous interval is the same period in the past
     $this->prevInterval = new \DateInterval('P' . ($diffdays + 1) . 'D');
     if ($diffdays < 2 && $diffTodayDays < 14) {
         $this->interval = '1 hour';
     } else {
         $this->interval = '1 day';
     }
     $this->prevStart = clone $this->start;
     $this->prevStart->sub($this->prevInterval);
     $this->wholePeriodPerviousEnd = clone $this->start;
     $this->wholePeriodPerviousEnd->modify('-1 day');
     $this->prevEnd = clone $this->prevStart;
     $this->prevEnd->add(new \DateInterval('P' . $this->start->diff(min($this->end, $this->today), true)->days . 'D'));
     $endoftheday = new \DateInterval('PT23H59M59S');
     $this->end->add($endoftheday);
     $this->prevEnd->add($endoftheday);
     $this->wholePeriodPerviousEnd->add($endoftheday);
     if (!$this->di) {
         $this->di = \DateInterval::createFromDateString($this->interval);
     }
     $this->dt = clone $this->start;
 }
开发者ID:mheydt,项目名称:scalr,代码行数:41,代码来源:ChartDailyIterator.php

示例2: testIsGreaterThanOrEqualTo

 public function testIsGreaterThanOrEqualTo()
 {
     $this->given($asserter = $this->newTestedInstance)->then->exception(function () use($asserter) {
         $asserter->isGreaterThanOrEqualTo(new \DateInterval('P1D'));
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Interval is undefined')->if($asserter->setWith(new \DateInterval('P1Y')))->then->object($asserter->isGreaterThanOrEqualTo(new \DateInterval('P1M')))->isIdenticalTo($asserter)->exception(function () use($asserter, &$interval) {
         $asserter->isGreaterThanOrEqualTo($interval = new \DateInterval('P2Y'));
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage('Interval ' . $asserter . ' is not greater than or equal to ' . $interval->format('%Y/%M/%D %H:%I:%S'));
 }
开发者ID:xihewang,项目名称:atoum,代码行数:8,代码来源:dateInterval.php

示例3: transform

 /**
  * Transforms a DateInterval object into a date string with the configured format.
  *
  * @param \DateInterval $value A DateInterval object
  *
  * @return string An ISO 8601 or relative date string like date interval presentation
  *
  * @throws UnexpectedTypeException If the given value is not a \DateInterval instance.
  */
 public function transform($value)
 {
     if (null === $value) {
         return '';
     }
     if (!$value instanceof \DateInterval) {
         throw new UnexpectedTypeException($value, '\\DateInterval');
     }
     return $value->format($this->format);
 }
开发者ID:unexge,项目名称:symfony,代码行数:19,代码来源:DateIntervalToStringTransformer.php

示例4: setDuration

 /**
  * {@inheritdoc}
  */
 public function setDuration(\DateInterval $duration, $notify = TRUE)
 {
     // Generate an ISO 8601 formatted string as supported by
     // DateInterval::__construct() and setValue().
     $this->value = $duration->format('%rP%yY%mM%dDT%hH%mM%sS');
     // Notify the parent of any changes.
     if ($notify && isset($this->parent)) {
         $this->parent->onChange($this->name);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:DurationIso8601.php

示例5: format

 /**
  * @param \DateInterval $interval
  * @return string
  */
 public static function format(\DateInterval $interval)
 {
     $string = $interval->format('%I:%S');
     if ($interval->h > 0) {
         $string = $interval->format('%H:') . $string;
     }
     if ($interval->d > 0) {
         $string = $interval->format('%D:') . $string;
     }
     return $string;
 }
开发者ID:stil,项目名称:phoebe,代码行数:15,代码来源:TimeDuration.php

示例6: getDefaultLength

 public function getDefaultLength()
 {
     $dateString = $this->webstream->getDbLength();
     $arr = explode(":", $dateString);
     if (count($arr) == 3) {
         list($hours, $min, $sec) = $arr;
         $di = new DateInterval("PT{$hours}H{$min}M{$sec}S");
         return $di->format("%Hh %Im");
     }
     return "";
 }
开发者ID:nidzix,项目名称:Airtime,代码行数:11,代码来源:Webstream.php

示例7: run

 public function run()
 {
     // TODO initialize formatter settings at begin of request from user settings
     Yii::$app->formatter->timeZone = 'Europe/Berlin';
     $now = $this->getTimeComponent()->getStartTime();
     $end = clone $now;
     $end->add($this->duration);
     // TODO introduce constant for DateInterval format
     $strDuration = $this->duration->format('%H:%I:%S');
     $strEnd = Yii::$app->formatter->asDatetime($end);
     return "<div>Duration: {$strDuration}, until: {$strEnd}</div>";
 }
开发者ID:iw-reload,项目名称:iw,代码行数:12,代码来源:DurationWidget.php

示例8: index

 public function index()
 {
     /** @var WP_Locale $wp_locale */
     global $wp_locale;
     $this->enqueueStyles(array('frontend' => array('css/intlTelInput.css'), 'module' => array('css/calendar.css', 'css/fullcalendar.min.css'), 'backend' => array('css/chosen.min.css', 'css/jquery-ui-theme/jquery-ui.min.css', 'css/bookly.main-backend.css', 'bootstrap/css/bootstrap.min.css')));
     $this->enqueueScripts(array('backend' => array('js/angular-1.3.11.min.js' => array('jquery'), 'js/angular-ui-date-0.0.7.js' => array('ab-angular-1.3.11.min.js'), 'js/ng-new_customer_dialog.js' => array('ab-angular-1.3.11.min.js'), 'js/moment.min.js' => array('jquery'), 'bootstrap/js/bootstrap.min.js' => array('jquery'), 'js/chosen.jquery.min.js' => array('jquery')), 'module' => array('js/ng-app.js' => array('ab-angular-ui-date-0.0.7.js', 'jquery-ui-datepicker', 'jquery-ui-widget', 'jquery-ui-dialog'), 'js/fullcalendar.min.js' => array('ab-moment.min.js'), 'js/fc-multistaff-view.js' => array('ab-fullcalendar.min.js'), 'js/calendar.js' => array('ab-fc-multistaff-view.js', 'ab-intlTelInput.min.js')), 'frontend' => array('js/intlTelInput.min.js' => array('jquery'))));
     $slot_length_minutes = get_option('ab_settings_time_slot_length', '15');
     $slot = new DateInterval('PT' . $slot_length_minutes . 'M');
     $this->staff_members = AB_Utils::isCurrentUserAdmin() ? AB_Staff::query()->sortBy('position')->find() : AB_Staff::query()->where('wp_user_id', get_current_user_id())->find();
     wp_localize_script('ab-calendar.js', 'BooklyL10n', array('slotDuration' => $slot->format('%H:%I:%S'), 'shortMonths' => array_values($wp_locale->month_abbrev), 'longMonths' => array_values($wp_locale->month), 'shortDays' => array_values($wp_locale->weekday_abbrev), 'longDays' => array_values($wp_locale->weekday), 'AM' => $wp_locale->meridiem['AM'], 'PM' => $wp_locale->meridiem['PM'], 'dpDateFormat' => AB_DateTimeUtils::convertFormat('date', AB_DateTimeUtils::FORMAT_JQUERY_DATEPICKER), 'mjsDateFormat' => AB_DateTimeUtils::convertFormat('date', AB_DateTimeUtils::FORMAT_MOMENT_JS), 'mjsTimeFormat' => AB_DateTimeUtils::convertFormat('time', AB_DateTimeUtils::FORMAT_MOMENT_JS), 'today' => __('Today', 'bookly'), 'week' => __('Week', 'bookly'), 'day' => __('Day', 'bookly'), 'month' => __('Month', 'bookly'), 'allDay' => __('All Day', 'bookly'), 'noStaffSelected' => __('No staff selected', 'bookly'), 'newAppointment' => __('New appointment', 'bookly'), 'editAppointment' => __('Edit appointment', 'bookly'), 'are_you_sure' => __('Are you sure?', 'bookly'), 'startOfWeek' => (int) get_option('start_of_week'), 'country' => get_option('ab_settings_phone_default_country'), 'intlTelInput_utils' => plugins_url('intlTelInput.utils.js', AB_PATH . '/frontend/resources/js/intlTelInput.utils.js')));
     $this->render('calendar');
 }
开发者ID:patrickcurl,项目名称:monks,代码行数:12,代码来源:AB_CalendarController.php

示例9: format

 /**
  * Format a date (or interval) to a string with a given format
  *
  * See formatting options as in PHP date()
  *
  * @param integer|string|\DateTime|\DateInterval $date
  * @param string $format
  * @return string
  */
 public function format($date, $format)
 {
     if ($date instanceof \DateTimeInterface) {
         return $date->format($format);
     } elseif ($date instanceof \DateInterval) {
         return $date->format($format);
     } elseif ($date === 'now') {
         return date($format);
     } else {
         $timestamp = (int) $date;
         return date($format, $timestamp);
     }
 }
开发者ID:neos,项目名称:flow-development-collection,代码行数:22,代码来源:DateHelper.php

示例10: getCacheDuration

 /**
  * Get the time things should be cached for in seconds.
  *
  * @return int
  */
 public function getCacheDuration()
 {
     if (!isset($this->_cacheDuration)) {
         $duration = $this->get('cacheDuration');
         if ($duration) {
             $interval = new DateInterval($duration);
             $this->_cacheDuration = $interval->toSeconds();
         } else {
             $this->_cacheDuration = 0;
         }
     }
     return $this->_cacheDuration;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:18,代码来源:ConfigService.php

示例11: getDuration

 /**
  *
  * Return duration in seconds
  *
  * @return int, duration in seconds
  */
 public function getDuration()
 {
     $this->initialRequest();
     if (isset($this->item['contentDetails']['duration'])) {
         $date = new \DateInterval($this->item['contentDetails']['duration']);
         $ret = 0;
         $ret += (int) $date->format('%d') * 86400;
         $ret += (int) $date->format('%h') * 3600;
         $ret += (int) $date->format('%i') * 60;
         $ret += (int) $date->format('%s');
         return $ret;
     } else {
         $this->onApiBadInterpretation("contentDetails.duration not found");
     }
 }
开发者ID:lingtalfi,项目名称:YouTubeUtils,代码行数:21,代码来源:YouTubeVideo.php

示例12: prepareDateInterval

 /**
  * Subtract given interval from current date time
  *
  * @param string $intervalString
  *
  * @return \DateTime
  */
 protected function prepareDateInterval($intervalString = null)
 {
     $date = new \DateTime('now', new \DateTimeZone('UTC'));
     $intervalString = $intervalString ?: $this->getContainer()->getParameter('oro_batch.cleanup_interval');
     $date->sub(\DateInterval::createFromDateString($intervalString));
     return $date;
 }
开发者ID:Maksold,项目名称:platform,代码行数:14,代码来源:CleanupCommand.php

示例13: createDateString

 static function createDateString($dateString = 'yesterday')
 {
     global $gTimezone;
     $date = new \DateTime('now', new \DateTimeZone($gTimezone));
     $date->add(\DateInterval::createFromDateString($dateString));
     return $date->format('Ymd');
 }
开发者ID:nobelprize-org,项目名称:top-laureates,代码行数:7,代码来源:wikipedia-stats.php

示例14: isPassed

 /**
  * Check if the time limit is up
  *
  * @param  DateTime $started Start time
  *
  * @return boolean True if the time limit is up
  */
 public function isPassed(\DateTime $started)
 {
     // Create a new datetime to now, subtract the limit from it and see if its less than started
     $now = new \DateTime();
     $now->sub(\DateInterval::createFromDateString(sprintf('%d seconds', $this->timeLimit)));
     return $now >= $started;
 }
开发者ID:tyhand,项目名称:workflow-bundle,代码行数:14,代码来源:TimeLimit.php

示例15: showWeek

 /**
  * Generate the view of the week for given month and given year
  * with events in this period.
  *
  * @param string $year
  * @param string $week 
  * @return view weekView
  *
  *
  */
 public function showWeek($year, $week)
 {
     // Create week start date on monday (day 1)
     $weekStart = date('Y-m-d', strtotime($year . "W" . $week . '1'));
     // Create the number of the next week
     $nextWeek = date("W", strtotime("next Week" . $weekStart));
     $nextYear = date("Y", strtotime("next Week" . $weekStart));
     // Create week end date - we go till tuesday (day 2) because café needs alternative week view (Mi-Di)
     $weekEnd = date('Y-m-d', strtotime($nextYear . "W" . $nextWeek . '2'));
     // Create the number of the previous week
     $previousWeek = date("W", strtotime("previous Week" . $weekStart));
     $previousYear = date("Y", strtotime("previous Week" . $weekStart));
     // Convert number of prev/next week to verbatim format - needed for correct << and >> button links
     $nextWeek = $nextYear . "/KW" . $nextWeek;
     $previousWeek = $previousYear . "/KW" . $previousWeek;
     $date = array('year' => $year, 'week' => $week, 'weekStart' => $weekStart, 'weekEnd' => $weekEnd, 'nextWeek' => $nextWeek, 'previousWeek' => $previousWeek);
     $events = ClubEvent::where('evnt_date_start', '>=', $weekStart)->where('evnt_date_start', '<=', $weekEnd)->with('getPlace', 'getSchedule.getEntries.getJobType', 'getSchedule.getEntries.getPerson.getClub')->orderBy('evnt_date_start')->orderBy('evnt_time_start')->get();
     $tasks = Schedule::where('schdl_show_in_week_view', '=', '1')->where('schdl_due_date', '>=', $weekStart)->where('schdl_due_date', '<=', $weekEnd)->with('getEntries.getPerson.getClub', 'getEntries.getJobType')->get();
     // TODO: don't use raw query, rewrite with eloquent.
     $persons = Cache::remember('personsForDropDown', 10, function () {
         $timeSpan = new DateTime("now");
         $timeSpan = $timeSpan->sub(DateInterval::createFromDateString('3 months'));
         return Person::whereRaw("prsn_ldap_id IS NOT NULL \n\t\t\t\t\t\t\t\t\t\t AND (prsn_status IN ('aktiv', 'kandidat') \n\t\t\t\t\t\t\t\t\t\t OR updated_at>='" . $timeSpan->format('Y-m-d H:i:s') . "')")->orderBy('clb_id')->orderBy('prsn_name')->get();
     });
     $clubs = Club::orderBy('clb_title')->lists('clb_title', 'id');
     // IDs of schedules shown, needed for bulk-update
     $updateIds = array();
     foreach ($events as $event) {
         array_push($updateIds, $event->getSchedule->id);
     }
     return View::make('weekView', compact('events', 'schedules', 'date', 'tasks', 'entries', 'weekStart', 'weekEnd', 'persons', 'clubs'));
 }
开发者ID:gitter-badger,项目名称:lara-vedst,代码行数:42,代码来源:WeekController.php


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