2
2
3
3
[ ![ Latest Version] ( https://img.shields.io/github/release/jessedp/php-timezones.svg?style=flat-square )] ( https://github.com/jessedp/php-timezones/releases )
4
4
[ ![ 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 )
6
6
[ ![ Quality Score] ( https://img.shields.io/scrutinizer/g/jessedp/php-timezones.svg?style=flat-square )] ( https://scrutinizer-ci.com/g/jessedp/php-timezones )
7
7
[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/jessedp/php-timezones.svg?style=flat-square )] ( https://packagist.org/packages/jessedp/php-timezones )
8
8
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.
10
10
11
11
This is done with Laravel 5.5+ in mind - YMMV elsewhere.
12
12
13
13
## Basics
14
14
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
23
23
24
24
## Installation
25
25
26
26
You can install this package using [ Composer] ( https://getcomposer.org ) .
27
27
28
- ``` bash
28
+ ``` bash
29
29
$ composer require jessedp/php-timezones
30
30
31
31
Using version ^0.2.0 for jessedp/php-timezones
@@ -40,48 +40,47 @@ Using version ^0.2.0 for jessedp/php-timezones
40
40
41
41
The method ` Timezones::create() ` has three parameters:
42
42
43
- ``` php
43
+ ``` php
44
44
Timezones::create($name, $selected, $opts);
45
45
```
46
46
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
53
53
54
54
#### Basic Example
55
55
56
- ``` php
57
- Timezones::create('timezone');
56
+ ``` php
57
+ Timezones::create('timezone');
58
58
```
59
59
60
60
Returns a string similar to:
61
61
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 >
70
69
```
71
70
72
71
#### "Selected" Example
73
72
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
75
74
76
- ``` php
75
+ ``` php
77
76
Timezones::create('timezone', 'Asia/Ho_Chi_Minh');
78
77
```
79
78
80
79
#### "Options" Example
81
80
82
81
You may also add multiple attributes with an array.
83
82
84
- ``` php
83
+ ``` php
85
84
Timezones::create('timezone', null,
86
85
['attr'=>[
87
86
'id' => 'my_id',
@@ -92,25 +91,37 @@ Timezones::create('timezone', null,
92
91
93
92
Which gives us:
94
93
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 >
107
118
```
108
119
109
120
#### "Regions/Grouping" Example
110
121
111
122
Say you want the option groups but only a couple regions...
112
123
113
- ``` php
124
+ ``` php
114
125
Timezones::create('timezone',null,
115
126
['attr'=>['class'=>'form-control'],
116
127
'with_regions'=>true,
@@ -120,23 +131,33 @@ Timezones::create('timezone',null,
120
131
121
132
This will return a string similar to the following:
122
133
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 >
140
161
```
141
162
142
163
### 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
145
166
146
167
Example in Laravel:
147
168
148
- ``` php
169
+ ``` php
149
170
$timezone_list = Timezones::toArray();
150
171
```
151
172
@@ -155,7 +176,7 @@ The package includes two methods that make it easy to deal with displaying and s
155
176
156
177
Each function accepts two required parameters and a third optional parameter dealing with the format of the returned timestamp.
157
178
158
- ``` php
179
+ ``` php
159
180
Timezones::convertFromUTC($timestamp, $timezone, $format);
160
181
Timezones::convertToUTC($timestamp, $timezone, $format);
161
182
```
@@ -168,7 +189,7 @@ The third parameter is optional, and default is set to `'Y-m-d H:i:s'` , which i
168
189
169
190
This is based off some lovely work by:
170
191
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
173
194
174
195
The [ 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