22
33[ ![ Latest Version] ( https://img.shields.io/github/release/jessedp/php-timezones.svg?style=flat-square )] ( https://github.com/jessedp/php-timezones/releases )
44[ ![ MIT Licensed] ( https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square )] ( LICENSE.md )
5- [ ![ Test Status] ( https://img.shields.io/github/workflow/status/jessedp/php-timezones/run-tests ?label=tests&style=flat-square )] ( https://github.com/jessedp/php-timezones/actions?query=workflow%3Arun-tests )
5+ [ ![ Test Status] ( https://img.shields.io/github/actions/ workflow/status/jessedp/php-timezones/run-test.yml ?label=tests&style=flat-square )] ( https://github.com/jessedp/php-timezones/actions?query=workflow%3Arun-tests )
66[ ![ Quality Score] ( https://img.shields.io/scrutinizer/g/jessedp/php-timezones.svg?style=flat-square )] ( https://scrutinizer-ci.com/g/jessedp/php-timezones )
77[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/jessedp/php-timezones.svg?style=flat-square )] ( https://packagist.org/packages/jessedp/php-timezones )
88
9- A wrapper to enumerate PHP 5.6+, 7.x timezones in a simplified way for use in various ways.
9+ A wrapper to enumerate PHP 5.6+, 7.x, 8.x timezones in a simplified way for use in various ways.
1010
1111This is done with Laravel 5.5+ in mind - YMMV elsewhere.
1212
1313## Basics
1414
15- * Creates timezone arrays based on PHP's supported timezones with optional grouping by region
16- * Lists are sorted by offset from high (+14:00) to low (-11:00)
17- * Optionally group the arrays (multi-dim associated array) by region
18- + sorting is the same, but only inside each region
19- * For either case, return those as:
20- + php arrays for whatever use your heart desires
21- + HTML select list
22- * 2 utility functions for converting to/from UTC
15+ - Creates timezone arrays based on PHP's supported timezones with optional grouping by region
16+ - Lists are sorted by offset from high (+14:00) to low (-11:00)
17+ - Optionally group the arrays (multi-dim associated array) by region
18+ - sorting is the same, but only inside each region
19+ - For either case, return those as:
20+ - php arrays for whatever use your heart desires
21+ - HTML select list
22+ - 2 utility functions for converting to/from UTC
2323
2424## Installation
2525
2626You can install this package using [ Composer] ( https://getcomposer.org ) .
2727
28- ``` bash
28+ ``` bash
2929$ composer require jessedp/php-timezones
3030
3131Using version ^0.2.0 for jessedp/php-timezones
@@ -40,48 +40,47 @@ Using version ^0.2.0 for jessedp/php-timezones
4040
4141The method ` Timezones::create() ` has three parameters:
4242
43- ``` php
43+ ``` php
4444Timezones::create($name, $selected, $opts);
4545```
4646
47- * $name ** required** - the * name * of the select element
48- * $selected - sets the selected value of list box, assuming the a value with the option exists
49- * $opts an array of options as key=>value:
50- + attr => * array * of key=>value pairs to be included in the select element (ie, 'id', 'class', etc.)
51- + with_regions => * boolean * whether or not to use option groups for the regions/continents (defaults to false)
52- + regions => array (of strings) specifying the region(s) to include
47+ - $name ** required** - the _ name _ of the select element
48+ - $selected - sets the selected value of list box, assuming the a value with the option exists
49+ - $opts an array of options as key=>value:
50+ - attr => _ array _ of key=>value pairs to be included in the select element (ie, 'id', 'class', etc.)
51+ - with * regions => \_ boolean * whether or not to use option groups for the regions/continents (defaults to false)
52+ - regions => array (of strings) specifying the region(s) to include
5353
5454#### Basic Example
5555
56- ``` php
57- Timezones::create('timezone');
56+ ``` php
57+ Timezones::create('timezone');
5858```
5959
6060Returns a string similar to:
6161
62- ``` html
63- <select name =" timezone" >
64- ...
65- <option value =" Africa/Abidjan" >(GMT/UTC + 00:00) Abidjan</option >
66- <option value =" Africa/Accra" >(GMT/UTC + 00:00) Accra</option >
67- ...
68-
69- </select >
62+ ``` html
63+ <select name =" timezone" >
64+ ...
65+ <option value =" Africa/Abidjan" >(GMT/UTC + 00:00) Abidjan</option >
66+ <option value =" Africa/Accra" >(GMT/UTC + 00:00) Accra</option >
67+ ...
68+ </select >
7069```
7170
7271#### "Selected" Example
7372
74- Same as above, but * Asia/Ho_Chi_Minh * will be selected by default
73+ Same as above, but _ Asia/Ho_Chi_Minh _ will be selected by default
7574
76- ``` php
75+ ``` php
7776Timezones::create('timezone', 'Asia/Ho_Chi_Minh');
7877```
7978
8079#### "Options" Example
8180
8281You may also add multiple attributes with an array.
8382
84- ``` php
83+ ``` php
8584Timezones::create('timezone', null,
8685 ['attr'=>[
8786 'id' => 'my_id',
@@ -92,25 +91,37 @@ Timezones::create('timezone', null,
9291
9392Which gives us:
9493
95- ``` html
96- <select name =" timezone" id =" my_id" class =" form-control" >
97- <option value =" Pacific/Apia" >(GMT/UTC + 14:00)  ;  ;  ;  ; Pacific/Apia</option >
98- <option value =" Pacific/Kiritimati" >(GMT/UTC + 14:00)  ;  ;  ;  ; Pacific/Kiritimati</option >
99- ...
100- <option value =" Asia/Shanghai" >(GMT/UTC + 08:00)  ;  ;  ;  ; Asia/Shanghai</option >
101- <option value =" Asia/Singapore" >(GMT/UTC + 08:00)  ;  ;  ;  ; Asia/Singapore</option >
102- <option value =" Asia/Taipei" >(GMT/UTC + 08:00)  ;  ;  ;  ; Asia/Taipei</option >
103- ...
104- <option value =" America/New_York" >(GMT/UTC − 05:00)  ;  ;  ;  ; America/New York</option >
105- ...
106- </select >
94+ ``` html
95+ <select name =" timezone" id =" my_id" class =" form-control" >
96+ <option value =" Pacific/Apia" >
97+ (GMT/UTC + 14:00)  ;  ;  ;  ; Pacific/Apia
98+ </option >
99+ <option value =" Pacific/Kiritimati" >
100+ (GMT/UTC + 14:00)  ;  ;  ;  ; Pacific/Kiritimati
101+ </option >
102+ ...
103+ <option value =" Asia/Shanghai" >
104+ (GMT/UTC + 08:00)  ;  ;  ;  ; Asia/Shanghai
105+ </option >
106+ <option value =" Asia/Singapore" >
107+ (GMT/UTC + 08:00)  ;  ;  ;  ; Asia/Singapore
108+ </option >
109+ <option value =" Asia/Taipei" >
110+ (GMT/UTC + 08:00)  ;  ;  ;  ; Asia/Taipei
111+ </option >
112+ ...
113+ <option value =" America/New_York" >
114+ (GMT/UTC − 05:00)  ;  ;  ;  ; America/New York
115+ </option >
116+ ...
117+ </select >
107118```
108119
109120#### "Regions/Grouping" Example
110121
111122Say you want the option groups but only a couple regions...
112123
113- ``` php
124+ ``` php
114125Timezones::create('timezone',null,
115126 ['attr'=>['class'=>'form-control'],
116127 'with_regions'=>true,
@@ -120,23 +131,33 @@ Timezones::create('timezone',null,
120131
121132This will return a string similar to the following:
122133
123- ``` html
124- <select name =" timezone" class =" form-control" >
125- <optgroup label =" Africa" >
126- <option value =" Africa/Addis_Ababa" >(GMT/UTC + 03:00)  ;  ;  ;  ; Addis Ababa</option >
127- <option value =" Africa/Asmara" >(GMT/UTC + 03:00)  ;  ;  ;  ; Asmara</option >
128- ...
129- </optgroup >
130- <optgroup label =" America" >
131- ...
132- <option value =" America/Noronha" >(GMT/UTC − 02:00)  ;  ;  ;  ; Noronha</option >
133- ...
134- <option value =" America/Argentina/Buenos_Aires" >(GMT/UTC − 03:00)  ;  ;  ;  ; Argentina/Buenos Aires</option >
135- ...
136- <option value =" America/New_York" >(GMT/UTC − 05:00)  ;  ;  ;  ; New York</option >
137- ...
138- </optgroup >
139- </select >
134+ ``` html
135+ <select name =" timezone" class =" form-control" >
136+ <optgroup label =" Africa" >
137+ <option value =" Africa/Addis_Ababa" >
138+ (GMT/UTC + 03:00)  ;  ;  ;  ; Addis Ababa
139+ </option >
140+ <option value =" Africa/Asmara" >
141+ (GMT/UTC + 03:00)  ;  ;  ;  ; Asmara
142+ </option >
143+ ...
144+ </optgroup >
145+ <optgroup label =" America" >
146+ ...
147+ <option value =" America/Noronha" >
148+ (GMT/UTC − 02:00)  ;  ;  ;  ; Noronha
149+ </option >
150+ ...
151+ <option value =" America/Argentina/Buenos_Aires" >
152+ (GMT/UTC − 03:00)  ;  ;  ;  ; Argentina/Buenos Aires
153+ </option >
154+ ...
155+ <option value =" America/New_York" >
156+ (GMT/UTC − 05:00)  ;  ;  ;  ; New York
157+ </option >
158+ ...
159+ </optgroup >
160+ </select >
140161```
141162
142163### 2. Render a timezone array
@@ -145,7 +166,7 @@ You can also render timezone list as an array. To do so, just use the `Timezones
145166
146167Example in Laravel:
147168
148- ``` php
169+ ``` php
149170$timezone_list = Timezones::toArray();
150171```
151172
@@ -155,7 +176,7 @@ The package includes two methods that make it easy to deal with displaying and s
155176
156177Each function accepts two required parameters and a third optional parameter dealing with the format of the returned timestamp.
157178
158- ``` php
179+ ``` php
159180 Timezones::convertFromUTC($timestamp, $timezone, $format);
160181 Timezones::convertToUTC($timestamp, $timezone, $format);
161182```
@@ -168,7 +189,7 @@ The third parameter is optional, and default is set to `'Y-m-d H:i:s'` , which i
168189
169190This is based off some lovely work by:
170191
171- * https://github.com/JackieDo/Timezone-List
172- * https://github.com/camroncade/timezone
192+ - https://github.com/JackieDo/Timezone-List
193+ - https://github.com/camroncade/timezone
173194
174195The [ Spatie group] ( https://github.com/spatie ) and specifically the [ laravel-analytics] ( https://github.com/spatie/laravel-analytics/ ) project I used ~~ as inspiration~~ copied for structure
0 commit comments