3 namespace Illuminate\Support
;
8 trait InteractsWithTime
11 * Get the number of seconds until the given DateTime.
13 * @param \DateTimeInterface|\DateInterval|int $delay
16 protected function secondsUntil($delay)
18 $delay = $this->parseDateInterval($delay);
20 return $delay instanceof DateTimeInterface
21 ?
max(0, $delay->getTimestamp() - $this->currentTime())
26 * Get the "available at" UNIX timestamp.
28 * @param \DateTimeInterface|\DateInterval|int $delay
31 protected function availableAt($delay = 0)
33 $delay = $this->parseDateInterval($delay);
35 return $delay instanceof DateTimeInterface
36 ?
$delay->getTimestamp()
37 : Carbon
::now()->addSeconds($delay)->getTimestamp();
41 * If the given value is an interval, convert it to a DateTime instance.
43 * @param \DateTimeInterface|\DateInterval|int $delay
44 * @return \DateTimeInterface|int
46 protected function parseDateInterval($delay)
48 if ($delay instanceof DateInterval
) {
49 $delay = Carbon
::now()->add($delay);
56 * Get the current system time as a UNIX timestamp.
60 protected function currentTime()
62 return Carbon
::now()->getTimestamp();