1

I have a problem with php in converting dates between timezones. In particular using the DateTime and DateTimeZone functions I get that the current offset of America/Mexico_City is -5 hours w.r.t UTC (-18000 seconds)

$dateTimeZone = new DateTimeZone('America/Mexico_City');
$date = new DateTime('NOW');
$offset = $dateTimeZone->getOffset( $date ); // -> here $offset = -18000

I read that Mexico cancelled the DST last year: https://www.timeanddate.com/news/time/mexico-abolishes-dst-2022.html

And now if you check the current time they say that the current offset is -6 hours w.r.t UTC: https://www.zeitverschiebung.net/en/city/3530597

Anyone experiencing this problem? I think I should open a bug to PHP but I'd like to double check if I am doing something wrong and if anyone else is experiencing this problem.

Thanks,

Gioia
  • 81
  • 1
  • 9
  • Do you know which version of the time zone database your PHP installation is using? – Jon Skeet Apr 05 '23 at 07:23
  • Just checked, seems to be the 2018.04 so of course it is not updated. Thanks for your input. I'll check with our system department to update it and will post the results. – Gioia Apr 05 '23 at 07:39

2 Answers2

3

You are probably using a very old version of PHP, which is why your libraries "don't know" that Mexico has dropped DST.

Try upgrading your PHP version to something that is actively supported like 8.1 or 8.2.

I checked it locally and in PHP 8.1.13 I get offset -21600, in PHP 8.1.12 -18000.

1

We found out that our PHP installation was using a timezone library outdated, we checked our php ini file in the "date" section.
Our system department updated the library and now the problem is gone.
Thanks a lot for your help S.O. community :)

Gioia
  • 81
  • 1
  • 9