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


PHP DateTime::from方法代码示例

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


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

示例1: filter

 /**
  * @param $value
  * @param $dataSource
  * @return mixed
  */
 public function filter($value, IDataSource $dataSource)
 {
     $value = strtotime($value);
     $begin = strtotime('today', $value);
     $end = strtotime('+1 day', $begin);
     $dataSource->filter(['%n BETWEEN %s AND %s', $this->column->getColumn(), DateTime::from($begin), DateTime::from($end)]);
 }
开发者ID:peterzadori,项目名称:movi,代码行数:12,代码来源:Date.php

示例2: setValue

 public function setValue($value)
 {
     if ($value) {
         $date = DateTime::from($value);
         $this->day = $date->format('j');
         $this->month = $date->format('n');
         $this->year = $date->format('Y');
     } else {
         $this->day = $this->month = $this->year = NULL;
     }
 }
开发者ID:jirinapravnik,项目名称:common,代码行数:11,代码来源:DateInput.php

示例3: updateCache

 /**
  * Parses the txt file and updates the cache files
  *
  * @return bool whether the file was correctly written to the disk
  */
 public function updateCache($force = FALSE)
 {
     if (($this->_registry = $this->load(Registry::REGISTRY)) !== NULL) {
         $cver = $this->load(Registry::ETAG);
         $this->getRemoteData($cver);
         if ($cver == $this->_etag && $this->load(Registry::MD5) == md5($this->_sourceData) && !$force) {
             return TRUE;
         }
     }
     $this->getRemoteData();
     $this->raw2csv();
     $this->csv2registry();
     // Save and return
     $expiration = \Nette\DateTime::from(time())->add(new \DateInterval('P2W'));
     $dependencies = [Caching\Cache::CONSTS => ['Nette\\Framework::REVISION'], Caching\Cache::EXPIRATION => $expiration];
     $this->save(Registry::SOURCE, $this->sourceUrl, $dependencies);
     $this->save(Registry::DATA, $this->_sourceData, $dependencies);
     $this->save(Registry::ETAG, $this->_etag, $dependencies);
     $this->save(Registry::MD5, md5($this->_sourceData), $dependencies);
     $this->save(Registry::REGISTRY, $this->_registry, $dependencies);
     $this->release();
 }
开发者ID:lohini,项目名称:cf,代码行数:27,代码来源:Registry.php

示例4: fromActiveRow

 /**
  * Creates Addon entity from Nette\Database row.
  *
  * @todo   Consider lazy loading for versions and tags.
  *
  * @param \Nette\Database\Table\ActiveRow
  * @param AddonVotes
  * @return Addon
  */
 public static function fromActiveRow(ActiveRow $row, AddonVotes $addonVotes = NULL)
 {
     $addon = new static();
     $addon->id = (int) $row->id;
     $addon->name = $row->name;
     $addon->composerVendor = $row->composerVendor;
     $addon->composerName = $row->composerName;
     $addon->userId = (int) $row->user->id;
     $addon->shortDescription = $row->shortDescription;
     $addon->description = $row->description;
     $addon->descriptionFormat = $row->descriptionFormat;
     $addon->defaultLicense = $row->defaultLicense;
     $addon->repository = $row->repository;
     $addon->repositoryHosting = $row->repositoryHosting;
     $addon->demo = $row->demo;
     $addon->updatedAt = $row->updatedAt ? DateTime::from($row->updatedAt) : NULL;
     $addon->deletedAt = $row->deletedAt;
     $addon->deletedBy = $row->ref('deletedBy');
     $addon->type = $row->type;
     $addon->stars = $row->stars;
     foreach ($row->related('versions') as $versionRow) {
         $version = AddonVersion::fromActiveRow($versionRow);
         $version->addon = $addon;
         $addon->versions[$version->version] = $version;
     }
     foreach ($row->related('tags') as $tagRow) {
         $addon->tags[$tagRow->tag->id] = Tag::fromActiveRow($tagRow->tag);
     }
     foreach ($row->related('addons_resources') as $resourceRow) {
         $addon->resources[$resourceRow->type] = $resourceRow->resource;
     }
     if ($addonVotes) {
         $addon->votes = $addonVotes->calculatePopularity($row);
     }
     return $addon;
 }
开发者ID:newPOPE,项目名称:web-addons.nette.org,代码行数:45,代码来源:Addon.php

