2017 © Pedro Peláez
 

library ranger

Formatter for date and time ranges with i18n support

image

openpsa/ranger

Formatter for date and time ranges with i18n support

  • Monday, July 23, 2018
  • by flack
  • Repository
  • 1 Watchers
  • 1 Stars
  • 7,284 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 6 Versions
  • 7 % Grown

The README.md

Ranger

Ranger is a formatter for date and time ranges, based (somewhat loosely) on Adam Shaw's formatRange algorithm in fullCalendar., (*1)

Some Examples

<?php
use OpenPsa\Ranger\Ranger;

$ranger = new Ranger('en');
echo $ranger->format('2013-10-05', '2013-10-20');
// Oct 5–20, 2013
echo $ranger->format('2013-10-05', '2013-11-20');
// Oct 5 – Nov 20, 2013

$ranger = new Ranger('en_GB');
echo $ranger->format('2013-10-05', '2013-10-20');
// 5–20 Oct 2013
echo $ranger->format('2013-10-05', '2013-11-20');
// 5 Oct – 20 Nov 2013

$ranger = new Ranger('de');
echo $ranger->format('2013-10-05', '2013-10-20');
// 05.–20.10.2013
echo $ranger->format('2013-10-05', '2013-11-20');
// 05.10.–20.11.2013

Usage

To use Ranger in any other locale than "en", you will need to have the php-intl extension installed., (*2)

Instantiate ranger with the name of your locale as the parameter. You can also pass null to use the ini.default_locale setting. Afterwards, you can call format() with two date parameters. Accepted types are, (*3)

  • DateTime objects
  • strings (any format that DateTime can read)
  • Unix timestamps
  • null (which means current date).

Output Customization

<?php
use OpenPsa\Ranger\Ranger;
use IntlDateFormatter;

$ranger = new Ranger('en');
$ranger
    ->setRangeSeparator(' and ')
    ->setDateTimeSeparator(', between ')
    ->setDateType(IntlDateFormatter::LONG)
    ->setTimeType(IntlDateFormatter::SHORT);

echo $ranger->format('2013-10-05 10:00:01', '2013-10-05 13:30:00');
// October 5, 2013, between 10:00 AM and 1:30 PM

The Versions

23/07 2018

dev-master

9999999-dev

Formatter for date and time ranges with i18n support

  Sources   Download

MIT

The Requires

 

date range time range

23/07 2018

v0.4.0

0.4.0.0

Formatter for date and time ranges with i18n support

  Sources   Download

MIT

The Requires

 

date range time range

26/03 2018

v0.3.1

0.3.1.0

Formatter for date and time ranges with i18n support

  Sources   Download

MIT

The Requires

 

date range time range

19/09 2017

v0.3.0

0.3.0.0

Formatter for date and time ranges with i18n support

  Sources   Download

MIT

The Requires

 

date range time range

19/09 2017

v0.2.0

0.2.0.0

Formatter for date and time ranges with i18n support

  Sources   Download

MIT

The Requires

 

date range time range

09/03 2016

v0.1.0

0.1.0.0

Formatter for date and time ranges with i18n support

  Sources   Download

MIT

The Requires

 

date range time range