Download the PHP package mpratt/relativetime without Composer
On this page you can find all versions of the php package mpratt/relativetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mpratt/relativetime
More information about mpratt/relativetime
Files in mpratt/relativetime
Package relativetime
Short Description A library that calculates the time difference between two dates and returns the result in words (Example: 5 minutes ago or 5 Minutes left). The library supports other languages aswell like Spanish and German.
License MIT
Homepage https://github.com/mpratt/RelativeTime
Informations about the package relativetime
RelativeTime
RelativeTime is a lightweight and easy to use library that helps you calculate the time difference between two dates and returns the result in words
(like, 5 minutes ago or 5 minutes left). The library supports other languages as well like Spanish
, PortugueseBR
, French
, Czech
, Russian
,
SimplifiedChinese
, Swedish
and German
It uses the standard \DateTime() and \DateInterval() classes found in modern PHP versions. For more information, please read the Usage
section of
this README.
Requirements
- PHP >= 5.3 (Tested only on PHP +7.3)
Installation
Install with Composer
If you're using Composer to manage dependencies, you can use this library by creating a composer.json file and adding this:
{
"require": {
"mpratt/relativetime": "~1.0"
}
}
Save it and run composer.phar install
Standalone Installation (without Composer)
Download the latest release or clone this repository, place the Lib/RelativeTime
directory somewhere in your project. Afterwards, you only need to include
the included Autoload.php
file.
Or if you already have PSR-0 compliant autoloader, you just need to register RelativeTime:
Usage
Most of the times you are going to need the convert($fromDate, $toDate)
method.
There are 2 other useful methods timeAgo($date)
and timeLeft($date)
, that calculate the time since/until
the current date/time.
Configuration Options
The main object accepts an array with configuration directives
Directive | Definition |
---|---|
language | The language to be used, for example English , Spanish , PortugueseBR , French , Czech , Russian , SimplifiedChinese , Swedish or German are supported. Even The instantiated object is allowed, as in new \RelativeTime\Languages\English() |
separator | The separator between time units. , by default. |
truncate | The number of units you want to display. By default it displays all of the available ones. |
suffix | Whether or not to append the .... ago or ..... left |
use_weeks | By default is set to false. When set to true it will include week numbers too. |
Author
Michael Pratt - http://www.michael-pratt.com See also the list of contributors which participated in this project.
If you like this library, it has been useful to you and want to support me, you can do it via paypal.
License
RelativeTime is licensed under the MIT License - see the LICENSE file for details