示例5: setValue

 function setValue($value)
 {
     if ($value instanceof DateTime) {
     } elseif (is_int($value)) {
     } elseif (empty($value)) {
         $rawValue = $value;
         $value = NULL;
     } elseif (is_string($value)) {
         $rawValue = $value;
         if (preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})([. -] *(?P<yyyy>\\d{4})?)?$#', $value, $matches)) {
             $dd = $matches['dd'];
             $mm = $matches['mm'];
             $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
             if (checkdate($mm, $dd, $yyyy)) {
                 $value = "{$yyyy}-{$mm}-{$dd}";
             } else {
                 $value = NULL;
             }
         }
     } else {
         throw new \InvalidArgumentException();
     }
     if ($value !== NULL) {
         try {
             $value = Nette\DateTime::from($value);
         } catch (\Exception $e) {
             $value = NULL;
         }
     }
     if (!isset($rawValue) && isset($value)) {
         $rawValue = $value->format(self::W3C_DATE_FORMAT);
     }
     $this->value = $value;
     $this->rawValue = $rawValue;
     return $this;
 }
开发者ID:BroukPytlik,项目名称:agility,代码行数:36,代码来源:DatePicker.php

示例6: datetime

 /**
  * @param string|int|\DateTime $time
  * @param string $format
  * @return string
  */
 public static function datetime($time, $format = NULL)
 {
     if ($time == NULL) {
         // intentionally ==
         return NULL;
     }
     return date($format ?: self::$datetimeFormat, \Nette\DateTime::from($time)->format('U'));
 }
开发者ID:lohini,项目名称:framework,代码行数:13,代码来源:Filters.php

