27/03
2018
Wallogit.com
2017 © Pedro Peláez
Bringing Ruby on Rails' time zone list to PHP.
Creating a time zone select in PHP can get unruly quickly, as DateTimeZone::listIdentifiers() returns over 415 Zones and Links. This is an attempt to take a page from Ruby on Rails' ActiveSupport::TimeZone time_zone_select(), largely by using their curated list of about 150 Zones, and also by allowing for 'priority_zones' to be at the top of the list., (*1)
, (*2)
Example:, (*3)
echo TimeZoneSelect::get_select(['country'=>'US']);, (*4)
Simple demo avaiable: http://scott.connerly.net/TimeZone/example.php, (*5)
Available args w/ default values:, (*6)
[
'country' => '', //ISO-3116 2-letter country code
'priority_zones' => [], //If you want to specify a list of zones that aren't country-specific
'priority_label' => 'Regional', //The label of the optgroup for the priority zones
'selected' => '', //which option is selected
'name' => 'time_zone', //name for the <select>
'class' => '', //class for the <select>
'id' => '', //id for the <select>
'data' => [], //list of data attributes to add to the <select>
]