Download the PHP package smirik/php-datetime-ago without Composer
On this page you can find all versions of the php package smirik/php-datetime-ago. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smirik/php-datetime-ago
More information about smirik/php-datetime-ago
Files in smirik/php-datetime-ago
Package php-datetime-ago
Short Description How much time ago in text format
License MIT
Informations about the package php-datetime-ago
php-datetime-ago
This library helps to format the date/time interval into text.
Examples
Condition | Text |
---|---|
Now | now |
Less than an hour | xx minutes ago |
Between 1 and 2 hours | 1 hour ago |
Between 2 and 24 hours | xx hours ago |
Between 1 and 2 days | 1 day ago |
Between 2 and 6 days | xx days ago |
7 or more days ago | xx weeks ago |
30 or more days ago | xx months ago |
365 or more days ago | xx years ago |
Notice that not every translator supports weeks, months and years
Usage
DateTimeAgo
class has public method get
. It accepts 1 required argument (\DateTime
object) and 1 optional (reference date. If it is null
, current time is used).
Russian translation:
Customization
Date formatter for more than 6 days
This setup date in format 01.01.2001 22:52:12
.
Custom translator
The DateTimeAgo constructor accept TextTranslator
file as the first argument. By default EnglishTextTranslator
is provided. You can add your custom translator to this constructor. Just make sure that your class implements Smirik\PHPDateTimeAgo\TextTranslator\TextTranslatorInterface
. There is also standard way for translations based on pluralization procedure. The methods are already implemented for any language in AbstractTextTranslator
class. English & Russian samples are already included in this package. You can also change the translator after creation:
Implementation
- How to integrate library with Symfony2
Tests
Most parts of the code are tested via phpspec
. To run the tests clone the repository and run
Development workflow
- In order to keep git versioning accurate please use git-flow pattern.
- So all pull requests except hotfix should go to the develop branch.
- Hotfix should go to both development branches: develop & master at the same time.
Contribution
Any contribution is welcome.
Acknowledgements
- Symfony cookbook for Russian pluralization rule.