- \RedMatter\Chrono\Clock\CalendarClockInterface (interface)
- \RedMatter\Chrono\Clock\SynchronisedClockInterface (interface)
- \RedMatter\Chrono\Clock\CalendarClock
- \RedMatter\Chrono\Clock\SteadyClock
- \RedMatter\Chrono\Clock\SynchronisedClock
- \RedMatter\Chrono\Clock\SteadyClockInterface (interface)
- \RedMatter\Chrono\Clock\Mock\CalendarClock
- \RedMatter\Chrono\Clock\Mock\SteadyClock
- \RedMatter\Chrono\Clock\Mock\SynchronisedClock
- \RedMatter\Chrono\Duration\Days
- \RedMatter\Chrono\Duration\Unit
- \RedMatter\Chrono\Duration\MilliSeconds
- \RedMatter\Chrono\Duration\NanoSeconds
- \RedMatter\Chrono\Duration\Duration
- \RedMatter\Chrono\Duration\Minutes
- \RedMatter\Chrono\Duration\MicroSeconds
- \RedMatter\Chrono\Duration\Hours
- \RedMatter\Chrono\Duration\Seconds
- \RedMatter\Chrono\Time\SteadyTime
- \RedMatter\Chrono\Time\CalendarTime
- \RedMatter\Chrono\Time\CalendarTimeInterface (interface)
- \RedMatter\Chrono\Time\TimeInterface (interface)
Visibility | Function |
---|---|
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool When the function returns, the clock would have elapsed by the specified duration. Returns false on failure or interruptions; otherwise true. |
public | now() : \RedMatter\Chrono\Time\CalendarTime Get current calendar-time. Time readings returned are subject to changes for clock synchronization. Difference between two values obtained after a specific duration need not be the same at all times. |
SynchronisedClockInterface is to be used in cases where the logic would rely on both calendar and monotonic clocks.
Visibility | Function |
---|---|
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool When the function returns, the clock would have elapsed by the specified duration. Returns false on failure or interruptions; otherwise true. |
public | getCalendarTime() : \RedMatter\Chrono\Time\CalendarTime Get time from the embedded Clock. |
public | getSteadyTime() : \RedMatter\Chrono\Time\SteadyTime Get time from the embedded SteadyClock. |
public | perform(\callable $f, \RedMatter\Chrono\Clock\Duration/null $d=null) : mixed Perform $f When the function returns, the clock would have elapsed by the duration it took for $f to finish. NOTE: This is meant for time sensitive use cases (from unit-testing perspective) where both the clocks should absolutely be in sync. Returns the return value from $f |
Wraps
\microtime
to get calendar time.
Visibility | Function |
---|---|
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool When the function returns, the clock would have elapsed by the specified duration. Returns false on failure or interruptions; otherwise true. |
public | now() : \RedMatter\Chrono\Time\CalendarTime Get current calendar-time. Time readings returned are subject to changes for clock synchronization. Difference between two values obtained after a specific duration need not be the same at all times. |
This class implements \RedMatter\Chrono\Clock\CalendarClockInterface
Wraps
hrtime
to get monotonic time.NOTE: Proper implementation of
\hrtime
is only available inphp >= 7.3
; without it the accuracy ofSteadyClock
will be affected by clock adjustments, either due to NTP sync or manual changes to system time.
Visibility | Function |
---|---|
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool When the function returns, the clock would have elapsed by the specified duration. Returns false on failure or interruptions; otherwise true. |
public | now() : \RedMatter\Chrono\Time\SteadyTime Get current monotonic-time. When used with PHP 7.3 or later, the time readings returned are free from changes due to clock synchronization. Even though older versions of PHP, which uses |
This class implements \RedMatter\Chrono\Clock\SteadyClockInterface
SynchronisedClock
wraps both calendar-clock and monotonic-clock for use-cases that require both the clocks.
Visibility | Function |
---|---|
public | __construct() : void |
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool When the function returns, the clock would have elapsed by the specified duration. Returns false on failure or interruptions; otherwise true. |
public | getCalendarTime() : \RedMatter\Chrono\Time\CalendarTime Get time from the embedded Clock. |
public | getSteadyTime() : \RedMatter\Chrono\Time\SteadyTime Get time from the embedded SteadyClock. |
public | perform(\callable $f, \RedMatter\Chrono\Clock\Duration/null $d=null) : mixed Perform $f When the function returns, the clock would have elapsed by the duration it took for $f to finish. NOTE: This is meant for time sensitive use cases (from unit-testing perspective) where both the clocks should absolutely be in sync. Returns the return value from $f |
This class implements \RedMatter\Chrono\Clock\SynchronisedClockInterface
Visibility | Function |
---|---|
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool When the function returns, the clock would have elapsed by the specified duration. Returns false on failure or interruptions; otherwise true. |
public | now() : \RedMatter\Chrono\Time\SteadyTime Get current monotonic-time. When used with PHP 7.3 or later, the time readings returned are free from changes due to clock synchronization. Even though older versions of PHP, which uses |
Mock Clock that models calendar-clock.
Visibility | Function |
---|---|
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool |
public | now() : \RedMatter\Chrono\Time\CalendarTime |
public | setDateTime(\DateTime $time) : void Set the time from DateTime |
public | setTime(\RedMatter\Chrono\Time\CalendarTime $time) : void Set the time |
This class implements \RedMatter\Chrono\Clock\CalendarClockInterface
Mock Clock that models monotonic-clock.
Visibility | Function |
---|---|
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool |
public | now() : \RedMatter\Chrono\Time\SteadyTime |
public | setTime(\RedMatter\Chrono\Time\SteadyTime $time) : void Set the time |
This class implements \RedMatter\Chrono\Clock\SteadyClockInterface
A utility class to keep the two clocks in sync.
Visibility | Function |
---|---|
public | __construct(\RedMatter\Chrono\Clock\Mock\DateTime/null/\DateTime $startTime=null) : void Construct clocks, optionally set to a specific time. |
public | elapse(\RedMatter\Chrono\Duration\Duration $duration) : bool |
public | getCalendarTime() : \RedMatter\Chrono\Time\CalendarTime |
public | getSteadyTime() : \RedMatter\Chrono\Time\SteadyTime |
public | perform(\callable $f, \RedMatter\Chrono\Clock\Mock\Duration/null $d=null) : mixed |
This class implements \RedMatter\Chrono\Clock\SynchronisedClockInterface
Visibility | Function |
---|---|
public | __construct(mixed $value) : void |
This class extends \RedMatter\Chrono\Duration\Duration
Duration unit constants and utilities.
Visibility | Function |
---|---|
public static | customUnitToString(float $unit) : string Get string representation for a custom unit. If the unit matches one of the predefined ones, then that will be chosen. |
public static | toString(float $unit, bool $plural=false) : string/null Get unit name from constants; returns null if not a predefined unit |
Visibility | Function |
---|---|
public | __construct(mixed $value) : void |
This class extends \RedMatter\Chrono\Duration\Duration
Visibility | Function |
---|---|
public | __construct(mixed $value) : void |
This class extends \RedMatter\Chrono\Duration\Duration
Models time-duration and facilitates its manipulation and comparison.
$oneSecond = new Seconds(1);
// it is equivalent to
$oneSecond = new Duration(1, Unit::SECONDS);
Visibility | Function |
---|---|
public | __construct(float $value, float $unit) : void Duration constructor. |
public | __toString() : string |
public | add(\RedMatter\Chrono\Duration\Duration $other) : \RedMatter\Chrono\Duration$this Add durations and return a new object; $this is left unmodified |
public | compare(\RedMatter\Chrono\Duration\Duration $other) : int Compare $this against $other and return an integer. The return value will be < 0 if $this is smaller than $other 0 if $this is equal to $other > 0 if $this is bigger than $other |
public static | createFrom(\RedMatter\Chrono\Duration\Duration $other) : \RedMatter\Chrono\Duration\Duration/\RedMatter\Chrono\Duration\static Create one kind of duration from other. |
public | divideFloat(\RedMatter\Chrono\Duration\Duration $other) : float Get how many time $other can go into $this |
public | divideInt(\RedMatter\Chrono\Duration\Duration $other) : int Get how many time $other can go into $this, in full |
public | intValue(float $unit=-1) : int Get integer part of the value. |
public | isEqual(\RedMatter\Chrono\Duration\Duration $other) : bool Check if $other is equal to this, after normalising the units |
public | isZero() : bool Is a zero duration? |
public | modulo(\RedMatter\Chrono\Duration\Duration $other) : \RedMatter\Chrono\Duration\static Calculate remainder for dividing $this by $other. |
public | slice(int/float $count) : \RedMatter\Chrono\Duration\Duration Slice $this into $count equal intervals and get one. |
public | subtract(\RedMatter\Chrono\Duration\Duration $other) : \RedMatter\Chrono\Duration$this Subtract $other from $this and return a new object; $this is left unmodified |
public | value(float $unit=-1) : float Get duration value in given unit. If no unit is given, the object's own unit is assumed. |
$oneSecond = new Seconds(1);
$twoSeconds = new Seconds(2);
echo (string)$oneSecond; // prints "1 second"
echo (string)$twoSeconds; // prints "2 seconds"
$d1 = new Seconds(10);
$res = $d1->add(new Seconds(3)); // $res will be "13 seconds"
$res = $d1->add(new Seconds(-3)); // $res will be "7 seconds"
$oneSecond = new Seconds(1);
$twoSeconds = new Seconds(1);
$oneThousandMSeconds = new MilliSeconds(1000);
echo $oneSecond->compare($oneThousandMSeconds); // prints "0"
echo $oneSecond->compare($twoSeconds); // prints "-1"
$tenSeconds = new Seconds(10);
$tenE6Microseconds = MicroSeconds::createFrom($d1);
$d1 = new Seconds(100);
$res = $d1->divideFloat(new Seconds(400)); // $res will be 0.25
$d1 = new Seconds(400);
$res = $d1->divideInt(new Seconds(100)); // $res will be 4
$d1 = new Seconds(10);
$res = $d1->slice(4)->intValue(); // $res will be 2
$d1 = new Seconds(11);
$modulo = $d1->modulo(new Seconds(10)); // $modulo will be "1 second"
$d1 = new Seconds(100);
$res = $d1->slice(4); // $res will be "25 seconds"
$d1 = new Seconds(10);
$res = $d1->subtract(new Seconds(3)); // $res will be "7 seconds"
$res = $d1->subtract(new Seconds(-3)); // $res will be "13 seconds"
$d1 = new Seconds(10);
$res = $d1->slice(4)->value(); // $res will be 2.5
$res = $d1->slice(4)->value(Unit::MILLISECONDS); // $res will be 2500
Visibility | Function |
---|---|
public | __construct(mixed $value) : void |
This class extends \RedMatter\Chrono\Duration\Duration
Visibility | Function |
---|---|
public | __construct(mixed $value) : void |
This class extends \RedMatter\Chrono\Duration\Duration
Visibility | Function |
---|---|
public | __construct(mixed $value) : void |
This class extends \RedMatter\Chrono\Duration\Duration
Visibility | Function |
---|---|
public | __construct(mixed $value) : void |
This class extends \RedMatter\Chrono\Duration\Duration
Visibility | Function |
---|---|
public | __construct(float $sinceEpoch) : void time constructor |
public | __toString() : string Convert to string |
public | after(\RedMatter\Chrono\Duration\Duration $duration) : \RedMatter\Chrono\Time\static Get time that is after $this by $duration |
public | before(\RedMatter\Chrono\Duration\Duration $duration) : \RedMatter\Chrono\Time\static Get time that is before $this by $duration |
public | diff(\RedMatter\Chrono\Time\TimeInterface $other) : \RedMatter\Chrono\Time\Duration Get difference between times |
public static | fromTime(\RedMatter\Chrono\Time\CalendarTime $t) : \RedMatter\Chrono\Time\SteadyTime Convert calendar-time to monotonic-time. NOTE: Accuracy will be affected by the PHP version; php >= 7.3 preferred |
public | isAfter(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $this falls after $other. |
public | isBefore(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $this falls before $other. |
public | isEqual(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $other time is equal to $this; if they differ in type, it will be false. |
public | secondsSinceEpoch() : \RedMatter\Chrono\Duration\Seconds Get seconds since epoch |
This class implements \RedMatter\Chrono\Time\TimeInterface
Visibility | Function |
---|---|
public | __construct(float $sinceEpoch) : void time constructor |
public | __toString() : string |
public | after(\RedMatter\Chrono\Duration\Duration $duration) : \RedMatter\Chrono\Time\static Get time that is after $this by $duration |
public | before(\RedMatter\Chrono\Duration\Duration $duration) : \RedMatter\Chrono\Time\static Get time that is before $this by $duration |
public | diff(\RedMatter\Chrono\Time\TimeInterface $other) : \RedMatter\Chrono\Time\Duration Get difference between times |
public | format(string $fmt='Y-m-d\TH:i:s.uP' , \RedMatter\Chrono\Time\DateTimeZone/null/\DateTimeZone $timeZone=null) : stringFormat time using DateTime::format |
public static | fromDateTime(\DateTime $time) : \RedMatter\Chrono\Time\CalendarTime Convert DateTime to calendar-time. |
public static | fromSteadyTime(\RedMatter\Chrono\Time\SteadyTime $t) : \RedMatter\Chrono\Time\CalendarTime Convert monotonic-time to calendar-time NOTE: Accuracy will be affected by the PHP version; php >= 7.3 preferred |
public | getDateTime(\RedMatter\Chrono\Time\DateTimeZone/null/\DateTimeZone $timeZone=null) : \RedMatter\Chrono\Time\DateTime Get DateTime If no timezone is specified, it is set to '+00:00' except for PHP < 5.5.10. For PHP < 5.5.10 it is set to 'UTC'. |
public | getUnixTime(bool $float=false) : int/float Get unixtime |
public | isAfter(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $this falls after $other. |
public | isBefore(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $this falls before $other. |
public | isEqual(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $other time is equal to $this; if they differ in type, it will be false. |
public | secondsSinceEpoch() : \RedMatter\Chrono\Duration\Seconds Get seconds since epoch |
This class implements \RedMatter\Chrono\Time\TimeInterface, \RedMatter\Chrono\Time\CalendarTimeInterface
Visibility | Function |
---|---|
public | getDateTime(\RedMatter\Chrono\Time\DateTimeZone/null/\DateTimeZone $timeZone=null) : \RedMatter\Chrono\Time\DateTime Get DateTime If no timezone is specified, it is set to '+00:00' except for PHP < 5.5.10. For PHP < 5.5.10 it is set to 'UTC'. |
public | getUnixTime(bool $float=false) : int/float Get unixtime |
Visibility | Function |
---|---|
public | after(\RedMatter\Chrono\Duration\Duration $duration) : \RedMatter\Chrono\Time\static Get time that is after $this by $duration |
public | before(\RedMatter\Chrono\Duration\Duration $duration) : \RedMatter\Chrono\Time\static Get time that is before $this by $duration |
public | diff(\RedMatter\Chrono\Time\TimeInterface $other) : \RedMatter\Chrono\Duration\Duration Get difference between times |
public | isAfter(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $this falls after $other. |
public | isBefore(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $this falls before $other. |
public | isEqual(\RedMatter\Chrono\Time\TimeInterface $other) : bool Check if $other time is equal to $this; if they differ in type, it will be false. |
public | secondsSinceEpoch() : \RedMatter\Chrono\Duration\Seconds Get seconds since epoch |