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


PHP DateInterval::createFromDateString方法代码示例

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


在下文中一共展示了DateInterval::createFromDateString方法的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: getAppOnlineTime

 public function getAppOnlineTime($device_id, $apps, $days = 3)
 {
     if (!$apps) {
         return $apps;
     }
     $ids = [];
     foreach ($apps as $app) {
         $ids[] = $app->id;
     }
     $now = new \DateTime();
     $now->sub(\DateInterval::createFromDateString("{$days} days"));
     $where = ['status' => 'ACTIVE', 'downloads.create_date > ?' => $now->format('Y-m-d') . ' 00:00:00', "downloads.device_id" => $device_id];
     if ($ids) {
         $where['downloads.app_id in (' . substr(str_pad('', count($ids) * 2, ',?'), 1) . ')'] = $ids;
     }
     $downloads = $this->select('downloads.app_id')->from('downloads')->where($where)->groupBy('downloads.app_id')->result();
     $app_ids = [];
     foreach ($downloads as $download) {
         $app_ids[$download->app_id] = $download->app_id;
     }
     foreach ($apps as $app) {
         if (isset($app_ids[$app->id])) {
             $app->online_time = 0;
             $app->online_time_action = '0小时';
         }
     }
     return $apps;
 }
开发者ID:zhaoshengloveqingqing,项目名称:App-Download,代码行数:28,代码来源:DownloadModel.php

示例3: fetchURL

 private function fetchURL($forceRefresh)
 {
     $cachedFilePath = $this->cachingLocation + "/" + substr($URL, strrchr($URL, "/"));
     if (!$forceRefresh) {
         if (!file_exists($cachedFilePath)) {
             $content = file_get_contents($URL);
             file_put_contents($cachedFilePath, $content);
         } else {
             $cacheTTL = DateInterval::createFromDateString("15 minutes");
             $fetchingDelay = DateInterval::createFromDateString("5 minutes");
             $cacheAge = getdate(time() - filemtime($cachedFilePath));
             if ($cacheAge["minutes"] >= $cacheTTL) {
                 // Is cache expired
                 unlink($cachedFilePath);
                 // Just some housekeeping code, that may not be necessary
                 $content = file_get_contents($URL);
                 file_put_contents($cachedFilePath, $content);
                 return $content;
             } else {
                 return file_get_contents($cachedFilePath);
             }
         }
     } else {
         unlink($cachedFilePath);
         // Just some housekeeping code, that may not be necessary
         $content = file_get_contents($URL);
         file_put_contents($cachedFilePath, $content);
         return $content;
     }
 }
开发者ID:arthurmarkus2013,项目名称:Sample_Wrapper,代码行数:30,代码来源:wrapper.php

示例4: smarty_function_oauth_wechat

function smarty_function_oauth_wechat($params, $template)
{
    $label = lang('Wechat');
    $check = check_need_to_show('MicroMessenger');
    switch ($check) {
        case 0:
            return '';
            break;
        case 2:
            $label = lang('Let Me Online');
            break;
    }
    $type = 'wechat';
    $CI =& get_instance();
    $CI->load->model(array('login_model', 'user_social_app_model'));
    $args = $CI->login_model->getLoginArgs();
    if (isset($args->appid)) {
        $oauth_info = $CI->user_social_app_model->getSocialAppByType($args->appid, $type);
        if (isset($oauth_info->appid) && $oauth_info->appid) {
            unset($params['uri']);
            if ($check == 1 && isset($args->serial) && isset($args->gateway_ip) && isset($args->gateway_port) && isset($args->ip) && isset($args->mac)) {
                $CI->load->library('encryptor');
                $now = new DateTime();
                $expire = new DateTime();
                $expire->add(DateInterval::createFromDateString('5 minute'));
                $token = $CI->encryptor->encrypt(json_encode(array('uid' => 'activate', 'createDate' => $now->getTimestamp(), 'expireDate' => $expire->getTimestamp())));
                return anchor('http://' . $args->gateway_ip . ':' . $args->gateway_port . '/pinet/auth?token=' . urlencode($token) . '&url=' . urlencode('http://www.pinet.co/auth/tip'), $label, $params);
            }
            return anchor(site_url('oauth/session/' . $type . '/' . $args->appid), $label, $params);
        }
    }
    return '';
}
开发者ID:zhaoshengloveqingqing,项目名称:usercenter,代码行数:33,代码来源:function.oauth_wechat.php

