Skip to content

Commit

Permalink
Merge pull request #11 from JackieDo/5.x
Browse files Browse the repository at this point in the history
Upgrade core for Laravel 6+
  • Loading branch information
JackieDo authored Apr 12, 2020
2 parents b9629de + e28abfd commit 2c56729
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ language: php

php:
- 5.6
- hhvm
- 7.1
- 7.2
- 7.3

before_script:
- travis_retry composer self-update
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Laravel Timezone List

[![Latest Stable Version](https://poser.pugx.org/jackiedo/timezonelist/v/stable)](https://packagist.org/packages/jackiedo/timezonelist)
[![Total Downloads](https://poser.pugx.org/jackiedo/timezonelist/downloads)](https://packagist.org/packages/jackiedo/timezonelist)
[![Latest Unstable Version](https://poser.pugx.org/jackiedo/timezonelist/v/unstable)](https://packagist.org/packages/jackiedo/timezonelist)
[![License](https://poser.pugx.org/jackiedo/timezonelist/license)](https://packagist.org/packages/jackiedo/timezonelist)

# Feature
- Render a timezone listbox (select element) in Laravel
- Render a timezone array in Laravel
Expand All @@ -6,10 +13,10 @@

Currently, there are some branches of Timezone-List is compatible with the following version of Laravel framework

| Timezone-List branch | Laravel version |
| ------------------------------------------------------------- | ---------------- |
| [4.x](https://github.com/JackieDo/Timezone-List/tree/4.x) | 4.x |
| [5.x](https://github.com/JackieDo/Timezone-List/tree/5.x) | 5.x |
| Timezone-List branch | Laravel version |
| --------------------------------------------------------- | --------------- |
| [4.x](https://github.com/JackieDo/Timezone-List/tree/4.x) | 4.x |
| [5.x](https://github.com/JackieDo/Timezone-List/tree/5.x) | 5.x and above |

This documentation is use for Laravel 5.x

Expand All @@ -33,7 +40,9 @@ You can install this package through [Composer](https://getcomposer.org).
$ composer update
```

- Once update operation completes, the final step is to add the service provider. Open `config/app.php`, and add a new item to the providers array:
> **Note:** Instead of performing the above two steps, it may be faster to use the command line `$ composer require jackiedo/timezonelist:5.*`.
- Since Laravel 5.5, [service providers and aliases are automatically registered](https://laravel.com/docs/5.5/packages#package-discovery). But if you are using Laravel 5.4 and earlier, you must register the service provider manually. Open `config/app.php`, and add a new item to the providers array:

```php
...
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.*"
"illuminate/support": ">=5.0"
},
"autoload": {
"psr-4": {
"Jackiedo\\Timezonelist\\": "src/Jackiedo/Timezonelist"
}
},
"extra": {
"laravel": {
"providers": [
"Jackiedo\\Timezonelist\\TimezonelistServiceProvider"
]
}
},
"minimum-stability": "stable"
}
16 changes: 11 additions & 5 deletions src/Jackiedo/Timezonelist/Timezonelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class Timezonelist
*/
protected function formatTimezone($timezone, $continent, $htmlencode=true)
{
$time = new DateTime(null, new DateTimeZone($timezone));
$time = new DateTime(null, new DateTimeZone($timezone));
$offset = $time->format('P');

if ($htmlencode) {
$offset = str_replace('-', ' − ', $offset);
$offset = str_replace('+', ' + ', $offset);
Expand All @@ -72,16 +73,18 @@ protected function formatTimezone($timezone, $continent, $htmlencode=true)
/**
* Create a GMT timezone select element for form
*
* @param string $name
* @param string $selected
* @param mixed $attr
* @param string $name
* @param string $selected
* @param mixed $attr
* @param boolean $htmlencode
*
* @return string
**/
public function create($name, $selected='', $attr='', $htmlencode=true)
{

// Attributes for select element
$attrSet = null;

if (!empty($attr)) {
if (is_array($attr)) {
foreach ($attr as $attr_name => $attr_value) {
Expand All @@ -97,10 +100,12 @@ public function create($name, $selected='', $attr='', $htmlencode=true)

// Add popular timezones
$listbox .= '<optgroup label="General">';

foreach ($this->popularTimezones as $key => $value) {
$selected_attr = ($selected == $key) ? ' selected="selected"' : '';
$listbox .= '<option value="' .$key. '"' .$selected_attr. '>' .$value. '</option>';
}

$listbox .= '</optgroup>';

// Add all timezone of continents
Expand Down Expand Up @@ -146,6 +151,7 @@ public function toArray($htmlencode=true)
// Add all timezone of continents to list
foreach ($this->continents as $continent => $mask) {
$timezones = DateTimeZone::listIdentifiers($mask);

foreach ($timezones as $timezone) {
$list[$continent][$timezone] = $this->formatTimezone($timezone, $continent, $htmlencode);
}
Expand Down

0 comments on commit 2c56729

Please sign in to comment.