當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。