Mauizah Nasir
Mauizah Nasir

Reputation: 1

Carbon returning wrong timezone offset for America/Sao_Paulo

I am using Carbon dates in my Laravel 8 project using PHP 7. I recently came across a strange bug that occurring only on my production server and failed to execute locally.

I am sending an invite for the time set to timezone 'America/Sao_Paulo' which currently is operating over offset (-03:00), However, when I receive the email the timezone is rendered as (-02:00) and hence my conversion is all disturbed by one hour difference.

I even tried hardcoding it like below and the value dumped on production sometimes gives (-02:00) and other times the correct value which is (-03:00).

$date = Carbon::now(tz: 'America/Sao_paolo')->getOffsetString();
dd($date);

What is the solution for this?

Upvotes: 0

Views: 1129

Answers (1)

user16539325
user16539325

Reputation:

in the AppServiceProvider.php you can add a little script for the whole Laravel app , please check

public function boot()
{
    date_default_timezone_set('America/Sao_Paulo');
} 

Upvotes: 0

Related Questions