Relative Date enables Kirby CMS to display date and time in a human-readable format. It converts your absolute date (and time) in something relative and more readable. It is built on the Carbon library and offers access to all its methods.
Kirby CMS 2.3.0+ and PHP 5.4+.
- Download the current release.
- Add the files to
site/plugins/relative-date/
With the Kirby CLI
kirby plugin:install distantnative/relative-date
You can either use it as field method:
<?= $page->published()->relativeDate() ?>
Or as Kirbytext tag:
Published: (relativeDate: 2015-02-15)
Or with the relativeDate()
global helper function:
<?= relativeDate($page->modified()) ?>
Relative Date is a wrapper for a Carbon instance and only when echoed, shows the diffForHumans()
method of Carbon. However, you can also use it for all other methods of Carbon, e.g.:
<?php
$relativeDate = relativeDate($page->modified());
echo $relativeDate->addDays(5)->diffForHumans();
echo $relativeDate->isBirthday()
…
?>
If you have any suggestions for further configuration options, please let me know.
- This plugin cannot be used with the Kirby's default date field as it is not chainable. Please use the plugin on a field named differently than
date
, e.g.published
. As another workaround thedate
field could be passed directly to therelativeDate()
helper function:
<?= relativeDate($page->date('Y-m-d')) ?>
You can find a more or less complete version history in the changelog.
Nico Hoffmann - https://nhoffmann.com