-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Date->datesUntil, Year->yearsUntil and Year-modify (#21)
Co-authored-by: Christian Kolb <info@digital-craftsman.de>
- Loading branch information
1 parent
82104d1
commit 5124ee0
Showing
9 changed files
with
332 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Upgrade guide | ||
|
||
## From 0.6.* to 0.7.0 | ||
|
||
No breaking changes | ||
|
||
## From 0.5.* to 0.6.0 | ||
|
||
No breaking changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalCraftsman\DateTimeParts; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\Date */ | ||
final class DateDatesUntilTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @dataProvider dataProvider | ||
* | ||
* @covers ::datesUntil | ||
*/ | ||
public function dates_until_works( | ||
array $expectedResult, | ||
Date $startDate, | ||
Date $endDate, | ||
PeriodLimit $periodLimit, | ||
): void { | ||
// -- Act & Assert | ||
self::assertEquals($expectedResult, $startDate->datesUntil($endDate, $periodLimit)); | ||
} | ||
|
||
/** | ||
* @return array<string, array{ | ||
* 0: array<int, Date>, | ||
* 1: Date, | ||
* 2: Date, | ||
* 3: PeriodLimit, | ||
* }> | ||
*/ | ||
public function dataProvider(): array | ||
{ | ||
return [ | ||
'two days apart with start and end included' => [ | ||
[ | ||
Date::fromString('2022-08-03'), | ||
Date::fromString('2022-08-04'), | ||
Date::fromString('2022-08-05'), | ||
], | ||
Date::fromString('2022-08-03'), | ||
Date::fromString('2022-08-05'), | ||
PeriodLimit::INCLUDING_START_AND_END, | ||
], | ||
'three days apart with start and end included over the ends of a year' => [ | ||
[ | ||
Date::fromString('2022-12-30'), | ||
Date::fromString('2022-12-31'), | ||
Date::fromString('2023-01-01'), | ||
], | ||
Date::fromString('2022-12-30'), | ||
Date::fromString('2023-01-01'), | ||
PeriodLimit::INCLUDING_START_AND_END, | ||
], | ||
'two days apart with start included' => [ | ||
[ | ||
Date::fromString('2022-09-08'), | ||
Date::fromString('2022-09-09'), | ||
], | ||
Date::fromString('2022-09-08'), | ||
Date::fromString('2022-09-10'), | ||
PeriodLimit::INCLUDING_START, | ||
], | ||
'two days apart with end included' => [ | ||
[ | ||
Date::fromString('2022-09-09'), | ||
Date::fromString('2022-09-10'), | ||
], | ||
Date::fromString('2022-09-08'), | ||
Date::fromString('2022-09-10'), | ||
PeriodLimit::INCLUDING_END, | ||
], | ||
'two days apart with start and end excluded' => [ | ||
[ | ||
Date::fromString('2022-09-09'), | ||
], | ||
Date::fromString('2022-09-08'), | ||
Date::fromString('2022-09-10'), | ||
PeriodLimit::EXCLUDING_START_AND_END, | ||
], | ||
'two days apart with start after end' => [ | ||
[], | ||
Date::fromString('2022-09-11'), | ||
Date::fromString('2022-09-09'), | ||
PeriodLimit::INCLUDING_START, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalCraftsman\DateTimeParts; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\Year */ | ||
final class YearModifyTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @dataProvider dataProvider | ||
* | ||
* @covers ::modify | ||
*/ | ||
public function modify_works( | ||
Year $expectedResult, | ||
Year $month, | ||
string $modifier, | ||
): void { | ||
// -- Act & Assert | ||
self::assertEquals($expectedResult, $month->modify($modifier)); | ||
} | ||
|
||
/** | ||
* @return array<string, array{ | ||
* 0: Year, | ||
* 1: Year, | ||
* 2: string, | ||
* }> | ||
*/ | ||
public function dataProvider(): array | ||
{ | ||
return [ | ||
'subtract one year' => [ | ||
Year::fromString('2021'), | ||
Year::fromString('2022'), | ||
'- 1 year', | ||
], | ||
'add one year' => [ | ||
Year::fromString('2023'), | ||
Year::fromString('2022'), | ||
'+ 1 year', | ||
], | ||
'stupid but valid modification with one day' => [ | ||
Year::fromString('2022'), | ||
Year::fromString('2022'), | ||
'+ 1 day', | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalCraftsman\DateTimeParts; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @coversDefaultClass \DigitalCraftsman\DateTimeParts\Year */ | ||
final class YearYearsUntilTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @dataProvider dataProvider | ||
* | ||
* @covers ::yearsUntil | ||
*/ | ||
public function years_until_works( | ||
array $expectedResult, | ||
Year $startYear, | ||
Year $endYear, | ||
PeriodLimit $periodLimit, | ||
): void { | ||
// -- Act & Assert | ||
self::assertEquals($expectedResult, $startYear->yearsUntil($endYear, $periodLimit)); | ||
} | ||
|
||
/** | ||
* @return array<string, array{ | ||
* 0: array<int, Year>, | ||
* 1: Year, | ||
* 2: Year, | ||
* 3: PeriodLimit, | ||
* }> | ||
*/ | ||
public function dataProvider(): array | ||
{ | ||
return [ | ||
'two years apart with start and end included' => [ | ||
[ | ||
Year::fromString('2021'), | ||
Year::fromString('2022'), | ||
Year::fromString('2023'), | ||
], | ||
Year::fromString('2021'), | ||
Year::fromString('2023'), | ||
PeriodLimit::INCLUDING_START_AND_END, | ||
], | ||
'two years apart with start included' => [ | ||
[ | ||
Year::fromString('2022'), | ||
Year::fromString('2023'), | ||
], | ||
Year::fromString('2022'), | ||
Year::fromString('2024'), | ||
PeriodLimit::INCLUDING_START, | ||
], | ||
'two years apart with end included' => [ | ||
[ | ||
Year::fromString('2023'), | ||
Year::fromString('2024'), | ||
], | ||
Year::fromString('2022'), | ||
Year::fromString('2024'), | ||
PeriodLimit::INCLUDING_END, | ||
], | ||
'two years apart with start and end excluded' => [ | ||
[ | ||
Year::fromString('2023'), | ||
], | ||
Year::fromString('2022'), | ||
Year::fromString('2024'), | ||
PeriodLimit::EXCLUDING_START_AND_END, | ||
], | ||
'two years apart with start after end' => [ | ||
[], | ||
Year::fromString('2024'), | ||
Year::fromString('2022'), | ||
PeriodLimit::INCLUDING_START, | ||
], | ||
]; | ||
} | ||
} |