示例5: authenticate

 /**
  * {@inheritdoc}
  */
 public function authenticate($key, $code, \DateTime $timestampToCheck = null)
 {
     $timestampToCheck = $timestampToCheck ?: new \DateTime();
     if ($this->blacklist->contains($key, $code)) {
         return false;
     }
     $timeStep = $this->generator->getTimeStep();
     $lookAroundSeconds = (int) ($this->lookAround * $timeStep);
     $interval = \DateInterval::createFromDateString($lookAroundSeconds . ' seconds');
     $start = clone $timestampToCheck;
     $start->sub($interval);
     $end = clone $timestampToCheck;
     $end->add($interval);
     $modification = '+ ' . $timeStep . ' seconds';
     for ($timestamp = $start; $timestamp <= $end; $timestamp->modify($modification)) {
         $generatedCode = $this->generator->generateCode($key, strlen($code), $timestamp);
         if ($generatedCode === $code) {
             $this->blacklist->add($key, $code);
             return true;
         }
         if (!$this->lookAround) {
             break;
         }
     }
     $this->blacklist->add($key, $code);
     return false;
 }
开发者ID:battlerattle,项目名称:doorman,代码行数:30,代码来源:TimeBasedAuthenticator.php

示例6: __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 = 'week';
     $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;
     //Week should start from sunday
     if ($this->start->format('w') != 0) {
         $this->start->modify('last sunday');
     }
     $this->prevInterval = new \DateInterval('P7D');
     //Each point
     $this->interval = '1 day';
     $this->end = clone $this->start;
     $this->end->add(new \DateInterval('P6D'));
     $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,代码行数:39,代码来源:ChartWeeklyIterator.php

示例7: __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 = 'month';
     $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;
     //Previous period is the previous month started from the the first day of the month
     $this->prevInterval = new \DateInterval('P1M');
     $this->interval = '1 day';
     $this->start = new DateTime($this->start->format('Y-m-01'), $this->timezone);
     $this->end = new DateTime($this->start->format('Y-m-t'), $this->timezone);
     $this->prevStart = clone $this->start;
     $this->prevStart->sub($this->prevInterval);
     $this->wholePeriodPerviousEnd = clone $this->prevStart;
     $this->wholePeriodPerviousEnd->modify('last day of this month');
     $this->determinePrevEnd();
     $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,代码行数:34,代码来源:ChartMonthlyIterator.php

示例8: getStatus

 /**
  * Returns the element's status.
  *
  * @return string|null
  */
 public function getStatus()
 {
     $currentTime = DateTimeHelper::currentTimeStamp();
     $startDate = $this->startDate ? $this->startDate->getTimestamp() : null;
     $endDate = $this->endDate ? $this->endDate->getTimestamp() : null;
     $pluginSettings = craft()->plugins->getPlugin('maintenance')->pluginSettings;
     $interval = $pluginSettings['maintenanceImminent'];
     $interval = DateInterval::createFromDateString($interval);
     $secondsInAdvance = (new DateTime('@0'))->add($interval)->getTimeStamp();
     if (!$startDate) {
         return static::NONE;
     }
     if (!$this->blockCp && !$this->blockSite) {
         return static::DISABLED;
     } else {
         if ($startDate > $currentTime) {
             if ($startDate > $currentTime + $secondsInAdvance) {
                 return static::PENDING;
             } else {
                 return static::IMMINENT;
             }
         } else {
             if ($startDate <= $currentTime && (!$endDate || $endDate > $currentTime)) {
                 return static::INPROGRESS;
             } else {
                 if ($startDate <= $currentTime) {
                     return static::COMPLETED;
                 }
             }
         }
     }
 }
开发者ID:carlcs,项目名称:craft-maintenance,代码行数:37,代码来源:Maintenance_AnnouncementModel.php

示例9: setHistory

 protected function setHistory($history = '-1 week')
 {
     $now = new \DateTime();
     $prev = new \DateTime();
     $prev->add(\DateInterval::createFromDateString($history));
     $this->date = array($now, $prev);
 }
开发者ID:svobodni,项目名称:web,代码行数:7,代码来源:BaseChartControl.php

