2017 © Pedro PelĂĄez
 

library daterange

Display a range of dates, with consolidated time parts.

image

gamajo/daterange

Display a range of dates, with consolidated time parts.

  • Sunday, June 3, 2018
  • by GaryJones
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 4 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Gamajo Date Range

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Display a range of dates, with consolidated time parts., (*2)

Table Of Contents

Installation

The best way to use this package is through Composer:, (*3)

composer require gamajo/daterange

Basic Usage

Create an instance of the DateRange class, with DateTimeImmutable or DateTime start and end date-time objects as arguments. Then choose the format to use as the end date output. The start date will only display the time parts that are not duplicated., (*4)

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18 14:00'),
    new DateTimeImmutable('2018-06-23T15:00')
);
echo $dateRange->format('H:i d M Y'); // 14:00 – 15:00 23 Jun 2018

If the formatted date would be the same start and end date, only a single date is displayed:, (*5)

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18 14:00'),
    new DateTimeImmutable('2018-06-23T15:00')
);
echo $dateRange->format('jS M Y'); // 23rd Jun 2018

Advanced Usage

Change Separator

The default separator between the start and end date, is a space, en-dash, space: ' – ', (*6)

This can be changed via the changeSeparator() method:, (*7)

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18 14:00'),
    new DateTimeImmutable('2018-06-23T15:00')
);
$dateRange->changeSeparator(' to ');
echo 'From ', $dateRange->format('H:i d M Y'); // From 14:00 to 15:00 23 Jun 2018

Change Removable Delimiters

The consolidation and removal of some time parts may leave delimiters from the format:, (*8)

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18'),
    new DateTimeImmutable('2018-06-24')
);
echo $dateRange->format('d·M·Y'); //  23·· – 24·Jun·2018

Be default, /, - and . are trimmed from the start date, but this can be amended with the changeRemovableDelimiters() method:, (*9)

$dateRange = new DateRange(
    new DateTimeImmutable('23rd June 18'),
    new DateTimeImmutable('2018-06-24')
);
$dateRange->changeRemovableDelimiters('·');
echo $dateRange->format('d·M·Y'); //  23 – 24·Jun·2018

Known Issues

These are known issues which need addressing before this package can be considered stable:, (*10)

Contributing

All feedback, bug reports and pull requests are welcome., (*11)

License

Copyright (c) 2018 Gary Jones, Gamajo, (*12)

This code is licensed under the MIT License., (*13)

The Versions