bkry-code / relative-date

Relative Date and Time (multi-language) plugin for Kirby 2 CMS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Relative Date for Kirby CMS

Release Issues Kirby Version

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.

Overview

  1. Requirements
  2. Installation
  3. Usage
  4. Help & Improve
  5. Known Issues)
  6. Version History

Requirements

Kirby CMS 2.3.0+ and PHP 5.4+.

Installation & Update

  1. Download the current release.
  2. Add the files to site/plugins/relative-date/

With the Kirby CLI

kirby plugin:install distantnative/relative-date

Usage

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()) ?>

Use Carbon

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()
…

?>

Help & Improve

If you have any suggestions for further configuration options, please let me know.

Known Issues

  • 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 the date field could be passed directly to the relativeDate() helper function:
<?= relativeDate($page->date('Y-m-d')) ?>

Version history

You can find a more or less complete version history in the changelog.

License

MIT License

Author

Nico Hoffmann - https://nhoffmann.com

About

Relative Date and Time (multi-language) plugin for Kirby 2 CMS


Languages

Language:PHP 100.0%