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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.1.0 || ^11.1.3"
"phpunit/phpunit": "^10.5.58 || ^11.1.3"
},
"provide": {
"psr/clock-implementation": "1.0"
Expand Down
9 changes: 8 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true">
colors="true"
failOnDeprecation="true"
displayDetailsOnTestsThatTriggerDeprecations="true">
<testsuites>
<testsuite name="Chronos Test Suite">
<directory>tests</directory>
Expand All @@ -13,4 +15,9 @@
<directory suffix=".php">src/</directory>
</include>
</source>

<php>
<!-- E_ALL (32767) -->
<ini name="error_reporting" value="32767"/>
</php>
</phpunit>
11 changes: 11 additions & 0 deletions src/Chronos.php
Original file line number Diff line number Diff line change
Expand Up @@ -2587,6 +2587,17 @@ public function diffForHumans(?DateTimeInterface $other = null, bool $absolute =
return static::diffFormatter()->diffForHumans($this, $other, $absolute);
}

/**
* Converts the time zone to UTC and returns a string in RFC7231 format.
* This replaced the deprecated and broken ``DATE_RFC7231`` formatting constant.
*
* @return string
*/
public function toRfc7231String(): string
{
return $this->setTimezone('UTC')->format('D, d M Y H:i:s \G\M\T');
}

/**
* Returns a DateTimeImmutable instance
*
Expand Down
31 changes: 26 additions & 5 deletions tests/TestCase/DateTime/StringsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
$this->assertSame('1639224001', $time->toUnixString());
}

public function testToRfc7231String()
{
$time = Chronos::parse('2014-04-20 08:00:00', 'America/Toronto');
$this->assertSame('Sun, 20 Apr 2014 12:00:00 GMT', $time->toRfc7231String());
}

/**
* Provides values and expectations for the toQuarter method
*
Expand All @@ -171,10 +177,6 @@
['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],
];
}

Expand All @@ -186,7 +188,26 @@
#[DataProvider('toQuarterProvider')]
public function testToQuarter($date, $expected, $range = false)
{
$this->assertSame($expected, (new Chronos($date))->toQuarter($range));
$this->assertSame($expected, (new Chronos($date))->toQuarter());
}

public static function toQuarterRangeProvider()
{
return [
['2007-3-25', ['2007-01-01', '2007-03-31']],
['2007-5-25', ['2007-04-01', '2007-06-30']],
['2007-8-25', ['2007-07-01', '2007-09-30']],
['2007-12-25', ['2007-10-01', '2007-12-31']],
];
}

#[DataProvider('toQuarterRangeProvider')]
public function testToQuarterRange($date, $expected)
{
$this->assertSame($expected, (new Chronos($date))->toQuarterRange());
$this->deprecated(function() use ($date, $expected) {

Check failure on line 208 in tests/TestCase/DateTime/StringsTest.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Expected 1 space after FUNCTION keyword; 0 found
$this->assertSame($expected, (new Chronos($date))->toQuarter(true));
});
}

/**
Expand Down
Loading