Download the PHP package wookieb/relative-date without Composer
On this page you can find all versions of the php package wookieb/relative-date. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wookieb/relative-date
More information about wookieb/relative-date
Files in wookieb/relative-date
Package relative-date
Short Description Fully configurable tool to calculate and show date diff in human readable form like "2 minutes ago" or "10 minutes from now".
License MIT
Informations about the package relative-date
Relative-date
Library that helps you compute human readable information about dates.
This is especially useful for such cases like:
- Computing time ago - "2 seconds ago", "yesterday"
- Computing time in the future - "within 5 seconds", "tomorrow at 14:00" (in progress)
Features
- Customizable rules and predefined rules (see calculators)
- Smart "yesterday" and "tomorrow" calculations
- Support for translations or any other customer formatter
- Symfony 2 and 3 integration via relative-date-bundle
Installation
Usage
Rationale
I've created this library because I was tired of tons of very simplistic relative date calculators that compute a result based on very strict, immutable rules. That's why relative-date consists of parts that allows you to redefine the whole logic of relative date computation that exactly suits to your needs.
You don't need "2 years ago" result since in most cases it's useless? Feel free to pick "upTo2Weeks" calculator and get exactly what you need!
Translation and support for different languages
Translations are supported via TranslatorFormatter.
Symfony users should use relative-date-bundle.
Calculators
TimeAgoCalculator::full
Computes result in one of the units:
- seconds
- minutes
- hours
- days
- weeks
- months
- years
TimeAgoCalculator::upTo2Weeks
Computes result in one of the units:
- seconds
- minutes
- "yesterday"
- hours
- days
- weeks (up to 14 days)
- full date (if date is older than 14 days)
TimeAgoCalculator::upTo2Days
Computes result in one of the units:
- seconds
- minutes
- "yesterday"
- hours
- full date (if date is older than "yesterday")
Customization
Translator and custom placeholders
By default TranslatorFormatter defines only one placeholder "%count%" for your translations. You can define custom ones, especially useful for more detailed final outputs.
Custom full date format
Every built-in Formatter supports date format string applied to results representing full date.