Class ChronosTime
Constants
Property Summary
-
$ticks protected
int
-
$toStringFormat protected static
string
Format to use for __toString method.
Method Summary
-
__construct() public
Copies time from onther instance or from time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u.
-
__toString() public
Format the instance as a string using the set format
-
between() public
Returns whether time is between time range.
-
endOfDay() public static
Returns instance set to end of day - either 23:59:59 or 23:59:59.999999 if
$microseconds
is true -
equals() public
Returns whether time is equal to target time.
-
format() public
Formats string using the same syntax as
DateTimeImmutable::format()
. -
getHours() public
Returns clock hours.
-
getMicroseconds() public
Returns clock microseconds.
-
getMinutes() public
Returns clock minutes.
-
getSeconds() public
Return clock seconds.
-
greaterThan() public
Returns whether time is greater than target time.
-
greaterThanOrEquals() public
Returns whether time is greater than or equal to target time.
-
lessThan() public
Returns whether time is less than target time.
-
lessThanOrEquals() public
Returns whether time is less than or equal to target time.
-
midnight() public static
Returns instance set to midnight.
-
mod() protected static
-
noon() public static
Returns instance set to noon.
-
now() public static
Returns instance set to server time.
-
parse() public static
Copies time from onther instance or from string in the format HH[:.]mm or HH[:.]mm[:.]ss.u
-
parseString() protected static
-
resetToStringFormat() public static
Reset the format used to the default when converting to a string
-
setHours() public
Set clock hours.
-
setMicroseconds() public
Sets clock microseconds.
-
setMinutes() public
Set clock minutes.
-
setSeconds() public
Set clock seconds.
-
setTime() public
Sets clock time.
-
setToStringFormat() public static
Set the default format used when converting to a string
-
toDateTimeImmutable() public
Returns an
DateTimeImmutable
instance set to this clock time. -
toNative() public
Returns an
DateTimeImmutable
instance set to this clock time.
Method Detail
__construct() ¶ public
__construct(Cake\Chronos\ChronosTimeDateTimeInterface|string|null $time = null, DateTimeZone|string|null $timezone = null)
Copies time from onther instance or from time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u.
Defaults to server time.
Parameters
-
Cake\Chronos\ChronosTimeDateTimeInterface|string|null
$time optional Time
-
DateTimeZone|string|null
$timezone optional The timezone to use for now
__toString() ¶ public
__toString(): string
Format the instance as a string using the set format
Returns
string
between() ¶ public
between(Cake\Chronos\ChronosTime $start, Cake\Chronos\ChronosTime $end, bool $equals = true): bool
Returns whether time is between time range.
Parameters
-
Cake\Chronos\ChronosTime
$start Start of target range
-
Cake\Chronos\ChronosTime
$end End of target range
-
bool
$equals optional Whether to include the beginning and end of range
Returns
bool
endOfDay() ¶ public static
endOfDay(bool $microseconds = false): static
Returns instance set to end of day - either
23:59:59 or 23:59:59.999999 if $microseconds
is true
Parameters
-
bool
$microseconds optional Whether to set microseconds or not
Returns
static
equals() ¶ public
equals(Cake\Chronos\ChronosTime $target): bool
Returns whether time is equal to target time.
Parameters
-
Cake\Chronos\ChronosTime
$target Target time
Returns
bool
format() ¶ public
format(string $format): string
Formats string using the same syntax as DateTimeImmutable::format()
.
As this uses DateTimeImmutable::format() to format the string, non-time formatters will still be interpreted. Be sure to escape those characters first.
Parameters
-
string
$format Format string
Returns
string
greaterThan() ¶ public
greaterThan(Cake\Chronos\ChronosTime $target): bool
Returns whether time is greater than target time.
Parameters
-
Cake\Chronos\ChronosTime
$target Target time
Returns
bool
greaterThanOrEquals() ¶ public
greaterThanOrEquals(Cake\Chronos\ChronosTime $target): bool
Returns whether time is greater than or equal to target time.
Parameters
-
Cake\Chronos\ChronosTime
$target Target time
Returns
bool
lessThan() ¶ public
lessThan(Cake\Chronos\ChronosTime $target): bool
Returns whether time is less than target time.
Parameters
-
Cake\Chronos\ChronosTime
$target Target time
Returns
bool
lessThanOrEquals() ¶ public
lessThanOrEquals(Cake\Chronos\ChronosTime $target): bool
Returns whether time is less than or equal to target time.
Parameters
-
Cake\Chronos\ChronosTime
$target Target time
Returns
bool
now() ¶ public static
now(DateTimeZone|string|null $timezone = null): static
Returns instance set to server time.
Parameters
-
DateTimeZone|string|null
$timezone optional The timezone to use for now
Returns
static
parse() ¶ public static
parse(Cake\Chronos\ChronosTimeDateTimeInterface|string $time = null, DateTimeZone|string|null $timezone = null): static
Copies time from onther instance or from string in the format HH[:.]mm or HH[:.]mm[:.]ss.u
Defaults to server time.
Parameters
-
Cake\Chronos\ChronosTimeDateTimeInterface|string
$time optional Time
-
DateTimeZone|string|null
$timezone optional The timezone to use for now
Returns
static
parseString() ¶ protected static
parseString(string $time): int
Parameters
-
string
$time Time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u
Returns
int
resetToStringFormat() ¶ public static
resetToStringFormat(): void
Reset the format used to the default when converting to a string
Returns
void
setHours() ¶ public
setHours(int $hours): static
Set clock hours.
Parameters
-
int
$hours Clock hours
Returns
static
setMicroseconds() ¶ public
setMicroseconds(int $microseconds): static
Sets clock microseconds.
Parameters
-
int
$microseconds Clock microseconds
Returns
static
setMinutes() ¶ public
setMinutes(int $minutes): static
Set clock minutes.
Parameters
-
int
$minutes Clock minutes
Returns
static
setSeconds() ¶ public
setSeconds(int $seconds): static
Set clock seconds.
Parameters
-
int
$seconds Clock seconds
Returns
static
setTime() ¶ public
setTime(int $hours = 0, int $minutes = 0, int $seconds = 0, int $microseconds = 0): static
Sets clock time.
Parameters
-
int
$hours optional Clock hours
-
int
$minutes optional Clock minutes
-
int
$seconds optional Clock seconds
-
int
$microseconds optional Clock microseconds
Returns
static
setToStringFormat() ¶ public static
setToStringFormat(string $format): void
Set the default format used when converting to a string
Parameters
-
string
$format The format to use in future __toString() calls.
Returns
void
toDateTimeImmutable() ¶ public
toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable
Returns an DateTimeImmutable
instance set to this clock time.
Parameters
-
DateTimeZone|string|null
$timezone optional Time zone the DateTimeImmutable instance will be in
Returns
DateTimeImmutable
toNative() ¶ public
toNative(DateTimeZone|string|null $timezone = null): DateTimeImmutable
Returns an DateTimeImmutable
instance set to this clock time.
Alias of toDateTimeImmutable()
.
Parameters
-
DateTimeZone|string|null
$timezone optional Time zone the DateTimeImmutable instance will be in
Returns
DateTimeImmutable