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


PHP Nette\DateTime类代码示例

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


在下文中一共展示了DateTime类的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: getValue

 /**
  * Returns date
  *
  * @return mixed
  */
 public function getValue()
 {
     if (strlen($this->value) > 0) {
         return DateTime::createFromFormat($this->format, $this->value);
     }
     return $this->value;
 }
开发者ID:WebArchivCZ,项目名称:WWW,代码行数:12,代码来源:DatePicker.php

示例3: validityCheck

 public function validityCheck($form)
 {
     $values = $form->getValues();
     if ($values->password != $values->password2) {
         $form->addError('Obě varianty hesla musí být stejné.');
     }
     $bdate = new \Nette\DateTime($values->birthdate);
     $diff = $bdate->diff(new \Nette\DateTime());
     $diff = $diff->format('%d');
     if ($diff < 7) {
         $form->addError('Uživatelé by měli být starší než jeden týden. ' . $diff . ' dní je příliš málo.');
     }
     $data = $this->model->getSelection()->where(array("email" => $values->email))->fetch();
     if ($data) {
         $form->addError('Email ' . $values->email . ' je již používán.');
     }
 }
开发者ID:hajek-raven,项目名称:agenda,代码行数:17,代码来源:RegistrationForm.php

示例4: getDefaultParser

 protected function getDefaultParser()
 {
     return function ($value) {
         if (!preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})([. -] *(?P<yyyy>\\d{4})?)?$#', $value, $matches)) {
             return NULL;
         }
         $dd = $matches['dd'];
         $mm = $matches['mm'];
         $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
         if (!checkdate($mm, $dd, $yyyy)) {
             return NULL;
         }
         $value = new Nette\DateTime();
         $value->setDate($yyyy, $mm, $dd);
         $value->setTime(0, 0, 0);
         return $value;
     };
 }
开发者ID:patrickkusebauch,项目名称:27skauti,代码行数:18,代码来源:DatePicker.php

示例5: 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

示例6: getDefaultParser

 protected function getDefaultParser()
 {
     return function ($value) {
         if (!preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})(?:[. -] *(?P<yyyy>\\d{4})?)?(?: *[ -@] *(?P<hh>\\d{1,2})[:.](?P<ii>\\d{1,2})(?:[:.](?P<ss>\\d{1,2}))?)?$#', $value, $matches)) {
             return NULL;
         }
         $dd = $matches['dd'];
         $mm = $matches['mm'];
         $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
         $hh = isset($matches['hh']) ? $matches['hh'] : 0;
         $ii = isset($matches['ii']) ? $matches['ii'] : 0;
         $ss = isset($matches['ss']) ? $matches['ss'] : 0;
         if (!($hh >= 0 && $hh < 24 && $ii >= 0 && $ii <= 59 && $ss >= 0 && $ss <= 59)) {
             $hh = $ii = $ss = 0;
         }
         if (!checkdate($mm, $dd, $yyyy)) {
             return NULL;
         }
         $value = new Nette\DateTime();
         $value->setDate($yyyy, $mm, $dd);
         $value->setTime($hh, $ii, $ss);
         return $value;
     };
 }
开发者ID:patrickkusebauch,项目名称:27skauti,代码行数:24,代码来源:DateTimePicker.php

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

示例8: 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

示例9: 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

示例10: 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 Response  provides a fluent interface
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     if (headers_sent($file, $line)) {
         throw new Nette\InvalidStateException("Cannot set cookie after HTTP headers have been sent" . ($file ? " (output started at {$file}:{$line})." : "."));
     }
     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);
     return $this;
 }
开发者ID:rostenkowski,项目名称:HttpPHPUnit,代码行数:20,代码来源:Response.php

