2017 © Pedro Peláez
 

library bench

Easy way to present user friendly time zones.

image

suadhuskic/bench

Easy way to present user friendly time zones.

  • Monday, October 16, 2017
  • by suadhuskic1@gmail.com
  • Repository
  • 2 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

[Bench]

Bench is a PHP library that helps you present user friendly time zones without having a database. You shouldn't be scared of time zones and you shouldn't present America/Los_Angeles as an option to the user., (*2)

Just to get your attention, heres an example:, (*3)

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Bench\Bench;

//get all the countries in the united states.
//A two-letter ISO 3166-1 compatible country code,
//the time to use when starting the instance. Carbon\Carbon will be used.
//true/false - do you want unique offsets per country.
$us_time_zones = Bench::getTimezones('US', 'now', true);

foreach($us_time_zones as $tz) {
    echo $tz->getName()."\n";
    echo $tz->getShortAbbr()."\n";
    echo $tz->getLongAbbr()."\n";
    echo $tz->getOffset()."\n";
    echo $tz."\n";
    echo "----------------------------\n";

}

The answer is YES. I do take Daylight/Standard into consideration. The abbreviations are generated after starting the Carbon instance using the $time you passed., (*4)

The code above will output:, (*5)


// America/Adak // HDT // Hawaii-Aleutian Daylight Time // -09:00 // (GMT -09:00) Hawaii-Aleutian Daylight Time // ---------------------------- // America/Anchorage // AKDT // Alaska Daylight Time // -08:00 // (GMT -08:00) Alaska Daylight Time // ---------------------------- // America/Boise // MDT // Mountain Daylight Time // -06:00 // (GMT -06:00) Mountain Daylight Time // ---------------------------- // America/Chicago // CDT // Central Daylight Time // -05:00 // (GMT -05:00) Central Daylight Time // ---------------------------- // America/Detroit // EDT // Eastern Daylight Time // -04:00 // (GMT -04:00) Eastern Daylight Time // ---------------------------- // America/Los_Angeles // PDT // Pacific Daylight Time // -07:00 // (GMT -07:00) Pacific Daylight Time // ---------------------------- // Pacific/Honolulu // HST // Hawaii Standard Time // -10:00 // (GMT -10:00) Hawaii Standard Time // ----------------------------

Installation

With Composer

$ composer require suadhuskic/bench

Getting an array of countries:, (*6)

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Bench\Bench;

//get the countries. time zones are lazy-loaded per country. they dont get loaded until you call the getter the first time.
$countries = Bench::getCountries();
print_r($countries[0]);

// Bench\Country Object
// (
//     [code:protected] => AF
//     [name:protected] => Afghanistan
//     [timeZones:protected] => Array
//         (
//         )
// 
// )

Or get a specific country. don't forget timezones are lazy-loaded., (*7)

<?php
require_once __DIR__ . '/vendor/autoload.php';

use Bench\Bench;

$country = Bench::getCountries('FR');
print_r($country);
// Bench\Country Object
// (
//     [code:protected] => FR
//     [name:protected] => France
//     [timeZones:protected] => Array
//         (
//         )
// 
// )

Now if you want the time zones for a country; call the getter:, (*8)

print_r($country->getTimezones());
// Array
// (
//     [0] => Bench\TimeZone Object
//         (
//             [carbon:protected] => Carbon\Carbon Object
//                 (
//                     [date] => 2017-08-17 01:42:33.593773
//                     [timezone_type] => 3
//                     [timezone] => Europe/Paris
//                 )
// 
//             [shortAbbr:protected] => CEST
//             [longAbbr:protected] => Central European Summer Time
//         )
// 
// )


getters for Bench\Country: - getCode - A two-letter ISO 3166-1 compatible country code. - getName - the full country name - getTimezones(string $time='now', bool $unqiueOffsets=false) - get all time zones., (*9)


We want to use Bench\Bench as the factory. Getting a Bench\TimeZone instance:, (*10)

```php <?php require_once DIR . '/vendor/autoload.php';, (*11)

use Bench\Bench;, (*12)

$timezone = Bench::createTimeZone('now', 'America/Los_Angeles');, (*13)

print_r($timezone); // Bench\TimeZone Object // ( // [carbon:protected] => Carbon\Carbon Object // ( // [date] => 2017-08-16 16:46:18.410848 // [timezone_type] => 3 // [timezone] => America/Los_Angeles // ) // // [shortAbbr:protected] => PDT // [longAbbr:protected] => Pacific Daylight Time // ), (*14)

``` getters for Bench\TimeZone: - getName - America/Los_Angeles - getShortAbbr - PDT - getLongAbbr - Pacific Daylight Time - getLongAbbrWithGMTOffset - (GMT -07:00) Pacific Daylight Time - getOffset(string $type='human') - human=-07:00, hours=-7, *=-25200, (*15)


The Versions

16/10 2017

dev-master

9999999-dev https://github.com/suadhuskic/Bench

Easy way to present user friendly time zones.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Suad Huskic

datetime timezone countries datetimezone

16/10 2017

1.2

1.2.0.0 https://github.com/suadhuskic/Bench

Easy way to present user friendly time zones.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Suad Huskic

datetime timezone countries datetimezone

19/08 2017

1.1

1.1.0.0 https://github.com/suadhuskic/Bench

Easy way to present user friendly time zones.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Suad Huskic

datetime timezone countries datetimezone

17/08 2017

1.0.1

1.0.1.0 https://github.com/suadhuskic/Bench

Easy way to present user friendly time zones.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Suad Huskic

datetime timezone countries datetimezone

17/08 2017

1.0.0

1.0.0.0 https://github.com/suadhuskic/Bench

Easy way to present user friendly time zones.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Suad Huskic

datetime timezone countries datetimezone