briannesbitt / Carbon

A simple PHP API extension for DateTime.
https://carbon.nesbot.com/
MIT License
16.59k stars 1.28k forks source link

CarbonPeriod loses timezone when accessing days #3040

Closed AEM5299 closed 5 months ago

AEM5299 commented 5 months ago

Hello,

I encountered an issue with the following code:

echo CarbonPeriodImmutable::create('2024-01-01', '2024-01-05', CarbonTimeZone::create('Australia/Melbourne'))->first()->timezone

Carbon version: 3.3.1

PHP version: 8.2

I expected to get:

Australia/Melbourne

But I actually get:

UTC

In Carbon v2, the same code returns Australia/Melbourne as expected. I'm not sure if this is intended behaviour after the move to extend PHP's DatePeriod, but if it is I think it might need a callout in the upgrade guide.

Thanks!