本文整理汇总了PHP中DateTimeInterface::getTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeInterface::getTimestamp方法的具体用法?PHP DateTimeInterface::getTimestamp怎么用?PHP DateTimeInterface::getTimestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeInterface
的用法示例。
在下文中一共展示了DateTimeInterface::getTimestamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: getSerializedDirectMessageDelete
/**
* @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;
}
示例3: __construct
public function __construct(\DateTimeInterface $date = NULL)
{
if ($date === NULL) {
$this->date = new \DateTimeImmutable();
} else {
$this->date = new \DateTimeImmutable('@' . $date->getTimestamp(), $date->getTimezone());
}
}
示例4: setDueDate
public function setDueDate(\DateTimeInterface $dueDate = NULL)
{
if ($dueDate === NULL) {
$this->dueDate = NULL;
} else {
$this->dueDate = $dueDate->getTimestamp();
}
}
示例5: __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());
}
}
示例6: 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;
}
示例7: 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();
}
示例8: jsonSerialize
/**
* {@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];
}
示例9: getDateFormatted
/**
* @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 '';
}
}
示例10: durationDiff
/**
* 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;
}
示例11: transform
/**
* 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;
}
示例12: __construct
/**
* 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();
}
示例13: computeExpires
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());
}
示例14: setExpires
public function setExpires(\DateTimeInterface $expires)
{
$this->expires = new \DateTimeImmutable('@' . $expires->getTimestamp(), $expires->getTimezone());
}
示例15: receiveDueCommands
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;
}