Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/Chronos.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Chronos extends DateTimeImmutable implements Stringable
*/
public function __construct(
ChronosDate|ChronosTime|DateTimeInterface|string|int|null $time = 'now',
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
) {
if (is_int($time) || (is_string($time) && ctype_digit($time))) {
parent::__construct("@{$time}");
Expand Down Expand Up @@ -468,7 +468,7 @@ public static function instance(DateTimeInterface $other): static
*/
public static function parse(
ChronosDate|ChronosTime|DateTimeInterface|string|int|null $time = 'now',
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
): static {
return new static($time, $timezone);
}
Expand Down Expand Up @@ -568,7 +568,7 @@ public static function create(
?int $minute = null,
?int $second = null,
?int $microsecond = null,
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
): static {
$now = static::now();
$year = $year ?? (int)$now->format('Y');
Expand All @@ -589,7 +589,7 @@ public static function create(
$instance = static::createFromFormat(
'Y-m-d H:i:s.u',
sprintf('%s-%s-%s %s:%02s:%02s.%06s', 0, $month, $day, $hour, $minute, $second, $microsecond),
$timezone
$timezone,
);

return $instance->addYears($year);
Expand All @@ -608,7 +608,7 @@ public static function createFromDate(
?int $year = null,
?int $month = null,
?int $day = null,
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
): static {
return static::create($year, $month, $day, null, null, null, null, $timezone);
}
Expand All @@ -628,7 +628,7 @@ public static function createFromTime(
?int $minute = null,
?int $second = null,
?int $microsecond = null,
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
): static {
return static::create(null, null, null, $hour, $minute, $second, $microsecond, $timezone);
}
Expand All @@ -645,7 +645,7 @@ public static function createFromTime(
public static function createFromFormat(
string $format,
string $time,
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
): static {
if ($timezone !== null) {
$dateTime = parent::createFromFormat($format, $time, $timezone ? static::safeCreateDateTimeZone($timezone) : null);
Expand Down Expand Up @@ -725,7 +725,7 @@ public static function createFromArray(array $values): static
$values['hour'],
$values['minute'],
$values['second'],
$values['microsecond']
$values['microsecond'],
);

assert(!is_int($values['timezone']), 'Timezone cannot be of type `int`');
Expand Down Expand Up @@ -880,7 +880,7 @@ public function setDateTime(
int $day,
int $hour,
int $minute,
int $second = 0
int $second = 0,
): static {
return $this->setDate($year, $month, $day)->setTime($hour, $minute, $second);
}
Expand Down Expand Up @@ -2317,7 +2317,7 @@ public function diffFiltered(
callable $callback,
?DateTimeInterface $other = null,
bool $absolute = true,
int $options = 0
int $options = 0,
): int {
$start = $this;
$end = $other ?? static::now($this->tz);
Expand Down Expand Up @@ -2430,7 +2430,7 @@ public function diffInDaysFiltered(
callable $callback,
?DateTimeInterface $other = null,
bool $absolute = true,
int $options = 0
int $options = 0,
): int {
return $this->diffFiltered(new DateInterval('P1D'), $callback, $other, $absolute, $options);
}
Expand All @@ -2448,7 +2448,7 @@ public function diffInHoursFiltered(
callable $callback,
?DateTimeInterface $other = null,
bool $absolute = true,
int $options = 0
int $options = 0,
): int {
return $this->diffFiltered(new DateInterval('PT1H'), $callback, $other, $absolute, $options);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ChronosDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ChronosDate implements Stringable
*/
public function __construct(
ChronosDate|DateTimeInterface|string $time = 'now',
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
) {
$this->native = $this->createNative($time, $timezone);
}
Expand All @@ -127,7 +127,7 @@ public function __construct(
*/
protected function createNative(
ChronosDate|DateTimeInterface|string $time,
DateTimeZone|string|null $timezone
DateTimeZone|string|null $timezone,
): DateTimeImmutable {
if (!is_string($time)) {
return new DateTimeImmutable($time->format('Y-m-d 00:00:00'));
Expand Down Expand Up @@ -1425,7 +1425,7 @@ public function diffFiltered(
callable $callback,
?ChronosDate $other = null,
bool $absolute = true,
int $options = 0
int $options = 0,
): int {
$start = $this;
$end = $other ?? new ChronosDate(Chronos::now());
Expand Down Expand Up @@ -1518,7 +1518,7 @@ public function diffInDaysFiltered(
callable $callback,
?ChronosDate $other = null,
bool $absolute = true,
int $options = 0
int $options = 0,
): int {
return $this->diffFiltered(new DateInterval('P1D'), $callback, $other, $absolute, $options);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ChronosTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ChronosTime implements Stringable
*/
public function __construct(
ChronosTime|DateTimeInterface|string|null $time = null,
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
) {
if ($time === null) {
$time = Chronos::getTestNow() ?? Chronos::now();
Expand Down Expand Up @@ -107,7 +107,7 @@ public function __construct(
*/
public static function parse(
ChronosTime|DateTimeInterface|string|null $time = null,
DateTimeZone|string|null $timezone = null
DateTimeZone|string|null $timezone = null,
): static {
return new static($time, $timezone);
}
Expand All @@ -120,7 +120,7 @@ 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)
sprintf('Time string `%s` is not in expected format `HH[:.]mm` or `HH[:.]mm[:.]ss.u`.', $time),
);
}

Expand Down Expand Up @@ -474,7 +474,7 @@ public function toDateTimeImmutable(DateTimeZone|string|null $timezone = null):
$this->getHours(),
$this->getMinutes(),
$this->getSeconds(),
$this->getMicroseconds()
$this->getMicroseconds(),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/DifferenceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(?Translator $translate = null)
public function diffForHumans(
ChronosDate|DateTimeInterface $first,
ChronosDate|DateTimeInterface|null $second = null,
bool $absolute = false
bool $absolute = false,
): string {
$isNow = $second === null;
if ($second === null) {
Expand All @@ -61,7 +61,7 @@ public function diffForHumans(
}
assert(
($first instanceof ChronosDate && $second instanceof ChronosDate) ||
($first instanceof DateTimeInterface && $second instanceof DateTimeInterface)
($first instanceof DateTimeInterface && $second instanceof DateTimeInterface),
);

$diffInterval = $first->diff($second);
Expand Down
2 changes: 1 addition & 1 deletion src/DifferenceFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ interface DifferenceFormatterInterface
public function diffForHumans(
ChronosDate|DateTimeInterface $first,
ChronosDate|DateTimeInterface|null $second = null,
bool $absolute = false
bool $absolute = false,
): string;
}
16 changes: 8 additions & 8 deletions tests/TestCase/Date/ComparisonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function testBetweenEqualTrue()
$this->assertTrue(ChronosDate::create(2000, 1, 15)->between(
ChronosDate::create(2000, 1, 1),
ChronosDate::create(2000, 1, 31),
true
true,
));
}

Expand All @@ -104,7 +104,7 @@ public function testBetweenNotEqualTrue()
$this->assertTrue(ChronosDate::create(2000, 1, 15)->between(
ChronosDate::create(2000, 1, 1),
ChronosDate::create(2000, 1, 31),
false
false,
));
}

Expand All @@ -113,7 +113,7 @@ public function testBetweenEqualFalse()
$this->assertFalse(ChronosDate::create(1999, 12, 31)->between(
ChronosDate::create(2000, 1, 1),
ChronosDate::create(2000, 1, 31),
true
true,
));
}

Expand All @@ -122,7 +122,7 @@ public function testBetweenNotEqualFalse()
$this->assertFalse(ChronosDate::create(2000, 1, 1)->between(
ChronosDate::create(2000, 1, 1),
ChronosDate::create(2000, 1, 31),
false
false,
));
}

Expand All @@ -131,7 +131,7 @@ public function testBetweenEqualSwitchTrue()
$this->assertTrue(ChronosDate::create(2000, 1, 15)->between(
ChronosDate::create(2000, 1, 31),
ChronosDate::create(2000, 1, 1),
true
true,
));
}

Expand All @@ -140,7 +140,7 @@ public function testBetweenNotEqualSwitchTrue()
$this->assertTrue(ChronosDate::create(2000, 1, 15)->between(
ChronosDate::create(2000, 1, 31),
ChronosDate::create(2000, 1, 1),
false
false,
));
}

Expand All @@ -149,7 +149,7 @@ public function testBetweenEqualSwitchFalse()
$this->assertFalse(ChronosDate::create(1999, 12, 31)->between(
ChronosDate::create(2000, 1, 31),
ChronosDate::create(2000, 1, 1),
true
true,
));
}

Expand All @@ -158,7 +158,7 @@ public function testBetweenNotEqualSwitchFalse()
$this->assertFalse(ChronosDate::create(2000, 1, 1)->between(
ChronosDate::create(2000, 1, 31),
ChronosDate::create(2000, 1, 1),
false
false,
));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/DateTime/GettersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testGetAgeWithRealAge()
$age = intval(substr(
(string)(date('Ymd') - date('Ymd', $d->timestamp)),
0,
-4
-4,
));

$this->assertSame($age, $d->age);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/DateTime/InstanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testInstanceFromDateTimeKeepsTimezoneName()
{
$dating = Chronos::instance(DateTime::createFromFormat(
'Y-m-d H:i:s',
'1975-05-21 22:32:11'
'1975-05-21 22:32:11',
)->setTimezone(new DateTimeZone('America/Vancouver')));
$this->assertSame('America/Vancouver', $dating->tzName);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function ($code, $message, $file, $line, $context = null) use (&$previousHandler
}

return false;
}
},
);
try {
$callable();
Expand Down