spatie / period

Complex period comparisons
https://spatie.be/open-source
MIT License
1.56k stars 72 forks source link

Period roundDate() does not keep date's timezone #70

Closed tania-pets closed 3 years ago

tania-pets commented 3 years ago

When creating a new Period, with timezoned start, end, the period object ends up with start, end in UTC always.

  $start = new \DateTimeImmutable('2000-01-01', new \DateTimeZone('Europe/London'));
  $end = new \DateTimeImmutable('2000-02-01', new \DateTimeZone('Europe/London'));
  $period = new \Spatie\Period\Period($start, $end);
  var_dump($period->getStart());

result:

object(DateTimeImmutable)#3257 (3) { ["date"]=> string(26) "2000-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

Suggestion solution to change this: https://github.com/spatie/period/blob/14e56b619fb430b9bcfb7e79ebdbec86310648e3/src/Period.php#L527

to this:

 implode(' ', [$year, $month, $day, $hour, $minute, $second]), $date->getTimezone()
brendt commented 3 years ago

Fixed in https://github.com/spatie/period/releases/tag/1.5.2