本文整理汇总了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;
}
示例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;
}
示例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);
}
示例4: getDate
protected function getDate(\DateTimeInterface $date = null)
{
if ($date === null) {
return str_repeat('0', 8);
}
return $date->format('dmY');
}
示例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;
}
示例6: setDueDate
public function setDueDate(\DateTimeInterface $dueDate = NULL)
{
if ($dueDate === NULL) {
$this->dueDate = NULL;
} else {
$this->dueDate = $dueDate->getTimestamp();
}
}
示例7: __construct
public function __construct(\DateTimeInterface $date = NULL)
{
if ($date === NULL) {
$this->date = new \DateTimeImmutable();
} else {
$this->date = new \DateTimeImmutable('@' . $date->getTimestamp(), $date->getTimezone());
}
}
示例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));
}
示例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;
}
示例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;
}
示例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());
}
}
示例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'));
}
}
示例13: writeLastModified
private function writeLastModified(\XMLWriter $xmlWriter, \DateTimeInterface $lastModified = null)
{
if ($lastModified === null) {
return;
}
$xmlWriter->startElement('lastmod');
$xmlWriter->text($lastModified->format('c'));
$xmlWriter->endElement();
}
示例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);
}
}
示例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();
}