-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test DatePeriod constructor with named arguments
- Loading branch information
1 parent
4dc86c4
commit 5945367
Showing
3 changed files
with
124 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php // lint >= 8.0 | ||
|
||
namespace Bug5553; | ||
|
||
use DatePeriod; | ||
use DateTime; | ||
|
||
class Foo | ||
{ | ||
|
||
public function weekNumberToWorkRange(int $week, int $year): DatePeriod | ||
{ | ||
$dto = new DateTime(); | ||
$dto->setISODate($year, $week); | ||
$dto->setTime(8, 0, 0, 0); | ||
|
||
$start = clone $dto; | ||
$dto->modify('+4 days'); | ||
$end = clone $dto; | ||
$end->setTime(18, 0, 0, 0); | ||
|
||
return new DatePeriod( | ||
start: $start, | ||
interval: new \DateInterval('P1D'), | ||
end: $end | ||
); | ||
} | ||
|
||
} |
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,52 @@ | ||
<?php declare(strict_types = 1); // lint >= 8.0 | ||
|
||
namespace Bug7048; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(): \DatePeriod | ||
{ | ||
return new \DatePeriod( | ||
start: new \DateTime('now'), | ||
interval: new \DateInterval('P1D'), | ||
end: new \DateTime('now + 3 days'), | ||
); | ||
} | ||
|
||
public function doFoo(): void | ||
{ | ||
new \DatePeriod( | ||
start: new \DateTime('now'), | ||
interval: new \DateInterval('P1D'), | ||
recurrences: 5, | ||
); | ||
|
||
new \DatePeriod( | ||
isostr: 'R4/2012-07-01T00:00:00Z/P7D' | ||
); | ||
} | ||
|
||
public function allValid(): void | ||
{ | ||
$start = new \DateTime('2012-07-01'); | ||
$interval = new \DateInterval('P7D'); | ||
$end = new \DateTime('2012-07-31'); | ||
$recurrences = 4; | ||
$iso = 'R4/2012-07-01T00:00:00Z/P7D'; | ||
|
||
|
||
$period = new \DatePeriod($start, $interval, $recurrences); | ||
$period = new \DatePeriod($start, $interval, $end); | ||
$period = new \DatePeriod($iso); | ||
$period = new \DatePeriod($start, $interval, "foo"); | ||
} | ||
|
||
public function invalid(): void | ||
{ | ||
new \DatePeriod( | ||
start: new \DateTime('now'), | ||
interval: new \DateInterval('P1D'), | ||
end: "foo", | ||
); | ||
} | ||
} |