示例7: setExpiration

 /**
  * Sets the amount of time allowed between requests before the session will be terminated.
  * @param  string|int|DateTime  time, value 0 means "until the browser is closed"
  * @return self
  */
 public function setExpiration($time)
 {
     if (empty($time)) {
         return $this->setOptions(array('gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME, 'cookie_lifetime' => 0));
     } else {
         $time = Nette\DateTime::from($time)->format('U') - time();
         return $this->setOptions(array('gc_maxlifetime' => $time, 'cookie_lifetime' => $time));
     }
 }
开发者ID:genextwebs,项目名称:dropbox-sample,代码行数:14,代码来源:Session.php

示例8: normalizeRow

 /**
  * Normalizes result row.
  * @param  array
  * @return array
  */
 public function normalizeRow($row)
 {
     if ($this->types === NULL) {
         $this->types = (array) $this->supplementalDriver->getColumnTypes($this->pdoStatement);
     }
     foreach ($this->types as $key => $type) {
         $value = $row[$key];
         if ($value === NULL || $value === FALSE || $type === IReflection::FIELD_TEXT) {
         } elseif ($type === IReflection::FIELD_INTEGER) {
             $row[$key] = is_float($tmp = $value * 1) ? $value : $tmp;
         } elseif ($type === IReflection::FIELD_FLOAT) {
             if (($pos = strpos($value, '.')) !== FALSE) {
                 $value = rtrim(rtrim($pos === 0 ? "0{$value}" : $value, '0'), '.');
             }
             $float = (double) $value;
             $row[$key] = (string) $float === $value ? $float : $value;
         } elseif ($type === IReflection::FIELD_BOOL) {
             $row[$key] = (bool) $value && $value !== 'f' && $value !== 'F';
         } elseif ($type === IReflection::FIELD_DATETIME || $type === IReflection::FIELD_DATE || $type === IReflection::FIELD_TIME) {
             $row[$key] = new Nette\DateTime($value);
         } elseif ($type === IReflection::FIELD_TIME_INTERVAL) {
             preg_match('#^(-?)(\\d+)\\D(\\d+)\\D(\\d+)\\z#', $value, $m);
             $row[$key] = new \DateInterval("PT{$m['2']}H{$m['3']}M{$m['4']}S");
             $row[$key]->invert = (int) (bool) $m[1];
         } elseif ($type === IReflection::FIELD_UNIX_TIMESTAMP) {
             $row[$key] = Nette\DateTime::from($value);
         }
     }
     return $this->supplementalDriver->normalizeRow($row);
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:35,代码来源:ResultSet.php

示例9: setExpiration

 /**
  * Sets the expiration of the section or specific variables.
  * @param  string|int|DateTime  time, value 0 means "until the browser is closed"
  * @param  mixed   optional list of variables / single variable to expire
  * @return SessionSection  provides a fluent interface
  */
 public function setExpiration($time, $variables = NULL)
 {
     $this->start();
     if (empty($time)) {
         $time = NULL;
         $whenBrowserIsClosed = TRUE;
     } else {
         $time = Nette\DateTime::from($time)->format('U');
         $max = ini_get('session.gc_maxlifetime');
         if ($time - time() > $max + 3) {
             // bulgarian constant
             trigger_error("The expiration time is greater than the session expiration {$max} seconds", E_USER_NOTICE);
         }
         $whenBrowserIsClosed = FALSE;
     }
     if ($variables === NULL) {
         // to entire section
         $this->meta['']['T'] = $time;
         $this->meta['']['B'] = $whenBrowserIsClosed;
     } elseif (is_array($variables)) {
         // to variables
         foreach ($variables as $variable) {
             $this->meta[$variable]['T'] = $time;
             $this->meta[$variable]['B'] = $whenBrowserIsClosed;
         }
     } else {
         // to variable
         $this->meta[$variables]['T'] = $time;
         $this->meta[$variables]['B'] = $whenBrowserIsClosed;
     }
     return $this;
 }
开发者ID:cujan,项目名称:atlas-mineralov-a-hornin,代码行数:38,代码来源:SessionSection.php

示例10: modifyDate

 /**
  * Date/time modification.
  * @param  string|int|DateTime
  * @param  string|int
  * @param  string
  * @return Nette\DateTime
  */
 public static function modifyDate($time, $delta, $unit = NULL)
 {
     return $time == NULL ? NULL : Nette\DateTime::from($time)->modify($delta . $unit);
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:11,代码来源:Helpers.php

示例11: setCookie

 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|DateTime  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @param  bool
  * @return self
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     self::checkHeaders();
     setcookie($name, $value, $time ? Nette\DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly);
     $this->removeDuplicateCookies();
     return $this;
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:19,代码来源:Response.php

示例12: getFiles

 protected function getFiles()
 {
     $ret = array();
     foreach (Finder::findFiles('exception*')->in($this->logDir) as $file) {
         $data = explode('-', $file->getFileName());
         $date = "{$data[1]}-{$data[2]}-{$data[3]} {$data[4]}:{$data[5]}:{$data[6]}";
         $info = array('date' => DateTime::from($date), 'hash' => $data[7], 'link' => $file->getFileName());
         $ret[$date] = $info;
     }
     ksort($ret);
     return array_reverse($ret);
 }
开发者ID:svobodni,项目名称:web,代码行数:12,代码来源:LogsPresenter.php

示例13: strtr

strtr($m[0]," \t\r\n","\x1F\x1E\x1D\x1A");});$s=Strings::indent($s,$level,$chars);$s=strtr($s,"\x1F\x1E\x1D\x1A"," \t\r\n");}return$s;}static
function
date($time,$format=NULL){if($time==NULL){return
NULL;}if(!isset($format)){$format=self::$dateFormat;}$time=Nette\DateTime::from($time);return
Strings::contains($format,'%')?strftime($format,$time->format('U')):$time->format($format);}static
开发者ID:JanTvrdik,项目名称:NetteExtras,代码行数:5,代码来源:loader.php

示例14: createInterval

 /**
  * @param  mixed
  * @return \DateInterval
  */
 private function createInterval($value)
 {
     $dt = class_exists('Nette\\Utils\\DateTime') ? Nette\Utils\DateTime::from($value) : Nette\DateTime::from($value);
     return (new \DateTime())->diff($dt);
 }
开发者ID:milo,项目名称:github-api-nette,代码行数:9,代码来源:Panel.php

示例15: setValue

 public function setValue($value)
 {
     if ($value) {
         if (is_string($value)) {
             $date = call_user_func($this->parseDateCallback, $this->phpMask, $value);
         } else {
             $date = Nette\DateTime::from($value);
         }
         if (!$date instanceof DateTime) {
             throw new InvalidArgumentException("Invalid input for calendar picker: '{$value}'");
         }
         $this->year = $date->format('Y');
         $this->month = $date->format('n');
         $this->day = $date->format('j');
         if ($this->useTime) {
             $this->hour = $date->format('G');
             $this->minute = (int) $date->format('i');
             $this->second = (int) $date->format('s');
         }
     } else {
         $this->year = $this->month = $this->day = NULL;
         if ($this->useTime) {
             $this->hour = $this->minute = $this->second = NULL;
         }
     }
 }
开发者ID:dotblue,项目名称:nette-calendarpicker,代码行数:26,代码来源:CalendarPicker.php


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