2017 © Pedro Peláez
 

library relative-time

Library for building relative time strings in PHP.

image

salernolabs/relative-time

Library for building relative time strings in PHP.

  • Friday, April 28, 2017
  • by ericsalerno
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 25 % Grown

The README.md

salernolabs/relative-time

Latest Stable Version License Build Status, (*1)

Library for building relative time strings in PHP., (*2)

Usage

Installation

First include this project with composer, (*3)

composer require salernolabs/relative-time

Formatting Time

Then run the formatter on a DateTime object., (*4)

$formatter = new \SalernoLabs\RelativeTime\Formatter();
$relativeTime = $formatter->getRelativeTime(new \DateTime('-47 minutes'));
echo $relativeTime;

This would output '47 minutes ago'. The formatter will also go forward as well so if you put in '+47 minutes' it will say "47 mintues from now"., (*5)

Examples of Time Reformatting

This library will also give short-hand conversational outputs for some values. For example:, (*6)

Time Modification Output
-5 minutes just now
+5 minutes momentarily
-1 minute about a minute ago
+1 minute about a minute from now
-1 hour about an hour ago
+1 hour about an hour from now
-1 day yesterday
+1 day tomorrow

And actual numbers for other times, for example:, (*7)

Time Modification Output
-45 seconds 45 seconds ago
-45 minutes 45 minutes ago
-7 hours 7 hours ago
-3 years 3 years ago

HTML5 Tags

You can easily wrap the output in an html5 time tag by using the getRelativeTimeTag function., (*8)

$formatter = new \SalernoLabs\RelativeTime\Formatter();
$relativeTime = $formatter->getRelativeTimeTag(new \DateTime('-47 minutes'));
echo $relativeTime;

This would output:, (*9)

<time title="April 14th, 2017 - 4:14PM EDT">47 minutes ago</time>

Relative Time Clock

The relative time clock can give you a textual representation of a time of day., (*10)

$clock = new \SalernoLabs\RelativeTime\Clock();

$time = $clock
    ->setTime(new \DateTime('7:47'))
    ->getTime();

echo $time; // a quarter to eight o'clock

Examples of Relative Clock Output

Input Time Output
1:00 one o'clock
5:03 five o'clock,
2:07 almost ten after two o'clock,
3:10 ten after three o'clock
4:15 quarter after four o'clock
6:22 almost half past six o'clock
7:32 half past seven o'clock
8:44 almost a quarter to nine o'clock
9:45 a quarter to ten o'clock
11:55 almost twelve o'clock
12:00 twelve o'clock,
12:59 almost one o'clock
12:45 a quarter to one o'clock
12:43 almost a quarter to one o'clock

The Versions

28/04 2017

dev-master

9999999-dev http://www.salernolabs.com/

Library for building relative time strings in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php timestamp relative time

28/04 2017

0.2.1

0.2.1.0 http://www.salernolabs.com/

Library for building relative time strings in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php timestamp relative time

26/04 2017

0.2.0

0.2.0.0 http://www.salernolabs.com/

Library for building relative time strings in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php timestamp relative time

14/04 2017

0.1.0

0.1.0.0 http://www.salernolabs.com/

Library for building relative time strings in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php timestamp relative time

14/04 2017

0.1.1

0.1.1.0 http://www.salernolabs.com/

Library for building relative time strings in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php timestamp relative time