-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSystemClock.php
More file actions
60 lines (51 loc) · 1.79 KB
/
SystemClock.php
File metadata and controls
60 lines (51 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Icecave\Chrono\Clock;
use Icecave\Chrono\TimeZone;
/**
* A clock that uses the system to obtain real wall-clock date/times.
*/
class SystemClock extends AbstractClock
{
/**
* @return array<integer> A tuple containing time information, as per {@see localtime()}, plus the timezone offset in seconds.
*/
protected function currentLocalTimeInfo()
{
list($seconds) = $this->currentUnixTime();
$parts = $this->isolator->date('s,i,H,d,m,Y,w,z,I,Z', $seconds);
$parts = explode(',', $parts);
$parts = array_map('intval', $parts);
return $parts;
}
/**
* @return array<integer> A tuple containing time information, as per {@see localtime()}, plus the timezone offset in seconds, but for the UTC timezone.
*/
protected function currentUtcTimeInfo()
{
list($seconds) = $this->currentUnixTime();
$parts = $this->isolator->gmdate('s,i,H,d,m,Y,w,z,0,0', $seconds);
$parts = explode(',', $parts);
$parts = array_map('intval', $parts);
return $parts;
}
/**
* Fetch the current unix timestamp, bypassing suspended state.
*
* @return tuple<integer,integer> The current Unix time as a 2-tuple of seconds and nanoseconds.
*/
protected function currentUnixTime()
{
$microtime = $this->isolator->microtime(true);
$seconds = intval($microtime);
return [$seconds, intval(($microtime - $seconds) * 1000000000)];
}
/**
* @param int $seconds The number of seconds to sleep.
*
* @return bool True if the sleep completed; or false if the sleep was interrupted.
*/
protected function doSleep($seconds)
{
return 0 === $this->isolator->sleep($seconds);
}
}