2017 © Pedro Peláez
 

library daterange

Provides a way to display dateranges

image

org_heigl/daterange

Provides a way to display dateranges

  • Thursday, March 12, 2015
  • by heiglandreas
  • Repository
  • 1 Watchers
  • 2 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 2 % Grown

The README.md

org.heigl.DateRange

This small library tries to ease printing of date-ranges., (*1)

Build Status Code Climate Test Coverage Coverage Status, (*2)

Installation

Installation is easy via composer. Simply type this in your terminal to add the DateRange-Library to your composer.conf-file:, (*3)

composer require org_heigl/daterange

Usage

You can then use the DateRange library by creating a DateRange-instance, setting a format and a separator and then simply calling getDateRange() with the start-date and the end date as parameters., (*4)

Simple example:, (*5)

<?php
use Org_Heigl\DateRange\DateRangeFormatter

$dateRange = new DateRangeFormatter();
$dateRange->setFormat('d.m.Y');
$dateRange->setSeparator(' - ');
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.4.2015'));
// Will print: 12.03. - 13.04.2014
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015'));
// Will print: 12. - 13.03.2014

More complex example:, (*6)

<?php
use Org_Heigl\DateRange\DateRangeFormatter

$dateRange = new DateRangeFormatter();
$dateRange->setFormat('m/d/Y');
$dateRange->setSeparator(' - ');
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015'));
// Will print: 3/12/ - 3/13/2014

You want to change parts of the date-formatting string? Try the Filters., (*7)

If you want to display something like 12 - 13.03.2013 (node the missing dot after the 12) you can use the formatting-string d.m.Y and add a RemoveEverythingAfterLastDateStringFilter lik this:, (*8)

<?php
use Org_Heigl\DateRange\DateRangeFormatter;
use Org_Heigl\DateRange\Filter\RemoveEverythingAfterLastDateStringFilter;

$dateRange = new DateRangeFormatter();
$dateRange->setFormat('d.m.Y');
$dateRange->setSeparator(' - ');
$dateRange->addFilter(new RemoveEverythingAfterLastDateStringFilter(), DateRangeFormatter::FILTER_FIRST_DIFF);
echo $dateRange->getDateRange(new \DateTime('12.3.2015'), new \DateTime('13.3.2015'));
// Will print: 12 - 13.03.2014

Currently the following Filters are available:, (*9)

  • RemoveEverythingAfterLastDateStringFilter - This filter will remove everything after the last dateformatting-character in the given date-part. So when the dateformatting-string reads d.m. it will remove everything behind the m which is the last dateformatting-character.
  • TrimFilter - This filter will remove excess whitespace. It just passes the dateformatting-string through the ```trim``-function.

You can implement your own filter by simply implementing the Org_Heigl\DateRange\DateRangeFilterInterface That way evertything is possible!, (*10)

You can add a filter to four different filterchains that filter different parts of the formatting string., (*11)

  • DateRangeFormatter::FILTER_COMPLETE will be applied to a formatting string when first and second day are the same. So the input will be the formatting-string you provided via the DateRangeFormatter::setFormat().
  • DateRangeFormatter::FILTER_FIRST_DIFF will be applied to the first part of the splitted formatting string that is used for the start-date. So when your formatting string is d.m.Y and the dates differ in the month the filter will be applied to d.m. for the starting date
  • DateRangeFormatter::FILTER_SECOND_DIFF will be applied to the first part of the splitted formatting string that is used for the end-date. So when your formatting-string is d.m.Y and the dates differ in the month the filter will be applied to d.m. for the end-date
  • DateRangeFormatter::FILTER_SAME will be applied to the second part of the splitted formatting string that is used for the part that is equal on start- and end-date. So when your formatting-string is d.m.Y and the dates differ in the day the filter will be applied to m.Y.

The Versions

12/03 2015

dev-master

9999999-dev http://github.com/heiglandreas/daterange

Provides a way to display dateranges

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

date range datetime daterange

12/03 2015

1.2.0

1.2.0.0 http://github.com/heiglandreas/daterange

Provides a way to display dateranges

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

date range datetime daterange

12/03 2015

dev-feature/addFilter

dev-feature/addFilter http://github.com/heiglandreas/daterange

Provides a way to display dateranges

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

date range datetime daterange

11/03 2015

dev-feature/removeSeparator

dev-feature/removeSeparator http://github.com/heiglandreas/daterange

Provides a way to display dateranges

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

date range datetime daterange

08/03 2015

1.1.0

1.1.0.0 http://github.com/heiglandreas/daterange

Provides a way to display dateranges

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

date range datetime daterange

03/03 2015

1.0.0

1.0.0.0 http://github.com/heiglandreas/daterange

Provides a way to display dateranges

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

date range datetime daterange