2017 © Pedro Peláez
 

library ht-time-zone

HtTimeZone is a Zend Framework 2 module to simplify working with timezones. This module is useful when your application users are located all around the world.

image

hrevert/ht-time-zone

HtTimeZone is a Zend Framework 2 module to simplify working with timezones. This module is useful when your application users are located all around the world.

  • Tuesday, August 12, 2014
  • by hrevert
  • Repository
  • 2 Watchers
  • 3 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 4 Versions
  • 13 % Grown

The README.md

HtTimeZone

HtTimeZone is a Zend Framework 2 module to simplify working with timezones. This module is useful when your application users are located all around the world. To use this module you will have to store all the dates in a fixed timezone(UTC is recommended)., (*1)

Installation

  1. Add "hrevert/ht-time-zone": "dev-master", to your composer.json and run php composer.phar update
  2. Enable the module in config/application.config.php
  3. Copy file located in ./vendor/hrevert/ht-time-zone/config/ht-time-zone.global.php to ./config/autoload/ht-time-zone.global.php and change the values as you wish

Documentation

Doctrine Types

If you use doctrine DBAL, then you can use DBAL types provided this module which automate timezone conversion., (*2)

Included DBAL types

  1. HtTimeZone\DBAL\Types\UTCDateTimeType
  2. HtTimeZone\DBAL\Types\UTCTimeType
  3. HtTimeZone\DBAL\Types\TimeZoneType

Usage

/**
 * @Entity
 * @Table(name="myEvent)
 */
class Event
{
    ...

    /**
     * @Column(type="UTCDateTime")
     * @var DateTime
     */
     protected $datetime;

    ...
}

Suppose, you want to store user's timezone;, (*3)

<?php
/**
 * @Entity
 * @Table(name="user)
 */
class User
{
    ...

    /**
     * @Column(type="TimeZone")
     * @var DateTimeZone
     */
     protected $timeZone;

    ...
} 

Suppose you want to store time in other timezone (NOT UTC), say Asia/Kathmandu., (*4)

<?php
namespace Application\DBAL\Types;

use DateTimeZone;

class KtmDateTimeType extends AbstractTimeZoneDateTimeType
{
    /**
     * @var null|DateTimeZone 
     */
    static private $dateTimeZone = null;

    /**
     * {@inheritDoc}
     */
    protected function getDateTimeZone()
    {
        return (self::$dateTimeZone) ? self::$dateTimeZone : (self::$dateTimeZone = new DateTimeZone('Asia/Kathmandu'));
    }
}

return [
    'doctrine' => [
        'configuration' => [
            'orm_default' => [
                'types' => [
                    'ktmdatetime' => 'Application\DBAL\Types\KtmDateTimeType',
                ],
            ]
        ],
    ],
];

Filters

This module comes with some filters related to timezone. If you don`t know filters, this should be the first one to read., (*5)

Included filters

  1. HtTimeZone\Filter\TimeZoneConverter
  2. ClientToServerTimeZone
  3. ServerToClientTimeZone

Usage

HtTimeZone\Filter\TimeZoneConverter

This filter is pretty simple., (*6)

$filter = new HtTimeZone\Filter\TimeZoneConverter($fromTimeZone, $toTimeZone);
echo $filter->filter(new DateTime());

To get more understanding of how this filter works, the best way is to dig the code here., (*7)

HtTimeZone\Filter\ServerToClientTimeZone
$filter = $this->getServiceLocator()->get('FilterManager')->get('ServerToClientTimeZone');
echo $filter->filter(new DateTime());
HtTimeZone\Filter\ClientToServerTimeZone
$filter = $this->getServiceLocator()->get('FilterManager')->get('ClientToServerTimeZone');
echo $filter->filter(new DateTime());

Using View Helpers

This module comes with two view helpers to make our life easier., (*8)

  1. htTimeZone
  2. htTimeInterval

Basic Usage

htTimeZone

This view helper sets timezone of a DateTime instance to that of client's timezone. Thats it! This view helper is useful to display date in client's timezone!, (*9)

$dateTime = new DateTime();
echo $this->htTimeZone($dateTime)->format('d/m/Y H:i');// will print according to user`s timezone
htTimeInterval

This view helper is to display something like 5 minutes ago., (*10)

echo $this->htTimeInterval(new DateTime()); // will print `Just Now`
echo $this->htTimeInterval(time() - 10); // will print `10 seconds ago`

Hydrator Strategies

  1. HtTimeZone\Stdlib\Hydrator\Strategy\TimeZoneConverter
  2. HtTimeZone\Stdlib\Hydrator\Strategy\TimeZoneStringStrategy

WIP

This is a work in progress. Use at your own risk!, (*11)

The Versions

12/08 2014

dev-master

9999999-dev https://github.com/hrevert/HtTimeZone

HtTimeZone is a Zend Framework 2 module to simplify working with timezones. This module is useful when your application users are located all around the world.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ojhaujjwal
by Hrevert Technologies

zf2 date module datetime timezone

14/05 2014

dev-feature/clientside-detect

dev-feature/clientside-detect https://github.com/hrevert/HtTimeZone

HtTimeZone is a Zend Framework 2 module to simplify working with timezones. This module is useful when your application users are located all around the world.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ojhaujjwal
by Hrevert Technologies

zf2 date module datetime timezone

13/05 2014

dev-feature/maxmind-timezone-provider

dev-feature/maxmind-timezone-provider https://github.com/hrevert/HtTimeZone

HtTimeZone is a Zend Framework 2 module to simplify working with timezones. This module is useful when your application users are located all around the world.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ojhaujjwal
by Hrevert Technologies

zf2 date module datetime timezone

25/04 2014

dev-timezone-hydrator-strategy

dev-timezone-hydrator-strategy https://github.com/hrevert/HtTimeZone

HtTimeZone is a Zend Framework 2 module to simplify working with timezones. This module is useful when your application users are located all around the world.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar ojhaujjwal
by Hrevert Technologies

zf2 module timezone