/** * @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; }
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); }
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'])); }
protected function getDate(\DateTimeInterface $date = null) { if ($date === null) { return str_repeat('0', 8); } return $date->format('dmY'); }
/** * 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); }
/** * 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; }
private function writeLastModified(\XMLWriter $xmlWriter, \DateTimeInterface $lastModified = null) { if ($lastModified === null) { return; } $xmlWriter->startElement('lastmod'); $xmlWriter->text($lastModified->format('c')); $xmlWriter->endElement(); }
/** * 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; }
/** * @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')); } }
/** * @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)); }
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); } }
/** * @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; }
/** * @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; }
/** * @return \stdClass */ private function getSerializedDirectMessage() { $dmObj = new \stdClass(); $dmObj->id = $this->id; $dmObj->sender = $this->serializedSender; $dmObj->recipient = $this->serializedRecipient; $dmObj->text = $this->text; $dmObj->created_at = $this->date->format(TwitterDate::FORMAT); $dmObj->entities = $this->serializedEntities; $superDmObject = new \stdClass(); $superDmObject->direct_message = $dmObj; return $superDmObject; }
/** * @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; }
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; }
/** * @param $query * @return mixed */ private function appendDates($query) { if ($this->dateCriterionField !== null) { $query['date_field'] = $this->dateCriterionField; if ($this->dateCriterionMin) { $query['date_min'] = $this->dateCriterionMin->format('Y/m/d'); } if ($this->dateCriterionMax) { $query['date_max'] = $this->dateCriterionMax->format('Y/m/d'); return $query; } return $query; } return $query; }
/** * 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); }
/** * Outputs message depending on flag * * @return string */ public function __invoke(\DateTimeInterface $start, \DateTimeInterface $end, $format = null, \DateTimeZone $timezone = null, $separator = ' - ') { if (null !== $timezone) { $start->setTimezone($timezone); $end->setTimezone($timezone); } if (null !== $format) { $this->format = $format; } if ($start->format('Y') != $end->format('Y')) { return $start->format('d.m.Y') . $separator . $end->format('d.m.Y'); } if ($start->format('m') != $end->format('m')) { return $start->format('d.m.') . $separator . $end->format('d.m.Y'); } if ($start->format('d') != $end->format('d')) { return $start->format('d.') . $separator . $end->format('d.m.Y'); } if ($start->format('H') != $end->format('H') || $start->format('i') != $end->format('i')) { return $start->format('d.m.Y H:i') . $separator . $end->format('H:i'); } return ''; }
/** * Serialize as relative URL * * @param bool $canonical Canonical URL * @return string Relative URL */ public function toUrl($canonical = false) { $locator = []; $datePrecision = intval(getenv('OBJECT_DATE_PRECISION')); // Add the creation date foreach (array_slice(array_keys(self::$datePattern), 0, $datePrecision) as $dateFormat) { $locator[] = $this->creationDate->format($dateFormat); } // Add the object ID and type $uid = $this->uid->getId(); $locator[] = ($this->hidden ? '.' : '') . $uid; // If not only the canonical URL should be returned if (!$canonical) { $locator[count($locator) - 1] .= '-' . $this->type->getType(); // Add the ID, draft mode and revision $locator[] = rtrim(($this->revision->isDraft() ? '.' : '') . $uid . '-' . $this->revision->getRevision(), '-'); } return '/' . implode('/', $locator); }
/** * * @return \DateTimeImmutable date qui suit la date courante + N jours */ public static function getFirstDayAvailable($activityTypeConstant, \DateTimeInterface $date) { // récupère le nombre de jours à ajouter à la date disponible pour // retourner le 1er jour de disponible en fonction de l'activité $nbDays = 1; if (isset(self::$nbDaysUntilSubscribe[self::$keyDates[$activityTypeConstant]])) { $nbDays = self::$nbDaysUntilSubscribe[self::$keyDates[$activityTypeConstant]]; // aucune inscription n'est possible le jour même if ('0' === $nbDays) { throw new \LogicException('First day available must be >= 1 day.'); } $nbDays = \intval($nbDays); } $dateFirstDayAvail = new \DateTimeImmutable($date->format('Y-m-d') . ' +' . $nbDays . ' day'); // tient compte des jours fermés pour l'activité donnée // recherche la première date qui n'est pas un jour fermé // et décale d'autant le 1er jour disponible $oneDay = new \DateInterval('P1D'); while (self::isDayOff($activityTypeConstant, $dateFirstDayAvail)) { $dateFirstDayAvail = $dateFirstDayAvail->add($oneDay); } return $dateFirstDayAvail; }
/** * Converts a date to the given format. * * <pre> * {{ post.published_at|date("m/d/Y") }} * </pre> * * @param Twig_Environment $env A Twig_Environment instance * @param DateTime|DateTimeInterface|DateInterval|string $date A date * @param string|null $format The target format, null to use the default * @param DateTimeZone|string|null|false $timezone The target timezone, null to use the default, false to leave unchanged * * @return string The formatted date */ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $timezone = null) { if (null === $format) { $formats = $env->getExtension('core')->getDateFormat(); $format = $date instanceof DateInterval ? $formats[1] : $formats[0]; } if ($date instanceof DateInterval) { return $date->format($format); } return twig_date_converter($env, $date, $timezone)->format($format); }
/** * @param \DateTimeInterface $dateTime * @return \Staffim\DateTime\DateTime */ public static function createFromNativeDate(\DateTimeInterface $dateTime) { return new static($dateTime->format(self::FULL_ISO8601)); }
/** * @param \DateTime|\DateTimeInterface $value */ private function validateDate($value) { static $currentDate; if (!$currentDate) { $currentDate = new \DateTime('now', new \DateTimeZone('UTC')); $currentDate->setTime(0, 0, 0); } if ($value > $currentDate) { throw new TransformationFailedException(sprintf('Date "%s" is higher then current date "%s". Are you a time traveler?', $value->format('Y-m-d'), $currentDate->format('Y-m-d'))); } }
private static function toRelative(\DateTimeInterface $dateTime, \DateTimeInterface $now = null) { $precision = 'minute'; $now = $now ?: new \DateTimeImmutable(); if ($dateTime == $now) { return 'now'; } $diff = $dateTime->diff($now); if ($dateTime->format('Y-m-d') != $now->format('Y-m-d')) { $days = (new \DateTime($dateTime->format('Y-m-d')))->diff(new \DateTime($now->format('Y-m-d')))->days; if ($days == 1) { $dayString = 'tomorrow'; } else { if ($days < 7) { $dayString = $dateTime->format('l'); } else { $dayString = $dateTime->format('Y-m-d'); } } return $dayString . ' at ' . $dateTime->format('H:i'); } $times = []; foreach (['hour' => $diff->h, 'minute' => $diff->i, 'second' => $diff->s] as $unit => $value) { if ($value) { $times[] = $value . ' ' . $unit . ($value == 1 ? '' : 's'); } if ($precision == $unit) { break; } } return 'in ' . implode(', ', $times); }
/** * @param \DateTimeInterface|string $date * @param string|null $base * @param array $symbols * @return array */ public function getHistorical($date, $base = null, array $symbols = []) { $path = ['historical']; if ($date instanceof \DateTimeInterface) { $path[] = $date->format('Y-m-d'); } else { $path[] = $date; } $path = '/' . implode('/', $path) . '.json'; $query = ['base' => $base]; if ($symbols) { $query['symbols'] = implode(',', $symbols); } $body = $this->sendRequest($path, $query); return $body; }
/** * Get the second of a date * * @param \DateTimeInterface $dateTime * @return integer The second of the given date */ public function second(\DateTimeInterface $dateTime) { return (int) $dateTime->format('s'); }
/** * Indicate that the object got published * * @return SystemProperties System properties * @throws RuntimeException If the object is already published */ public function publish() { // If the object is already published if ($this->published instanceof \DateTimeInterface) { throw new RuntimeException('Cannot republish object previously published at ' . $this->published->format('c'), RuntimeException::CANNOT_REPUBLISH_OBJECT); } $systemProperties = clone $this; $systemProperties->published = new \DateTimeImmutable(); $systemProperties->revision = $this->revision->setDraft(false); return $systemProperties; }
/** * Set new date. * * @param \DateTimeInterface $date Date and time. * * @since 1.0 */ public function setDate(\DateTimeInterface $date) { $this->getDomElement()->nodeValue = $date->format(\DateTime::RFC3339); $this->setCachedProperty('content', $date); }
/** * @param \DateTimeInterface $dateStart * @param \DateTimeInterface $dateEnd * @return Response */ public function getDataProductsInModifiedInterval(\DateTimeInterface $dateStart, \DateTimeInterface $dateEnd) { return $this->getMaster()->call('GET', sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductDataService/{KEY}/GetByModifiedInterval?start=%s&end=%s', $dateStart->format('Y-m-d\\TH:i:s'), $dateEnd->format('Y-m-d\\TH:i:s'))); }