Carbon: Absolute timezone offset cannot be greater than 100

Created on 3 Sep 2019  路  4Comments  路  Source: briannesbitt/Carbon


Hello,

I upgraded my prodject's Carbon version from 1.21 to 2.23.1 and I encountered an issue with the following code:

echo Carbon::createFromTimestamp('468370800', '+0100');

Carbon version: 2.23.1

PHP version: 7.2

I expected to get:

1984-11-04 00:00:00

But I actually get:

[InvalidArgumentException]                            
Absolute timezone offset cannot be greater than 100.

Thanks!

bug

All 4 comments

In fact this timezone was wrong automatically fixed before 1.22: '+0100' was converted to '+01:00', but it's guessing and it can be dangerous, as you can also pass '+1' that also gives you '+01:00'

The problem was than 100 does not match either a number of minutes nor a name, so since 1.22, '+0100' became invalid to avoid bugs on unexpected timezones.

I will check if we can parse it with no risk. Meanwhile, you can simply use: '+01:00'

Or if your timezone is dynamic: substr($tz, 0, -2).':'.substr($tz, -2)

It can be fixed with no regression so it will be supported again in 2.25.0.

Fixed, you can test it on the dev-master version.

It works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MaxGiting picture MaxGiting  路  4Comments

Unibozu picture Unibozu  路  5Comments

mfn picture mfn  路  4Comments

yica00 picture yica00  路  4Comments

scs-ben picture scs-ben  路  3Comments