{"id":17472369,"url":"https://github.com/jackiedo/timezone-list","last_synced_at":"2025-04-05T22:10:31.236Z","repository":{"id":26266571,"uuid":"29713880","full_name":"JackieDo/Timezone-List","owner":"JackieDo","description":"A small package use to create a timezone list box in Laravel","archived":false,"fork":false,"pushed_at":"2024-01-29T11:45:37.000Z","size":92,"stargazers_count":93,"open_issues_count":2,"forks_count":20,"subscribers_count":3,"default_branch":"5.x","last_synced_at":"2024-10-18T19:34:54.174Z","etag":null,"topics":["laravel","timezone","timezone-array","timezone-list","timezone-listbox"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JackieDo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-23T03:03:05.000Z","updated_at":"2024-10-14T08:44:33.000Z","dependencies_parsed_at":"2024-06-18T15:41:01.483Z","dependency_job_id":null,"html_url":"https://github.com/JackieDo/Timezone-List","commit_stats":{"total_commits":45,"total_committers":4,"mean_commits":11.25,"dds":0.0888888888888889,"last_synced_commit":"f1c64d0159b4401a78c7ab536505175238c38837"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FTimezone-List","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FTimezone-List/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FTimezone-List/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FTimezone-List/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JackieDo","download_url":"https://codeload.github.com/JackieDo/Timezone-List/tar.gz/refs/heads/5.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406111,"owners_count":20933806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","timezone","timezone-array","timezone-list","timezone-listbox"],"created_at":"2024-10-18T17:08:54.020Z","updated_at":"2025-04-05T22:10:31.208Z","avatar_url":"https://github.com/JackieDo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Timezone List\n\n[![Fix coding standards](https://github.com/JackieDo/Timezone-List/actions/workflows/fix-coding-standards.yml/badge.svg?branch=5.x)](https://github.com/JackieDo/Timezone-List/actions/workflows/fix-coding-standards.yml)\n[![Latest Stable Version](https://poser.pugx.org/jackiedo/timezonelist/v/stable)](https://packagist.org/packages/jackiedo/timezonelist)\n[![Total Downloads](https://poser.pugx.org/jackiedo/timezonelist/downloads)](https://packagist.org/packages/jackiedo/timezonelist)\n[![License](https://poser.pugx.org/jackiedo/timezonelist/license)](https://packagist.org/packages/jackiedo/timezonelist)\n\n# Overview\n\n- [Laravel Timezone List](#laravel-timezone-list)\n- [Overview](#overview)\n- [Feature](#feature)\n- [Versions and compatibility](#versions-and-compatibility)\n- [Documentation](#documentation)\n  - [Installation](#installation)\n    - [Step 1 - Require Package](#step-1---require-package)\n    - [Step 2 - Register Service Provider](#step-2---register-service-provider)\n    - [Step 3 - Register Facade Alias](#step-3---register-facade-alias)\n  - [Usage](#usage)\n    - [Working With Facade](#working-with-facade)\n    - [Using As Regular Class](#using-as-regular-class)\n  - [Available Methods](#available-methods)\n    - [Render a timezone listbox](#render-a-timezone-listbox)\n    - [Render a timezone array](#render-a-timezone-array)\n    - [Filter the returned list](#filter-the-returned-list)\n      - [Get only some specified groups](#get-only-some-specified-groups)\n      - [Exclude some specified groups](#exclude-some-specified-groups)\n    - [Change the layout of the returned list](#change-the-layout-of-the-returned-list)\n      - [Decide whether to split group or not](#decide-whether-to-split-group-or-not)\n      - [Decide whether to show the timezone offset or not](#decide-whether-to-show-the-timezone-offset-or-not)\n    - [Reset all config and return new list](#reset-all-config-and-return-new-list)\n- [Contributors](#contributors)\n- [License](#license)\n\n# Feature\n- Render a timezone listbox (select element) in Laravel\n- Render a timezone array in Laravel\n\n# Versions and compatibility\n\nCurrently, there are some branches of Timezone-List is compatible with the following version of Laravel framework\n\n| Timezone-List branch                                      | Laravel version |\n| --------------------------------------------------------- | --------------- |\n| [4.x](https://github.com/JackieDo/Timezone-List/tree/4.x) | 4.x             |\n| [5.x](https://github.com/JackieDo/Timezone-List/tree/5.x) | 5.x and later   |\n\n\u003e This documentation is use for branch 5.x\n\n# Documentation\n\n## Installation\n\nYou can install this package through [Composer](https://getcomposer.org) with the following steps:\n\n### Step 1 - Require Package\n\nAt the root of your application directory, run the following command (in any terminal client):\n\n```shell\n$ composer require jackiedo/timezonelist\n```\n\n\u003e **Note:** 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 and the Facade manually. Do the following steps:\n\n### Step 2 - Register Service Provider\n\nOpen `config/app.php`, and add a new line to the providers section:\n\n```php\n...\nJackiedo\\Timezonelist\\TimezonelistServiceProvider::class,\n```\n\n### Step 3 - Register Facade Alias\nAdd the following line to the aliases section in file `config/app.php`:\n\n```php\n'Timezonelist' =\u003e Jackiedo\\Timezonelist\\Facades\\Timezonelist::class,\n```\n\n## Usage\n\n### Working With Facade\n\nLaravel Timezone List has a facade with the fully qualified namespace is `Jackiedo\\Timezonelist\\Facades\\Timezonelist`. You can perform all operations through this facade.\n\n**Example:**\n\n```php\n\u003c?php\n\nnamespace Your\\Namespace;\n\nuse Jackiedo\\Timezonelist\\Facades\\Timezonelist;\n\nclass YourClass\n{\n    public function yourMethod()\n    {\n        $return = Timezonelist::doSomething();\n    }\n}\n\n```\n\n\u003e **Note:** If at the installation step, you have registered the Facde alias, then in the areas where the namespace is not used, eg views..., you can completely use that Facde alias to use instead of having to use the fully qualified Facde namespace.\n\n**Example:** _(use in the `resources/views/demo.blade.php` file)_\n\n```php\n\u003cdiv class=\"form-group\"\u003e\n    {!! Timezonelist::doSomething() !!}\n\u003c/div\u003e\n```\n\n### Using As Regular Class\n\nYou can completely use the package through the `Jackiedo\\Timezonelist\\Timezonelist` class like using a regular object class.\n\n**Example:**\n\n```php\nnamespace Your\\Namespace;\n\nuse Jackiedo\\Timezonelist\\Timezonelist;\n\nclass YourClass\n{\n    public function yourMethod()\n    {\n        $timezoneList = new Timezonelist;\n\n        $return = $timezoneList-\u003edoSomething();\n    }\n}\n\n```\n\n## Available Methods\n\n### Render a timezone listbox\n\n**Syntax:**\n\n```php\n/**\n * Create a select box of timezones.\n *\n * @param string            $name       The name of the select tag\n * @param null|string       $selected   The selected value\n * @param null|array|string $attr       The HTML attributes of select thag\n * @param bool              $htmlencode Use HTML entities for values of select tag\n *\n * @return string\n */\npublic function toSelectBox($name, $selected = null, $attr = null, $htmlencode = true);\n\n/**\n * Alias of the `toSelectBox()` method.\n *\n * @deprecated 6.0.0 This method name no longer matches the semantics\n */\npublic function create($name, $selected = null, $attr = null, $htmlencode = true);\n```\n\u003e Note: the `create()` method will be removed in the version 6.x\n\n**Example:**\n\n```php\necho Timezonelist::toSelectBox('timezone');\n```\n\nThis will output the following HTML code:\n\n```html\n\u003cselect name=\"timezone\"\u003e\n    \u003coptgroup label=\"General\"\u003e\n        \u003coption value=\"GMT\"\u003eGMT timezone\u003c/option\u003e\n        \u003coption value=\"UTC\"\u003eUTC timezone\u003c/option\u003e\n    \u003c/optgroup\u003e\n    \u003coptgroup label=\"Africa\"\u003e\n        \u003coption value=\"Africa/Abidjan\"\u003e(GMT/UTC + 00:00) Abidjan\u003c/option\u003e\n        \u003coption value=\"Africa/Accra\"\u003e(GMT/UTC + 00:00) Accra\u003c/option\u003e\n        \u003coption value=\"Africa/Addis_Ababa\"\u003e(GMT/UTC + 03:00) Addis Ababa\u003c/option\u003e\n        \u003coption value=\"Africa/Algiers\"\u003e(GMT/UTC + 01:00) Algiers\u003c/option\u003e\n        \u003coption value=\"Africa/Asmara\"\u003e(GMT/UTC + 03:00) Asmara\u003c/option\u003e\n        \u003coption value=\"Africa/Bamako\"\u003e(GMT/UTC + 00:00) Bamako\u003c/option\u003e\n        \u003coption value=\"Africa/Bangui\"\u003e(GMT/UTC + 01:00) Bangui\u003c/option\u003e\n        \u003coption value=\"Africa/Banjul\"\u003e(GMT/UTC + 00:00) Banjul\u003c/option\u003e\n        \u003coption value=\"Africa/Bissau\"\u003e(GMT/UTC + 00:00) Bissau\u003c/option\u003e\n\n        ...\n    \u003c/optgroup\u003e\n    \u003coptgroup label=\"America\"\u003e\n        \u003coption value=\"America/Adak\"\u003e(GMT/UTC - 10:00) Adak\u003c/option\u003e\n        \u003coption value=\"America/Anchorage\"\u003e(GMT/UTC - 09:00) Anchorage\u003c/option\u003e\n        \u003coption value=\"America/Anguilla\"\u003e(GMT/UTC - 04:00) Anguilla\u003c/option\u003e\n        \u003coption value=\"America/Antigua\"\u003e(GMT/UTC - 04:00) Antigua\u003c/option\u003e\n        \u003coption value=\"America/Araguaina\"\u003e(GMT/UTC - 03:00) Araguaina\u003c/option\u003e\n        \u003coption value=\"America/Argentina/Buenos_Aires\"\u003e(GMT/UTC - 03:00) Argentina/Buenos Aires\u003c/option\u003e\n        \u003coption value=\"America/Argentina/Catamarca\"\u003e(GMT/UTC - 03:00) Argentina/Catamarca\u003c/option\u003e\n        \u003coption value=\"America/Argentina/Cordoba\"\u003e(GMT/UTC - 03:00) Argentina/Cordoba\u003c/option\u003e\n        \u003coption value=\"America/Argentina/Jujuy\"\u003e(GMT/UTC - 03:00) Argentina/Jujuy\u003c/option\u003e\n\n        ...\n    \u003c/optgroup\u003e\n\n    ...\n\u003c/select\u003e\n```\n\n\u003e The `Timezonelist::toSelectBox()` method has four parameters:\n\n- The first parameter is required, it is the name attribute of the rendered select tag\n- The second parameter use to set selected value of list box.\n- The third parameter use to set HTML attribute of select tag.\n- The fourth parameter allow to use some HTML entities in the rendered select tag. The purpose is to make the element look better.\n\n**Example:**\n\n```php\n// Render a select tag with the name `timezone` and the `Africa/Asmara` option preselected\nTimezonelist::toSelectBox('timezone', 'Africa/Asmara');\n\n// Render tag with some HTML attributes\nTimezonelist::toSelectBox('timezone', null, [\n    'id'    =\u003e 'timezone',\n    'class' =\u003e 'styled',\n    ...\n]);\n\n// Or with other method\nTimezonelist::toSelectBox('timezone', null, 'id=\"timezone\" class=\"styled\"');\n```\n\n\u003e Example of the difference of the `fourth parameter`\n\n![Example-render-select-tag](https://user-images.githubusercontent.com/9862115/158339796-c58a6447-8564-4976-a4e7-2b7f9807276d.jpg)\n\n### Render a timezone array\n\n**Syntax:**\n\n```php\n/**\n * Create a timezone array.\n *\n * @param bool $htmlencode Use HTML entities for items\n *\n * @return mixed\n */\npublic function toArray($htmlencode = true);\n```\n\n**Example:**\n\n```php\n$timezoneList = Timezonelist::toArray(false);\n\n// The returned list will be\n// [\n//     \"General\" =\u003e [\n//         \"GMT\" =\u003e \"(GMT/UTC + 00:00) GMT\",\n//         \"UTC\" =\u003e \"(GMT/UTC + 00:00) UTC\",\n//     ],\n//     \"Africa\" =\u003e [\n//         \"Africa/Abidjan \"    =\u003e \"(GMT/UTC + 00:00) Abidjan\",\n//         \"Africa/Accra\"       =\u003e \"(GMT/UTC + 00:00) Accra\",\n//         \"Africa/Addis_Ababa\" =\u003e \"(GMT/UTC + 03:00) AddisAbaba\",\n//         \"Africa/Algiers\"     =\u003e \"(GMT/UTC + 01:00) Algiers\",\n//         \"Africa/Asmara\"      =\u003e \"(GMT/UTC + 03:00) Asmara\",\n//         ...\n//     ],\n//     \"America\" =\u003e [\n//         \"America/Adak\"      =\u003e \"(GMT/UTC - 09:00) Adak\",\n//         \"America/Anchorage\" =\u003e \"(GMT/UTC - 08:00) Anchorage\",\n//         \"America/Anguilla\"  =\u003e \"(GMT/UTC - 04:00) Anguilla\",\n//         \"America/Antigua\"   =\u003e \"(GMT/UTC - 04:00) Antigua\",\n//         \"America/Araguaina\" =\u003e \"(GMT/UTC - 03:00) Araguaina\",\n//         ...\n//     ],\n//     ...\n// ]\n```\n\n### Filter the returned list\n\nBy default, the `toSelectBox`, `toArray`... methods will return a list of timezones consisting of 11 groups (one common group and 10 groups corresponding to the continents):\n\n- General\n- Africa\n- America\n- Antarctica\n- Arctic\n- Asia\n- Atlantic\n- Australia\n- Europe\n- Indian\n- Pacific\n\nIn some cases, we don't want to get in that list some specified groups, we can do that by some of the following methods:\n\n#### Get only some specified groups\n\n**Syntax:**\n\n```php\n/**\n * Set the filter of the groups want to get.\n *\n * @param array $groups\n *\n * @return $this\n */\npublic function onlyGroups($groups = []);\n```\n\n**Example:**\n\n```php\n...\n$return = Timezonelist::onlyGroups(['Asia', 'America'])-\u003etoSelectBox('timezone');\n```\n\n#### Exclude some specified groups\n\n**Syntax:**\n\n```php\n/**\n * Set the filter of the groups do not want to get.\n *\n * @param array $groups\n *\n * @return $this\n */\npublic function excludeGroups($groups = []);\n```\n\n**Example:**\n\n```php\n...\n$return = Timezonelist::excludeGroups(['General'])-\u003etoArray();\n```\n\n### Change the layout of the returned list\n\nIn some cases, we need to change the form of the list that we will receive, we can do it through some of the following methods:\n\n#### Decide whether to split group or not\n\n**Syntax:**\n\n```php\n/**\n * Decide whether to split group or not.\n *\n * @param bool $status\n *\n * @return $this\n */\npublic function splitGroup($status = true);\n```\n\n**Example:**\n\n```php\n$return = Timezonelist::splitGroup(false)-\u003eexcludeGroups(['General'])-\u003etoSelectBox('timezone');\n```\n\n#### Decide whether to show the timezone offset or not\n\n**Syntax:**\n\n```php\n/**\n * Decide whether to show the offset or not.\n *\n * @param bool $status\n *\n * @return $this\n */\npublic function showOffset($status = true);\n```\n\n**Example:**\n\n```php\n$return = Timezonelist::showOffset(false)-\u003eexcludeGroups(['General'])-\u003etoSelectBox('timezone');\n```\n\n### Reset all config and return new list\n\nAlways keep in mind that, if we use package methods via Facade, we are using it as a `static` interface to a class. This means that the filter and layout settings will always be saved for the next call. If we don't want to reuse these settings, we have to execute the following method on the next call:\n\n**Syntax:**\n\n```php\n/**\n * Return new static to reset all config.\n *\n * @return $this\n */\npublic function reset();\n```\n\n**Example:**\n\n```php\n// Genrate one select box, exclude two groups of timezones, Asia and Africa\n$selectBox = Timezonelist::excludeGroups(['Asia', 'Africa'])-\u003etoSelectBox('timezone');\n\n$list1 = Timezonelist::toArray();         // Two groups, Asia and Africa, will not be loaded into the result\n$list2 = Timezonelist::reset()-\u003etoArray() // All groups will be loaded\n```\n\n# Contributors\nThis project exists thanks to all its [contributors](https://github.com/JackieDo/Timezone-List/graphs/contributors).\n\n# License\n[MIT](LICENSE) © Jackie Do","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackiedo%2Ftimezone-list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackiedo%2Ftimezone-list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackiedo%2Ftimezone-list/lists"}