Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CarbonTimeZone behaves differently from DateTimeZone for short, signed offset values #2588

Closed
Nextra opened this issue Apr 13, 2022 · 2 comments · Fixed by #2589
Closed

CarbonTimeZone behaves differently from DateTimeZone for short, signed offset values #2588

Nextra opened this issue Apr 13, 2022 · 2 comments · Fixed by #2589
Assignees
Labels
Milestone

Comments

@Nextra
Copy link

Nextra commented Apr 13, 2022

Hello,

I encountered an issue with the following code:

echo (new CarbonTimeZone('+01'))->getName()

Carbon version: 2.57.0
PHP version: 8.1.1

I expected to get:

+01:00

But I actually get an exception:

DateTimeZone::__construct(): Unknown or bad timezone (++01:00)

Doing the same with a native DateTimeZone works as expected:

echo (new DateTimeZone('+01'))->getName()

shows:

+01:00

Thanks!

@kylekatarnls
Copy link
Collaborator

Hello 👋

Thanks for the report.

I will check if we can and should support this.

In the meantime I recommend to use the explicit full timezone string:

echo (new CarbonTimeZone('+01:00'))->getName();

It's supported, and the less ambiguous way IMO.

@kylekatarnls kylekatarnls self-assigned this Apr 13, 2022
@Nextra
Copy link
Author

Nextra commented Apr 13, 2022

I'm all good, don't worry about that. Found out about this discrepancy when playing around with 8601, pretty much by accident. Just figured I'd make someone aware.

Cheers for all you do!

@kylekatarnls kylekatarnls added this to the 2.58.0 milestone Apr 14, 2022
kylekatarnls added a commit to kylekatarnls/Carbon that referenced this issue Apr 14, 2022
kylekatarnls added a commit to kylekatarnls/Carbon that referenced this issue Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants