/** * 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; }
/** * @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; }
public function __construct(\DateTimeInterface $date = NULL) { if ($date === NULL) { $this->date = new \DateTimeImmutable(); } else { $this->date = new \DateTimeImmutable('@' . $date->getTimestamp(), $date->getTimezone()); } }
public function setDueDate(\DateTimeInterface $dueDate = NULL) { if ($dueDate === NULL) { $this->dueDate = NULL; } else { $this->dueDate = $dueDate->getTimestamp(); } }
/** * @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()); } }
/** * 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; }
/** * 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(); }
/** * {@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]; }
/** * @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 ''; } }
/** * Returns the difference between two Period objects. * * @param \Thin\Period $period * @param bool $get_as_seconds If used and set to true, the method will return * an intw hich represents the duration in seconds * instead of a\DateInterval object * * @return \DateInterval|int */ public function durationDiff(Period $period, $get_as_seconds = false) { $diff = $this->end->getTimestamp() - $this->start->getTimestamp() - $period->end->getTimestamp() + $period->start->getTimestamp(); if (!$get_as_seconds) { $res = new DateInterval('PT' . abs($diff) . 'S'); if (0 > $diff) { $res->invert = 1; } return $res; } return $diff; }
/** * 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; }
/** * Created a timer event subscription backed by a scheduled job. * * @param \DateTimeInterface $time Schedule date. * @param VirtualExecution $execution Target execution. * @param string $activityId ID of the activity that created the event subscription. * @param Node $node Target node to receive the delegated signal or NULL in order to use the activity node. * @param boolean $boundaryEvent Is this a subscription for a boundary event? */ public function __construct(\DateTimeInterface $time, VirtualExecution $execution, $activityId, Node $node = NULL, $boundaryEvent = false) { parent::__construct('timer', $execution, $activityId, $node, $boundaryEvent); $this->time = $time->getTimestamp(); }
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()); }
public function setExpires(\DateTimeInterface $expires) { $this->expires = new \DateTimeImmutable('@' . $expires->getTimestamp(), $expires->getTimezone()); }
public function receiveDueCommands(\DateTimeInterface $now, int $limit = SchedulerWorker::DEFAULT_THROTTLE, \DateTimeInterface $startTime = null) : array { if ($startTime === null) { $start = 0; } else { $start = $startTime->getTimestamp(); } $results = $this->evalScript('receive_due_messages', [$this->namespace, $start, $now->getTimestamp(), $limit]); $commands = []; foreach ($results as $result) { list($queueName, $id, $message, $score) = $result; $commands[] = new ReceivedScheduledCommand($queueName, $id, $message, new \DateTimeImmutable('@' . $score)); } return $commands; }
/** * Sets the expiration time for this cache item. * * @param \DateTimeInterface $expiration The point in time after which the item MUST be considered expired * * @return self */ public function expiresAt($expiration) { $this->expiration = $expiration->getTimestamp(); return $this; }
/** * @param \DateTimeInterface $dateTime * @param Event $event * @return ScheduleToken */ public function scheduleAt(\DateTimeInterface $dateTime, Event $event) : ScheduleToken { $token = new ScheduleToken(uniqid()); $this->schedule[$token->getTokenId()] = [$dateTime->getTimestamp() => $event]; return $token; }
function date_timestamp_get(DateTimeInterface $datetime) { return $datetime->getTimestamp(); }
/** * 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. * * @throws InvalidArgumentException */ public function expiresAt($expiration) { if ($expiration === null) { $this->_expiry = 0; } else { if (!$expiration instanceof \DateTimeInterface) { throw new InvalidArgumentException('Invalid expiration time.'); } $this->_expiry = $expiration->getTimestamp(); } return $this; }
public function taskCreatedAfter(\DateTimeInterface $date) { $this->taskCreatedAfter = $date->getTimestamp(); return $this; }
public function setLockedAt(\DateTimeInterface $lockedAt = NULL) { if ($lockedAt === NULL) { $this->lockedAt = NULL; } else { $this->lockedAt = new \DateTimeImmutable('@' . $lockedAt->getTimestamp(), new \DateTimeZone('UTC')); } }
public function deployedAfter(\DateTimeInterface $date) { $this->deployedAfter = $date->getTimestamp(); return $this; }
/** * Creates a unix timestamp from the given DateTime object. If NULL is given * NULL will be returned. * * @param \DateTime $dateTime * @return integer */ protected function processDateTime(\DateTimeInterface $dateTime = null) { if ($dateTime instanceof \DateTimeInterface) { return $dateTime->getTimestamp(); } else { return null; } }
/** * 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; }