示例11: date

 /**
  * Restricts the search by modified time.
  * @param  string  "[operator] [date]" example: >1978-01-23
  * @param  mixed
  * @return self
  */
 public function date($operator, $date = NULL)
 {
     if (func_num_args() === 1) {
         // in $operator is predicate
         if (!preg_match('#^(?:([=<>!]=?|<>)\\s*)?(.+)\\z#i', $operator, $matches)) {
             throw new Nette\InvalidArgumentException('Invalid date predicate format.');
         }
         list(, $operator, $date) = $matches;
         $operator = $operator ? $operator : '=';
     }
     $date = Nette\DateTime::from($date)->format('U');
     return $this->filter(function ($file) use($operator, $date) {
         return Finder::compare($file->getMTime(), $operator, $date);
     });
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:21,代码来源:Finder.php

示例12: completeDependencies

 private function completeDependencies($dp, $data)
 {
     if (is_object($data)) {
         $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkSerializationVersion'), get_class($data), Nette\Reflection\ClassType::from($data)->getAnnotation('serializationVersion'));
     }
     // convert expire into relative amount of seconds
     if (isset($dp[Cache::EXPIRATION])) {
         $dp[Cache::EXPIRATION] = Nette\DateTime::from($dp[Cache::EXPIRATION])->format('U') - time();
     }
     // convert FILES into CALLBACKS
     if (isset($dp[self::FILES])) {
         //clearstatcache();
         foreach (array_unique((array) $dp[self::FILES]) as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkFile'), $item, @filemtime($item));
             // @ - stat may fail
         }
         unset($dp[self::FILES]);
     }
     // add namespaces to items
     if (isset($dp[self::ITEMS])) {
         $dp[self::ITEMS] = array_unique(array_map(array($this, 'generateKey'), (array) $dp[self::ITEMS]));
     }
     // convert CONSTS into CALLBACKS
     if (isset($dp[self::CONSTS])) {
         foreach (array_unique((array) $dp[self::CONSTS]) as $item) {
             $dp[self::CALLBACKS][] = array(array(__CLASS__, 'checkConst'), $item, constant($item));
         }
         unset($dp[self::CONSTS]);
     }
     if (!is_array($dp)) {
         $dp = array();
     }
     return $dp;
 }
开发者ID:beejhuff,项目名称:PHP-Security,代码行数:34,代码来源:Cache.php

示例13: date

 /**
  * Date/time formatting.
  * @param  string|int|DateTime
  * @param  string
  * @return string
  */
 public static function date($time, $format = NULL)
 {
     if ($time == NULL) {
         // intentionally ==
         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);
     // formats using date()
 }
开发者ID:BroukPytlik,项目名称:agility,代码行数:19,代码来源:Helpers.php

示例14: 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)
 {
     if (!headers_sent() && ob_get_level() && ob_get_length()) {
         trigger_error("Possible problem: you are sending a cookie while already having some data in output buffer.  This may not work if the outputted data grows. Try starting the session earlier.", E_USER_NOTICE);
     }
     if (headers_sent($file, $line)) {
         throw new Nette\InvalidStateException("Cannot set cookie after HTTP headers have been sent" . ($file ? " (output started at {$file}:{$line})." : "."));
     }
     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:jurasm2,项目名称:nette,代码行数:24,代码来源:Response.php

示例15: addPaymentForeing

 /**
  *
  * @param float $amount
  * @param string $iban
  * @param string $bic
  * @param string $benefName
  * @param string $benefCountry
  * @throws FioException
  */
 public function addPaymentForeing($amount, $iban, $bic, $benefName, $benefCountry)
 {
     if ($this->content) {
         $this->createEmptyXml();
     }
     if (strlen($bic) != 11) {
         throw new FioException('BIC must lenght 11. Is ISO 9362.');
     }
     if (strlen($benefCountry) != 2 && $benefCountry != 'TCH') {
         throw new FioException('Country code consists of two letters.');
     }
     $this->xml->startElement('T2Transaction');
     $this->xmlContent($amount, $iban);
     $this->addXmlNode('bic', $bic, TRUE);
     $this->addXmlNode('date', DateTime::from($this->date)->format('Y-m-d'));
     $this->addXmlNode('comment', $this->comment);
     $this->addXmlNode('benefName', $benefName, TRUE);
     $this->addXmlNode('benefStreet', $this->benefStreet);
     $this->addXmlNode('benefCity', $this->benefCity);
     $this->addXmlNode('benefCountry', strtoupper($benefCountry), TRUE);
     $this->addXmlNode('remittanceInfo1', $this->remittanceInfo1);
     $this->addXmlNode('remittanceInfo2', $this->remittanceInfo2);
     $this->addXmlNode('remittanceInfo3', $this->remittanceInfo3);
     $this->addXmlNode('paymentReason', $this->paymentReason, FALSE);
     $this->addXmlNode('paymentType', $this->paymentTypeEuro, self::PAYMENT_STANDARD_EURO);
     $this->xml->endElement();
 }
开发者ID:svobodni,项目名称:web,代码行数:36,代码来源:XMLFio.php


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