jessedp / php-timezones

Basic Timezone utilities aimed at Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timezones::toArray() throws notice and warning, returns incomplete results

nathan-io opened this issue · comments

Thanks for the update! I was able to install on L7 without issue.

However, I encountered an issue with the toArray() method.

Output from a Tinker session:

>>> $timezone_list = Timezones::toArray();
PHP Notice:  Undefined property: jessedp/Timezones/Timezones::$continents in /mnt/c/Users/Nathan/Desktop/Gitkraken/account/vendor/jessedp/php-timezones/src/Timezones/Timezones.php on line 197
PHP Warning:  Invalid argument supplied for foreach() in /mnt/c/Users/Nathan/Desktop/Gitkraken/account/vendor/jessedp/php-timezones/src/Timezones/Timezones.php on line 197
=> [
     "General" => [
       "GMT" => "GMT timezone",
       "UTC" => "UTC timezone",
     ],
   ]

In the method, it looks like $this->continents is never set so the foreach() doesn't work as expected.

The method worked beautifully once I changed $this->continents to $this->regions.

Submitted a PR.

For performance reasons, it would maybe be a good idea if you could specify one or more regions to fetch the timezones from when calling the method.

commented

Thanks! Merged and 0.2.1 it available.

commented

Thanks for the nudge on this - I formalized it much more since yesterday. Probably good for another two years now :)