示例10: ibox_status_summary

 public function ibox_status_summary()
 {
     $begin = null;
     $end = null;
     $mode = 'day';
     $beginTime = new DateTime();
     $beginTime->sub(DateInterval::createFromDateString('1 month'));
     $endTime = new DateTime();
     if (!isset($_POST['__nouse__'])) {
         $begin = $this->input->post('begin');
         $end = $this->input->post('end');
         $mode = $this->input->post('mode');
         switch ($mode) {
             case 'month':
                 $this->setState('month', 'status');
                 break;
             case 'week':
                 $this->setState('week', 'status');
                 break;
         }
         $beginTime = parse_datetime($begin, $beginTime);
         $endTime = parse_datetime($end, $endTime);
     }
     $heart_beat_rate = get_ci_config('heart_beat_rate');
     $diff = ($endTime->getTimestamp() - $beginTime->getTimestamp()) / 60 / $heart_beat_rate;
     $user_id = $this->user_model->getLoginUserID();
     $this->jquery_mousewheel();
     $this->less('business/ibox_status_summary_css');
     $this->render('business/ibox_status_summary', array('form_data' => $this->_buildSearches($begin, $end, $mode), 'args' => array($user_id), 'online_args' => array($heart_beat_rate, $diff, $user_id), 'begin' => $begin, 'end' => $end, 'mode' => $mode));
 }
开发者ID:zhaoshengloveqingqing,项目名称:Website,代码行数:30,代码来源:business.php

示例11: test_FiveMinResolutionSumTwoSeries_RollupSpace_ReturnSumForBothSeries

 public function test_FiveMinResolutionSumTwoSeries_RollupSpace_ReturnSumForBothSeries()
 {
     $value1 = 10;
     $value2 = 20;
     $nDays = 20;
     $aggregation = Aggregation::SUM;
     $start = new DateTIme('2015-10-10 00:00:00');
     $end = clone $start;
     $end->add(DateInterval::createFromDateString($nDays . ' days'));
     $dateperiod = new DatePeriod($start, DateInterval::createFromDateString('5 minutes'), $end);
     $vals1 = [];
     $vals2 = [];
     $expected = [];
     foreach ($dateperiod as $datetime) {
         $vals1[$datetime->getTimestamp()] = $value1;
         $vals2[$datetime->getTimestamp()] = $value2;
         $expected[$datetime->format('Y-m-d H:i:s')] = $value1 + $value2;
     }
     $series1 = new Series($vals1);
     $series2 = new Series($vals2);
     $convert = new ConvertToDateStringKeys();
     $action = new RollupSpace($aggregation);
     $output = $action->run([$series1, $series2]);
     $output = $convert->run($output);
     $this->assertEquals($expected, $output);
 }
开发者ID:magnusjt,项目名称:mongotd,代码行数:26,代码来源:RollupSpaceTest.php

示例12: test_FiveMinResolutionDailySum_RollupTime_ReturnSumForEachDay

 public function test_FiveMinResolutionDailySum_RollupTime_ReturnSumForEachDay()
 {
     $value = 1;
     $nDays = 20;
     $resolution = Resolution::DAY;
     $aggregation = Aggregation::SUM;
     $start = new DateTIme('2015-10-10 00:00:00');
     $end = clone $start;
     $end->add(DateInterval::createFromDateString($nDays . ' days'));
     $dateperiodExpected = new DatePeriod($start, DateInterval::createFromDateString('1 day'), $end);
     $expected = [];
     foreach ($dateperiodExpected as $datetime) {
         $expected[$datetime->format('Y-m-d H:i:s')] = $value * (86400 / $resolution);
     }
     $dateperiod = new DatePeriod($start, DateInterval::createFromDateString($resolution . ' seconds'), $end);
     $valsByTimestamp = [];
     foreach ($dateperiod as $datetime) {
         $valsByTimestamp[$datetime->getTimestamp()] = $value;
     }
     $series = new Series($valsByTimestamp);
     $convert = new ConvertToDateStringKeys();
     $action = new RollupTime($resolution, $aggregation);
     $output = $action->run($series);
     $output = $convert->run($output);
     $this->assertEquals($expected, $output);
 }
开发者ID:magnusjt,项目名称:mongotd,代码行数:26,代码来源:RollupTimeTest.php

示例13: a

function a(DateTime $start, DateTime $end)
{
    $interval = DateInterval::createFromDateString('1 day');
    $period = new DatePeriod($start, $interval, 1);
    $period = new DatePeriod($start, $interval, $end);
    $period = new DatePeriod('P1D');
}
开发者ID:etsy,项目名称:phan,代码行数:7,代码来源:0235_internal_args_required.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: createFromDateString

 /**
  * @param string $time
  * @return \DateInterval
  */
 public static function createFromDateString($time)
 {
     $interval = parent::createFromDateString($time);
     $interval->u = 0;
     // should be implemented
     return $interval;
 }
开发者ID:alexpts,项目名称:dtms,代码行数:11,代码来源:DateInterval.php


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