code
stringlengths 31
707k
| docstring
stringlengths 23
14.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
public function endOfCentury(): static
{
$y = $this->year - 1
- ($this->year - 1)
% Chronos::YEARS_PER_CENTURY
+ Chronos::YEARS_PER_CENTURY;
$year = $this->endOfYear()
->year($y)
->year;
return $this->modify("last day of december $year");
}
|
Resets the date to end of the century and time to 23:59:59
@return static
|
endOfCentury
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function startOfWeek(): static
{
$dateTime = $this;
if ($dateTime->dayOfWeek !== Chronos::getWeekStartsAt()) {
$dateTime = $dateTime->previous(Chronos::getWeekStartsAt());
}
return $dateTime;
}
|
Resets the date to the first day of week (defined in $weekStartsAt)
@return static
|
startOfWeek
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function endOfWeek(): static
{
$dateTime = $this;
if ($dateTime->dayOfWeek !== Chronos::getWeekEndsAt()) {
$dateTime = $dateTime->next(Chronos::getWeekEndsAt());
}
return $dateTime;
}
|
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
@return static
|
endOfWeek
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function equals(ChronosDate $other): bool
{
return $this->native == $other->native;
}
|
Determines if the instance is equal to another
@param \Cake\Chronos\ChronosDate $other The instance to compare with.
@return bool
|
equals
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function notEquals(ChronosDate $other): bool
{
return !$this->equals($other);
}
|
Determines if the instance is not equal to another
@param \Cake\Chronos\ChronosDate $other The instance to compare with.
@return bool
|
notEquals
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function greaterThan(ChronosDate $other): bool
{
return $this->native > $other->native;
}
|
Determines if the instance is greater (after) than another
@param \Cake\Chronos\ChronosDate $other The instance to compare with.
@return bool
|
greaterThan
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function greaterThanOrEquals(ChronosDate $other): bool
{
return $this->native >= $other->native;
}
|
Determines if the instance is greater (after) than or equal to another
@param \Cake\Chronos\ChronosDate $other The instance to compare with.
@return bool
|
greaterThanOrEquals
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function lessThan(ChronosDate $other): bool
{
return $this->native < $other->native;
}
|
Determines if the instance is less (before) than another
@param \Cake\Chronos\ChronosDate $other The instance to compare with.
@return bool
|
lessThan
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function lessThanOrEquals(ChronosDate $other): bool
{
return $this->native <= $other->native;
}
|
Determines if the instance is less (before) or equal to another
@param \Cake\Chronos\ChronosDate $other The instance to compare with.
@return bool
|
lessThanOrEquals
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function between(ChronosDate $start, ChronosDate $end, bool $equals = true): bool
{
if ($start->greaterThan($end)) {
[$start, $end] = [$end, $start];
}
if ($equals) {
return $this->greaterThanOrEquals($start) && $this->lessThanOrEquals($end);
}
return $this->greaterThan($start) && $this->lessThan($end);
}
|
Determines if the instance is between two others
@param \Cake\Chronos\ChronosDate $start Start of target range
@param \Cake\Chronos\ChronosDate $end End of target range
@param bool $equals Whether to include the beginning and end of range
@return bool
|
between
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function closest(ChronosDate $first, ChronosDate $second, ChronosDate ...$others): ChronosDate
{
$closest = $first;
$closestDiffInDays = $this->diffInDays($first);
foreach ([$second, ...$others] as $other) {
$otherDiffInDays = $this->diffInDays($other);
if ($otherDiffInDays < $closestDiffInDays) {
$closest = $other;
$closestDiffInDays = $otherDiffInDays;
}
}
return $closest;
}
|
Get the closest date from the instance.
@param \Cake\Chronos\ChronosDate $first The instance to compare with.
@param \Cake\Chronos\ChronosDate $second The instance to compare with.
@param \Cake\Chronos\ChronosDate ...$others Others instance to compare with.
@return self
|
closest
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function farthest(ChronosDate $first, ChronosDate $second, ChronosDate ...$others): ChronosDate
{
$farthest = $first;
$farthestDiffInDays = $this->diffInDays($first);
foreach ([$second, ...$others] as $other) {
$otherDiffInDays = $this->diffInDays($other);
if ($otherDiffInDays > $farthestDiffInDays) {
$farthest = $other;
$farthestDiffInDays = $otherDiffInDays;
}
}
return $farthest;
}
|
Get the farthest date from the instance.
@param \Cake\Chronos\ChronosDate $first The instance to compare with.
@param \Cake\Chronos\ChronosDate $second The instance to compare with.
@param \Cake\Chronos\ChronosDate ...$others Others instance to compare with.
@return self
|
farthest
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isYesterday(DateTimeZone|string|null $timezone = null): bool
{
return $this->equals(static::yesterday($timezone));
}
|
Determines if the instance is yesterday
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isYesterday
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isToday(DateTimeZone|string|null $timezone = null): bool
{
return $this->equals(static::now($timezone));
}
|
Determines if the instance is today
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isToday
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isTomorrow(DateTimeZone|string|null $timezone = null): bool
{
return $this->equals(static::tomorrow($timezone));
}
|
Determines if the instance is tomorrow
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isTomorrow
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isNextWeek(DateTimeZone|string|null $timezone = null): bool
{
return $this->format('W o') === static::now($timezone)->addWeeks(1)->format('W o');
}
|
Determines if the instance is within the next week
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isNextWeek
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isLastWeek(DateTimeZone|string|null $timezone = null): bool
{
return $this->format('W o') === static::now($timezone)->subWeeks(1)->format('W o');
}
|
Determines if the instance is within the last week
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isLastWeek
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isNextMonth(DateTimeZone|string|null $timezone = null): bool
{
return $this->format('m Y') === static::now($timezone)->addMonths(1)->format('m Y');
}
|
Determines if the instance is within the next month
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isNextMonth
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isLastMonth(DateTimeZone|string|null $timezone = null): bool
{
return $this->format('m Y') === static::now($timezone)->subMonths(1)->format('m Y');
}
|
Determines if the instance is within the last month
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isLastMonth
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isNextYear(DateTimeZone|string|null $timezone = null): bool
{
return $this->year === static::now($timezone)->addYears(1)->year;
}
|
Determines if the instance is within the next year
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isNextYear
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isLastYear(DateTimeZone|string|null $timezone = null): bool
{
return $this->year === static::now($timezone)->subYears(1)->year;
}
|
Determines if the instance is within the last year
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isLastYear
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isFuture(DateTimeZone|string|null $timezone = null): bool
{
return $this->greaterThan(static::now($timezone));
}
|
Determines if the instance is in the future, ie. greater (after) than now
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isFuture
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function isPast(DateTimeZone|string|null $timezone = null): bool
{
return $this->lessThan(static::now($timezone));
}
|
Determines if the instance is in the past, ie. less (before) than now
@param \DateTimeZone|string|null $timezone Time zone to use for now.
@return bool
|
isPast
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffFiltered(
DateInterval $interval,
callable $callback,
?ChronosDate $other = null,
bool $absolute = true,
int $options = 0,
): int {
$start = $this;
$end = $other ?? new ChronosDate(Chronos::now());
$inverse = false;
if ($end < $start) {
$start = $end;
$end = $this;
$inverse = true;
}
// Hack around PHP's DatePeriod not counting equal dates at midnight as
// within the range. Sadly INCLUDE_END_DATE doesn't land until 8.2
$endTime = $end->native->modify('+1 second');
$period = new DatePeriod($start->native, $interval, $endTime, $options);
$vals = array_filter(iterator_to_array($period), function (DateTimeInterface $date) use ($callback) {
return $callback(static::parse($date));
});
$diff = count($vals);
return $inverse && !$absolute ? -$diff : $diff;
}
|
Get the difference by the given interval using a filter callable
@param \DateInterval $interval An interval to traverse by
@param callable $callback The callback to use for filtering.
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php}
@return int
|
diffFiltered
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffInYears(?ChronosDate $other = null, bool $absolute = true): int
{
$diff = $this->diff($other ?? new static(new Chronos()), $absolute);
return $diff->invert ? -$diff->y : $diff->y;
}
|
Get the difference in years
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@return int
|
diffInYears
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffInMonths(?ChronosDate $other = null, bool $absolute = true): int
{
$diff = $this->diff($other ?? new static(Chronos::now()), $absolute);
$months = $diff->y * Chronos::MONTHS_PER_YEAR + $diff->m;
return $diff->invert ? -$months : $months;
}
|
Get the difference in months
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@return int
|
diffInMonths
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffInWeeks(?ChronosDate $other = null, bool $absolute = true): int
{
return (int)($this->diffInDays($other, $absolute) / Chronos::DAYS_PER_WEEK);
}
|
Get the difference in weeks
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@return int
|
diffInWeeks
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffInDays(?ChronosDate $other = null, bool $absolute = true): int
{
$diff = $this->diff($other ?? new static(Chronos::now()), $absolute);
return $diff->invert ? -(int)$diff->days : (int)$diff->days;
}
|
Get the difference in days
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@return int
|
diffInDays
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffInDaysFiltered(
callable $callback,
?ChronosDate $other = null,
bool $absolute = true,
int $options = 0,
): int {
return $this->diffFiltered(new DateInterval('P1D'), $callback, $other, $absolute, $options);
}
|
Get the difference in days using a filter callable
@param callable $callback The callback to use for filtering.
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php}
@return int
|
diffInDaysFiltered
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffInWeekdays(?ChronosDate $other = null, bool $absolute = true, int $options = 0): int
{
return $this->diffInDaysFiltered(function (ChronosDate $date) {
return $date->isWeekday();
}, $other, $absolute, $options);
}
|
Get the difference in weekdays
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php}
@return int
|
diffInWeekdays
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffInWeekendDays(?ChronosDate $other = null, bool $absolute = true, int $options = 0): int
{
return $this->diffInDaysFiltered(function (ChronosDate $date) {
return $date->isWeekend();
}, $other, $absolute, $options);
}
|
Get the difference in weekend days using a filter
@param \Cake\Chronos\ChronosDate|null $other The instance to difference from.
@param bool $absolute Get the absolute of the difference
@param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php}
@return int
|
diffInWeekendDays
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function diffForHumans(?ChronosDate $other = null, bool $absolute = false): string
{
return static::diffFormatter()->diffForHumans($this, $other, $absolute);
}
|
Get the difference in a human readable format.
When comparing a value in the past to default now:
5 months ago
When comparing a value in the future to default now:
5 months from now
When comparing a value in the past to another value:
5 months before
When comparing a value in the future to another value:
5 months after
@param \Cake\Chronos\ChronosDate|null $other The datetime to compare with.
@param bool $absolute removes difference modifiers ago, after, etc
@return string
|
diffForHumans
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable
{
if ($timezone === null) {
return $this->native;
}
$timezone = is_string($timezone) ? new DateTimeZone($timezone) : $timezone;
return new DateTimeImmutable($this->native->format('Y-m-d H:i:s.u'), $timezone);
}
|
Returns the date as a `DateTimeImmutable` instance at midnight.
@param \DateTimeZone|string|null $timezone Time zone the DateTimeImmutable instance will be in
@return \DateTimeImmutable
|
toDateTimeImmutable
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function toNative(DateTimeZone|string|null $timezone = null): DateTimeImmutable
{
return $this->toDateTimeImmutable($timezone);
}
|
Returns the date as a `DateTimeImmutable` instance at midnight.
Alias of `toDateTimeImmutable()`.
@param \DateTimeZone|string|null $timezone Time zone the DateTimeImmutable instance will be in
@return \DateTimeImmutable
|
toNative
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function __get(string $name): string|float|int|bool
{
static $formats = [
'year' => 'Y',
'yearIso' => 'o',
'month' => 'n',
'day' => 'j',
'dayOfWeek' => 'N',
'dayOfYear' => 'z',
'weekOfYear' => 'W',
'daysInMonth' => 't',
];
switch (true) {
case isset($formats[$name]):
return (int)$this->format($formats[$name]);
case $name === 'dayOfWeekName':
return $this->format('l');
case $name === 'weekOfMonth':
return (int)ceil($this->day / Chronos::DAYS_PER_WEEK);
case $name === 'age':
return $this->diffInYears();
case $name === 'quarter':
return (int)ceil($this->month / 3);
case $name === 'half':
return $this->month <= 6 ? 1 : 2;
default:
throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name));
}
}
|
Get a part of the object
@param string $name The property name to read.
@return string|float|int|bool The property value.
@throws \InvalidArgumentException
|
__get
|
php
|
cakephp/chronos
|
src/ChronosDate.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosDate.php
|
MIT
|
public function __construct(
ChronosTime|DateTimeInterface|string|null $time = null,
DateTimeZone|string|null $timezone = null,
) {
if ($time === null) {
$time = Chronos::getTestNow() ?? Chronos::now();
if ($timezone !== null) {
$time = $time->setTimezone($timezone);
}
$this->ticks = static::parseString($time->format('H:i:s.u'));
} elseif (is_string($time)) {
$this->ticks = static::parseString($time);
} elseif ($time instanceof ChronosTime) {
$this->ticks = $time->ticks;
} else {
$this->ticks = static::parseString($time->format('H:i:s.u'));
}
}
|
Copies time from onther instance or from time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u.
Defaults to server time.
@param \Cake\Chronos\ChronosTime|\DateTimeInterface|string|null $time Time
@param \DateTimeZone|string|null $timezone The timezone to use for now
|
__construct
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public static function parse(
ChronosTime|DateTimeInterface|string|null $time = null,
DateTimeZone|string|null $timezone = null,
): static {
return new static($time, $timezone);
}
|
Copies time from onther instance or from string in the format HH[:.]mm or HH[:.]mm[:.]ss.u
Defaults to server time.
@param \Cake\Chronos\ChronosTime|\DateTimeInterface|string $time Time
@param \DateTimeZone|string|null $timezone The timezone to use for now
@return static
|
parse
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
protected static function parseString(string $time): int
{
if (!preg_match('/^\s*(\d{1,2})[:.](\d{1,2})(?|[:.](\d{1,2})[.](\d+)|[:.](\d{1,2}))?\s*$/', $time, $matches)) {
throw new InvalidArgumentException(
sprintf('Time string `%s` is not in expected format `HH[:.]mm` or `HH[:.]mm[:.]ss.u`.', $time),
);
}
$hours = (int)$matches[1];
$minutes = (int)$matches[2];
$seconds = (int)($matches[3] ?? 0);
$microseconds = (int)substr($matches[4] ?? '', 0, 6);
if ($hours > 24 || $minutes > 59 || $seconds > 59 || $microseconds > 999_999) {
throw new InvalidArgumentException(sprintf('Time string `%s` contains invalid values.', $time));
}
$ticks = $hours * self::TICKS_PER_HOUR;
$ticks += $minutes * self::TICKS_PER_MINUTE;
$ticks += $seconds * self::TICKS_PER_SECOND;
$ticks += $microseconds * self::TICKS_PER_MICROSECOND;
return $ticks % self::TICKS_PER_DAY;
}
|
@param string $time Time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u
@return int
|
parseString
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public static function now(DateTimeZone|string|null $timezone = null): static
{
return new static(null, $timezone);
}
|
Returns instance set to server time.
@param \DateTimeZone|string|null $timezone The timezone to use for now
@return static
|
now
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public static function midnight(): static
{
return new static('00:00:00');
}
|
Returns instance set to midnight.
@return static
|
midnight
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public static function noon(): static
{
return new static('12:00:00');
}
|
Returns instance set to noon.
@return static
|
noon
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public static function endOfDay(bool $microseconds = false): static
{
if ($microseconds) {
return new static('23:59:59.999999');
}
return new static('23:59:59');
}
|
Returns instance set to end of day - either
23:59:59 or 23:59:59.999999 if `$microseconds` is true
@param bool $microseconds Whether to set microseconds or not
@return static
|
endOfDay
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function setMicroseconds(int $microseconds): static
{
$baseTicks = $this->ticks - $this->ticks % self::TICKS_PER_SECOND;
$newTicks = static::mod($baseTicks + $microseconds * self::TICKS_PER_MICROSECOND, self::TICKS_PER_DAY);
$clone = clone $this;
$clone->ticks = $newTicks;
return $clone;
}
|
Sets clock microseconds.
@param int $microseconds Clock microseconds
@return static
|
setMicroseconds
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function setSeconds(int $seconds): static
{
$baseTicks = $this->ticks - ($this->ticks % self::TICKS_PER_MINUTE - $this->ticks % self::TICKS_PER_SECOND);
$newTicks = static::mod($baseTicks + $seconds * self::TICKS_PER_SECOND, self::TICKS_PER_DAY);
$clone = clone $this;
$clone->ticks = $newTicks;
return $clone;
}
|
Set clock seconds.
@param int $seconds Clock seconds
@return static
|
setSeconds
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function setMinutes(int $minutes): static
{
$baseTicks = $this->ticks - ($this->ticks % self::TICKS_PER_HOUR - $this->ticks % self::TICKS_PER_MINUTE);
$newTicks = static::mod($baseTicks + $minutes * self::TICKS_PER_MINUTE, self::TICKS_PER_DAY);
$clone = clone $this;
$clone->ticks = $newTicks;
return $clone;
}
|
Set clock minutes.
@param int $minutes Clock minutes
@return static
|
setMinutes
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function setHours(int $hours): static
{
$baseTicks = $this->ticks - ($this->ticks - $this->ticks % self::TICKS_PER_HOUR);
$newTicks = static::mod($baseTicks + $hours * self::TICKS_PER_HOUR, self::TICKS_PER_DAY);
$clone = clone $this;
$clone->ticks = $newTicks;
return $clone;
}
|
Set clock hours.
@param int $hours Clock hours
@return static
|
setHours
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function setTime(int $hours = 0, int $minutes = 0, int $seconds = 0, int $microseconds = 0): static
{
$ticks = $hours * self::TICKS_PER_HOUR +
$minutes * self::TICKS_PER_MINUTE +
$seconds * self::TICKS_PER_SECOND +
$microseconds * self::TICKS_PER_MICROSECOND;
$ticks = static::mod($ticks, self::TICKS_PER_DAY);
$clone = clone $this;
$clone->ticks = $ticks;
return $clone;
}
|
Sets clock time.
@param int $hours Clock hours
@param int $minutes Clock minutes
@param int $seconds Clock seconds
@param int $microseconds Clock microseconds
@return static
|
setTime
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
protected static function mod(int $a, int $b): int
{
if ($a < 0) {
return $a % $b + $b;
}
return $a % $b;
}
|
@param int $a Left side
@param int $a Right side
@return int
|
mod
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function format(string $format): string
{
return $this->toDateTimeImmutable()->format($format);
}
|
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.
@param string $format Format string
@return string
|
format
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public static function resetToStringFormat(): void
{
static::setToStringFormat(static::DEFAULT_TO_STRING_FORMAT);
}
|
Reset the format used to the default when converting to a string
@return void
|
resetToStringFormat
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public static function setToStringFormat(string $format): void
{
static::$toStringFormat = $format;
}
|
Set the default format used when converting to a string
@param string $format The format to use in future __toString() calls.
@return void
|
setToStringFormat
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function __toString(): string
{
return $this->format(static::$toStringFormat);
}
|
Format the instance as a string using the set format
@return string
|
__toString
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function equals(ChronosTime $target): bool
{
return $this->ticks === $target->ticks;
}
|
Returns whether time is equal to target time.
@param \Cake\Chronos\ChronosTime $target Target time
@return bool
|
equals
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function greaterThan(ChronosTime $target): bool
{
return $this->ticks > $target->ticks;
}
|
Returns whether time is greater than target time.
@param \Cake\Chronos\ChronosTime $target Target time
@return bool
|
greaterThan
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function greaterThanOrEquals(ChronosTime $target): bool
{
return $this->ticks >= $target->ticks;
}
|
Returns whether time is greater than or equal to target time.
@param \Cake\Chronos\ChronosTime $target Target time
@return bool
|
greaterThanOrEquals
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function lessThan(ChronosTime $target): bool
{
return $this->ticks < $target->ticks;
}
|
Returns whether time is less than target time.
@param \Cake\Chronos\ChronosTime $target Target time
@return bool
|
lessThan
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function lessThanOrEquals(ChronosTime $target): bool
{
return $this->ticks <= $target->ticks;
}
|
Returns whether time is less than or equal to target time.
@param \Cake\Chronos\ChronosTime $target Target time
@return bool
|
lessThanOrEquals
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function between(ChronosTime $start, ChronosTime $end, bool $equals = true): bool
{
if ($start->greaterThan($end)) {
[$start, $end] = [$end, $start];
}
if ($equals) {
return $this->greaterThanOrEquals($start) && $this->lessThanOrEquals($end);
}
return $this->greaterThan($start) && $this->lessThan($end);
}
|
Returns whether time is between time range.
@param \Cake\Chronos\ChronosTime $start Start of target range
@param \Cake\Chronos\ChronosTime $end End of target range
@param bool $equals Whether to include the beginning and end of range
@return bool
|
between
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable
{
$timezone = is_string($timezone) ? new DateTimeZone($timezone) : $timezone;
return (new DateTimeImmutable(timezone: $timezone))->setTime(
$this->getHours(),
$this->getMinutes(),
$this->getSeconds(),
$this->getMicroseconds(),
);
}
|
Returns an `DateTimeImmutable` instance set to this clock time.
@param \DateTimeZone|string|null $timezone Time zone the DateTimeImmutable instance will be in
@return \DateTimeImmutable
|
toDateTimeImmutable
|
php
|
cakephp/chronos
|
src/ChronosTime.php
|
https://github.com/cakephp/chronos/blob/master/src/ChronosTime.php
|
MIT
|
public function __construct(DateTimeZone|string|null $timezone = null)
{
$this->timezone = $timezone;
}
|
Constructor.
@param \DateTimeZone|string|null $timezone The timezone
|
__construct
|
php
|
cakephp/chronos
|
src/ClockFactory.php
|
https://github.com/cakephp/chronos/blob/master/src/ClockFactory.php
|
MIT
|
public function now(): DateTimeImmutable
{
return Chronos::now($this->timezone);
}
|
Returns the current time object.
@return \Cake\Chronos\Chronos The current time
|
now
|
php
|
cakephp/chronos
|
src/ClockFactory.php
|
https://github.com/cakephp/chronos/blob/master/src/ClockFactory.php
|
MIT
|
public function __construct(?Translator $translate = null)
{
$this->translate = $translate ?: new Translator();
}
|
Constructor.
@param \Cake\Chronos\Translator|null $translate The text translator object.
|
__construct
|
php
|
cakephp/chronos
|
src/DifferenceFormatter.php
|
https://github.com/cakephp/chronos/blob/master/src/DifferenceFormatter.php
|
MIT
|
public function toDateString(): string
{
return $this->format('Y-m-d');
}
|
Format the instance as date
@return string
|
toDateString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toFormattedDateString(): string
{
return $this->format('M j, Y');
}
|
Format the instance as a readable date
@return string
|
toFormattedDateString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toTimeString(): string
{
return $this->format('H:i:s');
}
|
Format the instance as time
@return string
|
toTimeString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toDateTimeString(): string
{
return $this->format('Y-m-d H:i:s');
}
|
Format the instance as date and time
@return string
|
toDateTimeString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toDayDateTimeString(): string
{
return $this->format('D, M j, Y g:i A');
}
|
Format the instance with day, date and time
@return string
|
toDayDateTimeString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toAtomString(): string
{
return $this->format(DateTime::ATOM);
}
|
Format the instance as ATOM
@return string
|
toAtomString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toCookieString(): string
{
return $this->format(DateTime::COOKIE);
}
|
Format the instance as COOKIE
@return string
|
toCookieString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toIso8601String(): string
{
return $this->format(DateTime::ATOM);
}
|
Format the instance as ISO8601
@return string
|
toIso8601String
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toRfc822String(): string
{
return $this->format(DateTime::RFC822);
}
|
Format the instance as RFC822
@return string
@link https://tools.ietf.org/html/rfc822
|
toRfc822String
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toRfc850String(): string
{
return $this->format(DateTime::RFC850);
}
|
Format the instance as RFC850
@return string
@link https://tools.ietf.org/html/rfc850
|
toRfc850String
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toRfc1036String(): string
{
return $this->format(DateTime::RFC1036);
}
|
Format the instance as RFC1036
@return string
@link https://tools.ietf.org/html/rfc1036
|
toRfc1036String
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toRfc1123String(): string
{
return $this->format(DateTime::RFC1123);
}
|
Format the instance as RFC1123
@return string
@link https://tools.ietf.org/html/rfc1123
|
toRfc1123String
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toRfc2822String(): string
{
return $this->format(DateTime::RFC2822);
}
|
Format the instance as RFC2822
@return string
@link https://tools.ietf.org/html/rfc2822
|
toRfc2822String
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toRfc3339String(): string
{
return $this->format(DateTime::RFC3339);
}
|
Format the instance as RFC3339
@return string
@link https://tools.ietf.org/html/rfc3339
|
toRfc3339String
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toRssString(): string
{
return $this->format(DateTime::RSS);
}
|
Format the instance as RSS
@return string
|
toRssString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toW3cString(): string
{
return $this->format(DateTime::W3C);
}
|
Format the instance as W3C
@return string
|
toW3cString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toUnixString(): string
{
return $this->format('U');
}
|
Returns a UNIX timestamp.
@return string UNIX timestamp
|
toUnixString
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toQuarter(bool $range = false): int|array
{
$quarter = (int)ceil((int)$this->format('m') / 3);
if ($range === false) {
return $quarter;
}
$year = $this->format('Y');
switch ($quarter) {
case 1:
return [$year . '-01-01', $year . '-03-31'];
case 2:
return [$year . '-04-01', $year . '-06-30'];
case 3:
return [$year . '-07-01', $year . '-09-30'];
default:
return [$year . '-10-01', $year . '-12-31'];
}
}
|
Returns the quarter
@param bool $range Range.
@return array|int 1, 2, 3, or 4 quarter of year or array if $range true
|
toQuarter
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function toWeek(): int
{
return (int)$this->format('W');
}
|
Returns ISO 8601 week number of year, weeks starting on Monday
@return int ISO 8601 week number of year
|
toWeek
|
php
|
cakephp/chronos
|
src/FormattingTrait.php
|
https://github.com/cakephp/chronos/blob/master/src/FormattingTrait.php
|
MIT
|
public function exists(string $key): bool
{
return isset(static::$strings[$key]);
}
|
Check if a translation key exists.
@param string $key The key to check.
@return bool Whether the key exists.
|
exists
|
php
|
cakephp/chronos
|
src/Translator.php
|
https://github.com/cakephp/chronos/blob/master/src/Translator.php
|
MIT
|
public function plural(string $key, int $count, array $vars = []): string
{
if ($count === 1) {
return $this->singular($key, $vars);
}
return $this->singular($key . '_plural', ['count' => $count] + $vars);
}
|
Get a plural message.
@param string $key The key to use.
@param int $count The number of items in the translation.
@param array $vars Additional context variables.
@return string The translated message or ''.
|
plural
|
php
|
cakephp/chronos
|
src/Translator.php
|
https://github.com/cakephp/chronos/blob/master/src/Translator.php
|
MIT
|
public function singular(string $key, array $vars = []): string
{
if (isset(static::$strings[$key])) {
$varKeys = array_keys($vars);
foreach ($varKeys as $i => $k) {
$varKeys[$i] = '{' . $k . '}';
}
return str_replace($varKeys, $vars, static::$strings[$key]);
}
return '';
}
|
Get a singular message.
@param string $key The key to use.
@param array $vars Additional context variables.
@return string The translated message or ''.
|
singular
|
php
|
cakephp/chronos
|
src/Translator.php
|
https://github.com/cakephp/chronos/blob/master/src/Translator.php
|
MIT
|
public function deprecated(Closure $callable): void
{
/** @var bool $deprecation Expand type for psalm */
$deprecation = false;
$previousHandler = set_error_handler(
function ($code, $message, $file, $line, $context = null) use (&$previousHandler, &$deprecation): bool {
if ($code == E_USER_DEPRECATED) {
$deprecation = true;
return true;
}
if ($previousHandler) {
return $previousHandler($code, $message, $file, $line, $context);
}
return false;
},
);
try {
$callable();
} finally {
restore_error_handler();
}
$this->assertTrue($deprecation, 'Should have at least one deprecation warning');
}
|
Helper method for check deprecation methods
@param \Closure $callable callable function that will receive asserts
@return void
|
deprecated
|
php
|
cakephp/chronos
|
tests/TestCase/TestCase.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/TestCase.php
|
MIT
|
public static function inputTimeProvider()
{
return [
['@' . strtotime('2015-08-19 22:24:32')],
['2015-08-19 10:00:00'],
['2015-08-19T10:00:00+05:00'],
['Monday, 15-Aug-2005 15:52:01 UTC'],
['Mon, 15 Aug 05 15:52:01 +0000'],
['Monday, 15-Aug-05 15:52:01 UTC'],
['Mon, 15 Aug 05 15:52:01 +0000'],
['Mon, 15 Aug 2005 15:52:01 +0000'],
['Mon, 15 Aug 2005 15:52:01 +0000'],
['Mon, 15 Aug 2005 15:52:01 +0000'],
['2005-08-15T15:52:01+00:00'],
['20050815'],
];
}
|
Data provider for constructor testing.
@return array
|
inputTimeProvider
|
php
|
cakephp/chronos
|
tests/TestCase/Date/ConstructTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/Date/ConstructTest.php
|
MIT
|
public function testConstructWithLargeTimezoneChange(): void
{
date_default_timezone_set('Pacific/Kiritimati');
$samoaTimezone = new DateTimeZone('Pacific/Samoa');
// Pacific/Samoa -11:00 is used intead of local timezone +14:00
$c = ChronosDate::today($samoaTimezone);
$samoa = new DateTimeImmutable('now', $samoaTimezone);
$this->assertSame($samoa->format('Y-m-d'), $c->format('Y-m-d'));
}
|
This tests with a large difference between local timezone and
timezone provided as parameter. This is to help guarantee a date
change would occur so the tests are more consistent.
|
testConstructWithLargeTimezoneChange
|
php
|
cakephp/chronos
|
tests/TestCase/Date/ConstructTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/Date/ConstructTest.php
|
MIT
|
public function testAddYearPassingArg()
{
$this->assertSame(1977, Chronos::createFromDate(1975)->addYears(2)->year);
}
|
** Test non plural methods with non default args ****
|
testAddYearPassingArg
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/AddTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/AddTest.php
|
MIT
|
public function testFromNow()
{
$date = Chronos::now();
$date = $date->modify('-1 year')
->modify('-6 days')
->modify('-51 seconds');
$interval = Chronos::fromNow($date);
$result = $interval->format('%y %m %d %H %i %s');
$this->assertSame($result, '1 0 6 00 0 51');
}
|
Tests the "from now" time calculation.
|
testFromNow
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/DiffTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/DiffTest.php
|
MIT
|
public function testTimestamp()
{
$date = Chronos::createFromTimestamp(0)->setTimezone('+02:00');
$this->assertSame('0', $date->format('U'));
}
|
Ensures that $date->format('U') returns unchanged timestamp
|
testTimestamp
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/PhpBug72338Test.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/PhpBug72338Test.php
|
MIT
|
public function testEqualSetAndCreate()
{
$date = Chronos::createFromTimestamp(0)->setTimezone('+02:00');
$date1 = new Chronos('1970-01-01T02:00:00+02:00');
$this->assertSame($date->format('U'), $date1->format('U'));
}
|
Ensures that date created from string with timezone and with same timezone set by setTimezone() is equal
|
testEqualSetAndCreate
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/PhpBug72338Test.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/PhpBug72338Test.php
|
MIT
|
public function testSecondSetTimezone()
{
$date = Chronos::createFromTimestamp(0)->setTimezone('+02:00')->setTimezone('Europe/Moscow');
$this->assertSame('0', $date->format('U'));
}
|
Ensures that second call to setTimezone() dont changing timestamp
|
testSecondSetTimezone
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/PhpBug72338Test.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/PhpBug72338Test.php
|
MIT
|
public static function toQuarterProvider()
{
return [
['2007-12-25', 4],
['2007-9-25', 3],
['2007-3-25', 1],
['2007-3-25', ['2007-01-01', '2007-03-31'], true],
['2007-5-25', ['2007-04-01', '2007-06-30'], true],
['2007-8-25', ['2007-07-01', '2007-09-30'], true],
['2007-12-25', ['2007-10-01', '2007-12-31'], true],
];
}
|
Provides values and expectations for the toQuarter method
@return array
|
toQuarterProvider
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/StringsTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/StringsTest.php
|
MIT
|
public static function toWeekProvider()
{
return [
['2007-1-1', 1],
['2007-3-25', 12],
['2007-12-29', 52],
['2007-12-31', 1],
];
}
|
Provides values and expectations for the toWeek method
@return array
|
toWeekProvider
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/StringsTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/StringsTest.php
|
MIT
|
public function testNowNoMutateDateTime()
{
$value = '2018-06-21 10:11:12';
$notNow = new Chronos($value);
Chronos::setTestNow($notNow);
$instance = new Chronos('-10 minutes');
$this->assertSame('10:01:12', $instance->format('H:i:s'));
$instance = new Chronos('-10 minutes');
$this->assertSame('10:01:12', $instance->format('H:i:s'));
}
|
Ensure that using test now doesn't mutate test now.
|
testNowNoMutateDateTime
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/TestingAidsTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/TestingAidsTest.php
|
MIT
|
public function testParseRelativeWithTimezoneAndTestValueSet()
{
$notNow = Chronos::parse('2013-07-01 12:00:00', 'America/New_York');
Chronos::setTestNow($notNow);
$this->assertSame('06:30:00', Chronos::parse('2013-07-01 06:30:00', 'America/Mexico_City')->toTimeString());
$this->assertSame('06:30:00', Chronos::parse('6:30', 'America/Mexico_City')->toTimeString());
$this->assertSame('2013-07-01T06:30:00-04:00', Chronos::parse('2013-07-01 06:30:00')->toIso8601String());
$this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('2013-07-01 06:30:00', 'America/Mexico_City')->toIso8601String());
$this->assertSame('2013-07-01T06:30:00-04:00', Chronos::parse('06:30')->toIso8601String());
$this->assertSame('2013-07-01T06:30:00-04:00', Chronos::parse('6:30')->toIso8601String());
$this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('6:30', 'America/Mexico_City')->toIso8601String());
$this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('6:30:00', 'America/Mexico_City')->toIso8601String());
$this->assertSame('2013-07-01T06:30:00-05:00', Chronos::parse('06:30:00', 'America/Mexico_City')->toIso8601String());
}
|
Test parse() with relative values and timezones
|
testParseRelativeWithTimezoneAndTestValueSet
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/TestingAidsTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/TestingAidsTest.php
|
MIT
|
public function testSetTestNowSingular()
{
$c = new Chronos('2016-01-03 00:00:00', 'Europe/Copenhagen');
Chronos::setTestNow($c);
$this->assertSame($c, Chronos::getTestNow());
}
|
Test that setting testNow() on one class sets it on all of the chronos classes.
|
testSetTestNowSingular
|
php
|
cakephp/chronos
|
tests/TestCase/DateTime/TestingAidsTest.php
|
https://github.com/cakephp/chronos/blob/master/tests/TestCase/DateTime/TestingAidsTest.php
|
MIT
|
public function __construct($environment, $debug)
{
parent::__construct($environment, $debug);
$this->setContext(self::CONTEXT_ADMIN);
}
|
@param string $environment
@param bool $debug
|
__construct
|
php
|
sulu/sulu-standard
|
app/AdminKernel.php
|
https://github.com/sulu/sulu-standard/blob/master/app/AdminKernel.php
|
MIT
|
public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false)
{
$this->fulfilled = (bool) $fulfilled;
$this->testMessage = (string) $testMessage;
$this->helpHtml = (string) $helpHtml;
$this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText;
$this->optional = (bool) $optional;
}
|
Constructor that initializes the requirement.
@param bool $fulfilled Whether the requirement is fulfilled
@param string $testMessage The message for testing the requirement
@param string $helpHtml The help text formatted in HTML for resolving the problem
@param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
@param bool $optional Whether this is only an optional recommendation not a mandatory requirement
|
__construct
|
php
|
sulu/sulu-standard
|
app/SymfonyRequirements.php
|
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
|
MIT
|
public function isFulfilled()
{
return $this->fulfilled;
}
|
Returns whether the requirement is fulfilled.
@return bool true if fulfilled, otherwise false
|
isFulfilled
|
php
|
sulu/sulu-standard
|
app/SymfonyRequirements.php
|
https://github.com/sulu/sulu-standard/blob/master/app/SymfonyRequirements.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.