composer package updates
[openemr.git] / vendor / illuminate / support / InteractsWithTime.php
blob19ed3f242a62776804cd9ddff47a92b21d1799f7
1 <?php
3 namespace Illuminate\Support;
5 use DateInterval;
6 use DateTimeInterface;
8 trait InteractsWithTime
10 /**
11 * Get the number of seconds until the given DateTime.
13 * @param \DateTimeInterface|\DateInterval|int $delay
14 * @return int
16 protected function secondsUntil($delay)
18 $delay = $this->parseDateInterval($delay);
20 return $delay instanceof DateTimeInterface
21 ? max(0, $delay->getTimestamp() - $this->currentTime())
22 : (int) $delay;
25 /**
26 * Get the "available at" UNIX timestamp.
28 * @param \DateTimeInterface|\DateInterval|int $delay
29 * @return int
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();
40 /**
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);
52 return $delay;
55 /**
56 * Get the current system time as a UNIX timestamp.
58 * @return int
60 protected function currentTime()
62 return Carbon::now()->getTimestamp();