/**
  * @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;
 }
Ejemplo n.º 2
1
 /**
  * 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;
 }
Ejemplo n.º 3
1
 /**
  * @return \stdClass
  */
 private function getSerializedDirectMessageDelete()
 {
     $serializedTweetDelete = new \stdClass();
     $serializedTweetDelete->delete = new \stdClass();
     $serializedTweetDelete->delete->direct_message = new \stdClass();
     $serializedTweetDelete->delete->direct_message->id = $this->id;
     $serializedTweetDelete->delete->direct_message->user_id = $this->userId;
     $serializedTweetDelete->delete->timestamp_ms = $this->date->getTimestamp() * 1000;
     return $serializedTweetDelete;
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 protected function getDate(\DateTimeInterface $date = null)
 {
     if ($date === null) {
         return str_repeat('0', 8);
     }
     return $date->format('dmY');
 }
 /**
  * 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;
 }
Ejemplo n.º 7
0
 public function setDueDate(\DateTimeInterface $dueDate = NULL)
 {
     if ($dueDate === NULL) {
         $this->dueDate = NULL;
     } else {
         $this->dueDate = $dueDate->getTimestamp();
     }
 }
Ejemplo n.º 8
0
 public function __construct(\DateTimeInterface $date = NULL)
 {
     if ($date === NULL) {
         $this->date = new \DateTimeImmutable();
     } else {
         $this->date = new \DateTimeImmutable('@' . $date->getTimestamp(), $date->getTimezone());
     }
 }
Ejemplo n.º 9
0
 /**
  * @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));
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * 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;
 }
 /**
  * @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());
     }
 }
Ejemplo n.º 13
0
 /**
  * @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'));
     }
 }
Ejemplo n.º 14
0
 private function writeLastModified(\XMLWriter $xmlWriter, \DateTimeInterface $lastModified = null)
 {
     if ($lastModified === null) {
         return;
     }
     $xmlWriter->startElement('lastmod');
     $xmlWriter->text($lastModified->format('c'));
     $xmlWriter->endElement();
 }
Ejemplo n.º 15
0
 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);
     }
 }
 /**
  * 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();
 }
Ejemplo n.º 17
0
 /**
  * @param string|\DateTimeInterface $date
  *
  * @return string
  */
 public function getDateFormatted($date) : string
 {
     if ($date instanceof \DateTimeInterface) {
         return $this->formatter->format($date->getTimestamp());
     } elseif (is_string($date)) {
         return $this->formatter->format(strtotime($date));
     } else {
         return '';
     }
 }
 public function tag(\DateTimeInterface $date)
 {
     $this->getDay->bindValue(':datum', $date->format('Y-m-d'));
     $this->getDay->execute();
     $columns = $this->getDay->fetch(\PDO::FETCH_ASSOC);
     if ($columns === false) {
         $columns = array('status' => $date->format('N') >= 6 ? Status::WOCHENENDE : Status::FREI, 'beginn' => $date->format('Y-m-d'), 'ende' => $date->format('Y-m-d'));
     }
     return new Tag(new Status($columns['status']), new \DateTimeImmutable($columns['beginn']), new \DateTimeImmutable($columns['ende']));
 }
Ejemplo n.º 19
0
 /**
  * @param null|\DateTimeInterface $dateTime
  * @param null|string $division
  * @return null|\stdClass[]
  * @throws \Exception
  */
 public static function getHolidays(\DateTimeInterface $dateTime = null, $division = null)
 {
     self::loadHolidayData();
     /** @var \stdClass $events */
     $events = self::filterByDivision($division);
     if (!$dateTime) {
         return $events;
     }
     /** @var string $dateKey */
     $dateKey = $dateTime->format('Y-m-d');
     return isset($events[$dateKey]) ? $events[$dateKey] : null;
 }
Ejemplo n.º 20
0
 /**
  * Returns a formatted diff for the given from and to datetimes
  *
  * @param  DateTimeInterface $from
  * @param  DateTimeInterface $to
  *
  * @return string
  */
 public function formatDiff(DateTimeInterface $from, DateTimeInterface $to)
 {
     static $units = array('y' => 'year', 'm' => 'month', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second');
     $diff = $to->diff($from);
     foreach ($units as $attribute => $unit) {
         $count = $diff->{$attribute};
         if (0 !== $count) {
             return $this->doGetDiffMessage($count, $diff->invert, $unit);
         }
     }
     return $this->getEmptyDiffMessage();
 }
 /**
  * @param \DateTimeInterface $date
  * @return null|Period
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function getSchoolYearIncluding(\DateTimeInterface $date)
 {
     $result = $this->getEntityManager()->createQuery('
         SELECT s
         FROM WCSCantineBundle:SchoolYear s 
         WHERE DATE(s.dateStart) < :date_day
         AND DATE(s.dateEnd) > :date_day
     ')->setParameter(':date_day', $date->format('Y-m-d'))->getOneOrNullResult();
     if ($result) {
         return new Period($result->getDateStart(), $result->getDateEnd());
     }
     return null;
 }
Ejemplo n.º 22
0
 public static function monday(\DateTimeInterface $date = null)
 {
     if ($date) {
         $today = DateTime::createFromFormat('U', $date->format('U'), $date->getTimezone())->asDate()->asDateTime();
     } else {
         $today = self::today();
     }
     if ($today->format('w') < 1) {
         $monday = $today->modify('-6 day');
     } else {
         $monday = $today->modify('-' . ($today->format('w') - 1) . ' day');
     }
     return $monday;
 }
 /**
  * Transforms a normalized date into a localized date string/array.
  *
  * @param \DateTimeInterface $dateTime A DateTimeInterface object
  *
  * @return string|array Localized date string/array
  *
  * @throws TransformationFailedException If the given value is not a \DateTimeInterface
  *                                       or if the date could not be transformed.
  */
 public function transform($dateTime)
 {
     if (null === $dateTime) {
         return '';
     }
     if (!$dateTime instanceof \DateTimeInterface) {
         throw new TransformationFailedException('Expected a \\DateTimeInterface.');
     }
     $value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());
     if (intl_get_error_code() != 0) {
         throw new TransformationFailedException(intl_get_error_message());
     }
     return $value;
 }
Ejemplo n.º 24
0
 /**
  * Publish testcase result
  *
  * @param string $testCaseName
  * @param string $status
  * @param string $result
  * @param \DateTimeInterface $startDate Testcase start datetime
  * @param \DateTimeInterface $endDate Testcase end datetime
  */
 public function publishResults($testCaseName, $status, $result = null, \DateTimeInterface $startDate = null, \DateTimeInterface $endDate = null)
 {
     $xml = $this->readAndLock();
     $testCaseNode = $this->getTestCaseNode($xml, $testCaseName);
     $testCaseNode['status'] = $status;
     if ($result) {
         $testCaseNode['result'] = $result;
     }
     if ($startDate) {
         $testCaseNode['start'] = $startDate->format(\DateTime::ISO8601);
     }
     if ($endDate) {
         $testCaseNode['end'] = $endDate->format(\DateTime::ISO8601);
     }
     $this->writeAndUnlock($xml);
 }
Ejemplo n.º 25
0
 /**
  * Creates an example for a date format.
  *
  * This is centralized for a consistent method of creating these examples.
  *
  * @param string $format
  *
  * @return string
  */
 public static function formatExample($format)
 {
     if (!static::$dateExample) {
         static::$dateExample = new DrupalDateTime();
     }
     return static::$dateExample->format($format);
 }
 /**
  * {@inheritdoc}
  */
 public function expiresAfter($time)
 {
     $this->expires = new DateTimeImmutable();
     if (!$time instanceof DateInterval) {
         $time = new DateInterval(sprintf('PT%sS', $time));
     }
     $this->expires = $this->expires->add($time);
     return $this;
 }
Ejemplo n.º 27
0
 /**
  * @return \stdClass
  */
 private function getSerializedEvent()
 {
     $eventObj = new \stdClass();
     $eventObj->event = $this->type;
     $eventObj->source = $this->serializedSource;
     $eventObj->target = $this->serializedTarget;
     $eventObj->target_object = $this->serializedTargetObject;
     $eventObj->created_at = $this->date->format(TwitterDate::FORMAT);
     return $eventObj;
 }
Ejemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function jsonSerialize()
 {
     $expires_at = null;
     if ($this->expires_at instanceof JsonSerializable) {
         $expires_at = $this->expires_at->jsonSerialize();
     } elseif ($this->expires_at instanceof DateTimeInterface) {
         $expires_at = $this->expires_at->getTimestamp();
     }
     return ['session_id' => $this->session_id, 'user_id' => $this->user_id, 'expires_at' => $expires_at];
 }
Ejemplo n.º 29
0
 /**
  * @param \DateTimeInterface|NULL $value
  * @return \Nella\Forms\DateTime\DateTimeInput
  */
 public function setValue($value = NULL)
 {
     if ($value === NULL) {
         $this->date = NULL;
         $this->time = NULL;
         return $this;
     } elseif (!$value instanceof \DateTimeInterface) {
         throw new \Nette\InvalidArgumentException('Value must be DateTimeInterface or NULL');
     }
     $this->date = $value->format($this->dateFormat);
     $this->time = $value->format($this->timeFormat);
     return $this;
 }
Ejemplo n.º 30
-1
 public function runsAt(\DateTimeInterface $time)
 {
     if ($time->getTimeZone() != $this->tz) {
         $time = clone $time;
         $time->setTimeZone($this->tz);
     }
     if (!in_array($time->format('i'), $this->minutes)) {
         return false;
     }
     if (!in_array($time->format('H'), $this->hours)) {
         return false;
     }
     if ($this->daysOfMonth != self::LAST_DAY_OF_MONTH && !in_array($time->format('j'), $this->daysOfMonth)) {
         return false;
     }
     if ($this->daysOfMonth == self::LAST_DAY_OF_MONTH && $time->format('j') != $time->format('t')) {
         return false;
     }
     if (!in_array($time->format('w'), $this->daysOfWeek)) {
         return false;
     }
     if (!in_array($time->format('n'), $this->months)) {
         return false;
     }
     return true;
 }