public function __construct(\DateTimeInterface $date = NULL) { if ($date === NULL) { $this->date = new \DateTimeImmutable(); } else { $this->date = new \DateTimeImmutable('@' . $date->getTimestamp(), $date->getTimezone()); } }
/** * 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; }
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; }
protected function computeExpires(\DateTimeInterface $expires = NULL) { // TODO: Lock min / max timeouts must be configurable. $min = new \DateTimeImmutable('+2 minutes'); if ($expires === NULL || $expires < $min) { return $min; } $max = new \DateTimeImmutable('+2 hours'); if ($expires > $max) { return $max; } return new \DateTimeImmutable('@' . $expires->getTimestamp(), $expires->getTimezone()); }
/** * @param \DateTimeInterface $dateTime * * @return string */ private function extractTimezone(\DateTimeInterface $dateTime) { return $dateTime->getTimezone()->getName(); }
/** * @param \DateTimeInterface $date * @param int $dateType * @param int $timeType * @param null $locale * @param null $timezone * @param string|null $pattern * @return string */ public function formatDateTime( \DateTimeInterface $date, $dateType = \IntlDateFormatter::SHORT, $timeType = \IntlDateFormatter::SHORT, $locale = null, $timezone = null, $pattern = null ) { $formatter = new \IntlDateFormatter( $locale ?: $this->_localeResolver->getLocale(), $dateType, $timeType, $timezone ?: $date->getTimezone(), null, $pattern ); return $formatter->format($date); }
/** * @param \DateTimeInterface $date * @param int $dateType * @param int $timeType * @param null $locale * @param null $timezone * @param string|null $pattern * @return string */ public function formatDateTime(\DateTimeInterface $date, $dateType = \IntlDateFormatter::SHORT, $timeType = \IntlDateFormatter::SHORT, $locale = null, $timezone = null, $pattern = null) { if ($timezone === null) { if ($date->getTimezone() === null || $date->getTimezone()->getName() === '+00:00') { $timezone = new \DateTimeZone('UTC'); } else { $timezone = $date->getTimezone(); } } $formatter = new \IntlDateFormatter($locale ?: $this->_localeResolver->getLocale(), $dateType, $timeType, $timezone, null, $pattern); return $formatter->format($date); }
function date_timezone_get(DateTimeInterface $datetime) { return $datetime->getTimezone(); }
public function setExpires(\DateTimeInterface $expires) { $this->expires = new \DateTimeImmutable('@' . $expires->getTimestamp(), $expires->getTimezone()); }
/** * Set the end date for the range * * @param \DateTimeInterface $end * @return DateRange */ public function setEnd(\DateTimeInterface $end) { $this->endTimezone = $end->getTimezone(); $this->end = (new \DateTimeImmutable($end->format('c')))->setTimezone(new \DateTimeZone('UTC')); return $this; }
/** * @param \DateTimeInterface $dateTime * @param int $dateType * @param int $timeType * @param string $pattern * * @return \IntlDateFormatter */ private function createFormatter($dateTime, $dateType = self::NONE, $timeType = self::NONE, $pattern = null) { return new \IntlDateFormatter($this->locale, $dateType, $timeType, $dateTime->getTimezone(), \IntlDateFormatter::GREGORIAN, $pattern); }
/** * Sets the expiration time for this cache item. * * @param \DateTimeInterface $expiration * The point in time after which the item MUST be considered expired. * If null is passed explicitly, a default value MAY be used. If none is set, * the value should be stored permanently or for as long as the * implementation allows. * * @return static * The called object. */ public function expiresAt($expiration) { $now = new \DateTime('now', $expiration->getTimezone()); $this->cacheLifetime = $expiration->getTimestamp() - $now->getTimestamp(); return $this; }