org_heigl/date-formatter

Extendable Library to format DateTimes using Zend-Frameworks Date-Constants

1.1.0 2016-03-25 15:59 UTC

This package is auto-updated.

Last update: 2024-12-23 09:39:26 UTC


README

Build Status Code Climate Test Coverage Scrutinizer Code Quality

Extendable Library to format DateTimes using Zend-Frameworks Date-Constants

Installation

composer require org_heigl/date-formatter

Usage

use Org_Heigl\DateFormatter\FormatterFacade as Formatter;

$date = new DateTime('2013-12-03 12:23:34', new DateTimeZone('Europe/Berlin'));

echo Formatter::format($date, 'PDF');
// Prints "20131203122334+01'00'"

Currently the following formatters are available:

  • PDF
  • ATOM
  • COOKIE
  • RFC_822
  • RFC_850
  • RFC_1036
  • RFC_1123
  • RFC_3339
  • RSS
  • W3C
  • MYSQL

Extending

You can add your own formatter by creating a class that implements the Org_Heigl\DateFormatter\Formatter\FormatterInterface. This class can then either be used directly like in this example:

use Org_Heigl\DateFormatter\DateFormatter as Formatter;

$formatter = new Formatter(new MyCoolClassImplementingFormatterInterface());

$date = new DateTime('2013-12-03 12:23:34', new DateTimeZone('Europe/Berlin'));

echo $formatter->format($date);
// Prints whatever you formatted the given date to ;)

To be able to use it with the FormatterFacade you have to announce the Folder containing the formatter to the class like in this example:

use Org_Heigl\DateFormatter\FormatterFacade as Formatter;

// Announce the Folder containing your formatter to the class
Formatter::addFormatterFolder('/absolute/Path/To/Your/Formatter/Folder');

$date = new DateTime('2013-12-03 12:23:34', new DateTimeZone('Europe/Berlin'));

echo Formatter::format($date, 'WhateverYouCalledYourFormatter');
// Prints WhateverYourFormatterDoes ;)

Self-Defined formatters will always be called instead of default formatters. So when you have a formatter for "PDF" in your added folder that formatter will be called instead of the default formatter!