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


PHP DateTimeInterface类代码示例

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


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

示例1: findListDatesWithin

 /**
  * @param \DateTimeInterface $dateStart
  * @param \DateTimeInterface $dateEnd
  * @return \DateTime[]
  */
 public function findListDatesWithin(\DateTimeInterface $dateStart, \DateTimeInterface $dateEnd)
 {
     $yearStart = $dateStart->format('Y-m-d');
     $yearEnd = $dateEnd->format('Y-m-d');
     $dayStart = $dateStart->format('Y-m-d');
     $dayEnd = $dateEnd->format('Y-m-d');
     $qb = $this->createQueryBuilder('f')->where("f.annee >= :yearStart AND f.annee <= :yearEnd")->orderBy("f.annee");
     $qb->setParameter(':yearStart', $yearStart)->setParameter(':yearEnd', $yearEnd);
     $rows = $qb->getQuery()->getResult();
     if (is_null($rows)) {
         return array();
     }
     /**
      * @var \WCS\CantineBundle\Entity\Feries $dayOff
      */
     $result = [];
     foreach ($rows as $dayOff) {
         // the order is important !
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getJourAn', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getPaques', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getFeteTravail', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getHuitMai', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getAscension', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getVendrediAscension', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getPentecote', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getFeteNational', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getAssomption', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getToussaint', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getArmistice', $result);
         $this->pushDateIfWithin($dayStart, $dayEnd, $dayOff, 'getNoel', $result);
     }
     return $result;
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:38,代码来源:FeriesRepository.php

示例2: getSeconds

 /**
  * Calculate the number of seconds with the given delay.
  *
  * @param int|\DateTimeInterface $delay
  *
  * @return int
  */
 protected function getSeconds($delay) : int
 {
     if ($delay instanceof DateTimeInterface) {
         return max(0, $delay->getTimestamp() - $this->getTime());
     }
     return (int) $delay;
 }
开发者ID:narrowspark,项目名称:framework,代码行数:14,代码来源:AbstractQueue.php

示例3: serializeDateTimeImmutable

 public function serializeDateTimeImmutable(VisitorInterface $visitor, \DateTimeInterface $date, array $type, Context $context)
 {
     if ($visitor instanceof XmlSerializationVisitor && false === $this->xmlCData) {
         return $visitor->visitSimpleString($date->format($this->getFormat($type)), $type, $context);
     }
     return $visitor->visitString($date->format($this->getFormat($type)), $type, $context);
 }
开发者ID:hellofresh,项目名称:engine,代码行数:7,代码来源:DateTimeImmutableHandler.php

示例4: getDate

 protected function getDate(\DateTimeInterface $date = null)
 {
     if ($date === null) {
         return str_repeat('0', 8);
     }
     return $date->format('dmY');
 }
开发者ID:forward-hkg,项目名称:tikon-generator,代码行数:7,代码来源:TikonGenerator.php

示例5: getQueryEleveIdsInscritsVoyage

 /**
  * renvoit la requete suivante :
  * tous les ids des eleves INSCRITS en voyage scolaire (non annulée)
  * à la date donnée
  *
  * @param \DateTimeInterface $date_day
  *
  * @return QueryBuilder
  */
 protected function getQueryEleveIdsInscritsVoyage(\DateTimeInterface $date_day)
 {
     $query = $this->getEntityManager()->createQueryBuilder()->select('DISTINCT eleve_inscrit.id')->from('WCSCantineBundle:Eleve', 'eleve_inscrit')->join('eleve_inscrit.voyages', 'voyage_scolaire')->where('voyage_scolaire.estAnnule = FALSE')->andWhere(':date_day BETWEEN 
                     DATE(voyage_scolaire.date_debut) 
                     AND 
                     DATE(voyage_scolaire.date_fin)')->setParameter(':date_day', $date_day->format('Y-m-d'));
     return $query;
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:17,代码来源:ActivityRepositoryAbstract.php

示例6: setDueDate

 public function setDueDate(\DateTimeInterface $dueDate = NULL)
 {
     if ($dueDate === NULL) {
         $this->dueDate = NULL;
     } else {
         $this->dueDate = $dueDate->getTimestamp();
     }
 }
开发者ID:Lesspion,项目名称:bpmn,代码行数:8,代码来源:CreateUserTaskCommand.php

示例7: __construct

 public function __construct(\DateTimeInterface $date = NULL)
 {
     if ($date === NULL) {
         $this->date = new \DateTimeImmutable();
     } else {
         $this->date = new \DateTimeImmutable('@' . $date->getTimestamp(), $date->getTimezone());
     }
 }
开发者ID:koolkode,项目名称:http,代码行数:8,代码来源:AbstractDateHeader.php

示例8: setValue

 /**
  * @param \DateTimeInterface|NULL $value
  * @return \Nella\Forms\DateTime\DateInput
  */
 public function setValue($value = NULL)
 {
     if ($value === NULL) {
         return parent::setValue(NULL);
     } elseif (!$value instanceof \DateTimeInterface) {
         throw new \Nette\InvalidArgumentException('Value must be DateTimeInterface or NULL');
     }
     return parent::setValue($value->format($this->format));
 }
开发者ID:nella,项目名称:forms-datetime,代码行数:13,代码来源:DateInput.php

示例9: setDateTime

 /**
  * Set the date-time of the Date in this Header.
  *
  * If a DateTime instance is provided, it is converted to DateTimeImmutable.
  *
  * @param DateTimeInterface $dateTime
  */
 public function setDateTime(DateTimeInterface $dateTime)
 {
     $this->clearCachedValueIf($this->getCachedValue() != $dateTime->format(DateTime::RFC2822));
     if ($dateTime instanceof DateTime) {
         $immutable = new DateTimeImmutable('@' . $dateTime->getTimestamp());
         $dateTime = $immutable->setTimezone($dateTime->getTimezone());
     }
     $this->dateTime = $dateTime;
 }
开发者ID:tweakers-dev,项目名称:swiftmailer,代码行数:16,代码来源:DateHeader.php

示例10: init

 /**
  * Init.
  *
  * @param TwitterMessageId   $id
  * @param TwitterUser        $sender
  * @param string             $text
  * @param TwitterEntities    $entities
  * @param \DateTimeInterface $date
  */
 public function init(TwitterMessageId $id, TwitterUser $sender, $text, TwitterEntities $entities, \DateTimeInterface $date)
 {
     Assertion::eq(new \DateTimeZone('UTC'), $date->getTimezone());
     $this->entities = $entities;
     $this->id = $id;
     $this->sender = $sender;
     $this->text = $text;
     $this->date = $date;
 }
开发者ID:remi-san,项目名称:twitter,代码行数:18,代码来源:AbstractMessage.php

示例11: __construct

 /**
  * @param string $token
  * @param \DateTimeInterface $expiry
  */
 public function __construct($token, \DateTimeInterface $expiry)
 {
     $this->token = $token;
     if ($expiry instanceof \DateTimeImmutable) {
         $this->expiry = $expiry;
     } else {
         $this->expiry = new \DateTimeImmutable('@' . $expiry->getTimestamp());
     }
 }
开发者ID:moneymaxim,项目名称:TrustpilotAuthenticator,代码行数:13,代码来源:AccessToken.php

示例12: __construct

 /**
  * @inheritdoc
  */
 public function __construct(\DateTimeInterface $firstDate, \DateTimeInterface $lastDate, $description = '')
 {
     $this->firstDate = new \DateTimeImmutable($firstDate->format('Y-m-d H:i:s'));
     $this->lastDate = new \DateTimeImmutable($lastDate->format('Y-m-d H:i:s'));
     $this->description = $description;
     if ($this->firstDate > $this->lastDate) {
         throw new \LogicException('The first date must be lower than the last date (first date : ' . $this->firstDate->format('Y-m-d') . ' last date : ' . $this->lastDate->format('Y-m-d'));
     }
 }
开发者ID:WildCodeSchool,项目名称:projet-gesty,代码行数:12,代码来源:Period.php

示例13: writeLastModified

 private function writeLastModified(\XMLWriter $xmlWriter, \DateTimeInterface $lastModified = null)
 {
     if ($lastModified === null) {
         return;
     }
     $xmlWriter->startElement('lastmod');
     $xmlWriter->text($lastModified->format('c'));
     $xmlWriter->endElement();
 }
开发者ID:refinery29,项目名称:sitemap,代码行数:9,代码来源:SitemapWriter.php

示例14: formatDate

 protected function formatDate(\DateTimeInterface $value, $nestingLevel)
 {
     $seconds = (int) $value->format('U');
     $milliseconds = (int) $value->format('u') / 1000;
     if ($seconds < 0) {
         return new UTCDateTime($seconds * 1000 - $milliseconds);
     } else {
         return new UTCDateTime($seconds * 1000 + $milliseconds);
     }
 }
开发者ID:acrobat,项目名称:monolog,代码行数:10,代码来源:MongoDBFormatter.php

示例15: transform

 /**
  * Transforms a DateTime object into a timestamp in the configured timezone.
  *
  * @param \DateTime|\DateTimeInterface $dateTime A DateTime object
  *
  * @return int A timestamp
  *
  * @throws TransformationFailedException If the given value is not an instance
  *                                       of \DateTime or \DateTimeInterface
  */
 public function transform($dateTime)
 {
     if (null === $dateTime) {
         return;
     }
     if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
         throw new TransformationFailedException('Expected a \\DateTime or \\DateTimeInterface.');
     }
     return $dateTime->getTimestamp();
 }
开发者ID:WilBenShu,项目名称:digital_pilot,代码行数:20,代码来源:DateTimeToTimestampTransformer.php


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