Skip to content

Commit

Permalink
LocalDateRange::toInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
solodkiy committed Sep 30, 2023
1 parent f013742 commit 3517451
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions .idea/date-time.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/LocalDateRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,25 @@ public function jsonSerialize(): string
return (string) $this;
}

/**
* Converts this LocalDateRange to Interval instance.
*
* The result is Interval from 00:00 start date and 00:00 end date + one day (because end in Interval is exclude)
* in the given time-zone.
*/
public function toInterval(TimeZone $timeZone): Interval
{
$startZonedDateTime = $this->getStart()
->atTime(LocalTime::min())
->atTimeZone($timeZone);
$endZonedDateTime = $this->getEnd()
->plusDays(1)
->atTime(LocalTime::min())
->atTimeZone($timeZone);

return $startZonedDateTime->getIntervalTo($endZonedDateTime);
}

/**
* Converts this LocalDateRange to a native DatePeriod object.
*
Expand Down
Loading

0 comments on commit 3517451

Please sign in to comment.