Relative Date for Kirby (human-readable date & time)

Relative Date for Kirby CMS

The Relative Date plugin for Kirby CMS displays date and time to a human-readable relative format. It converts your absolute date (and time) in something relative and more readable, e.g.:

2 months 3 days ago
5 hours 47 minutes 18 seconds from now

Usage

You can either use it as field method:

<?php echo $page->published()->relative() ?>

Or as Kirbytag:

Published: (relativedate: 2015-02-15)

Languages supported

Arabic, Bulgarian, Catalan, Chinese, Chinese Taiwan, Czech, Danish, Dutch, English, Finnish, French, German, Italian, Japanese, Norwegian, Polish, Portuguese, Portuguese Brazilian, Romanian, Russian, Serbian, Spanish, Swedish, Thai, Turkish – help with them is always appreciated.

Docs & Download: https://github.com/distantnative/relative-date
See it in use: used in https://www.project-hub.net

Support me: with buying a moral license

4 Likes

Really nice - Maybe I can use it in a few weeks :slight_smile:

If anyone has any knowledge of Arabic, that’d really help! :wink:
-> https://github.com/distantnative/kirby-relativedate/issues/1

Made some progress. Supporting at the moment the following languages:

  • English (en) [default]
  • Arabic (ar) [experimental]
  • Dutch (nl)
  • Finnish (fi)
  • French (fr)
  • German (de)
  • Italian (it)
  • Japanese (ja)
  • Norwegian (no)
  • Polish (pol)
  • Portuguese (pt)
  • Portuguese Brazilian (pt_BR)
  • Russian (ru)
  • Serbian (sr)
  • Spanish (es)
  • Swedish (sv)
  • Thai (th)
  • Turkish (tr)
1 Like

thank you for doing this. It could be useful for me in the future, but it isn’t something i need all the time so having it not in the core is great!

Let me know if you find bugs or have ideas for improvements.
Don’t really have time for a lot of testing these days, so that must wait till end of April sadly.

Thanks for sharing!

Just one quick one, I’m having trouble getting it to work with the main date() field, it throws an error that it’s not an object

I’ve got it set up with an additional field that I called published, but this meand having to set the date twice in the panel?

Already answered this in a private message, but for everyone else: I believe, this problem is caused by the issue that the ->date() method isn’t chainable, so you actually can’t add the ->relative() method on a field named date as this would also involve the ->date() method, but better go for a field named e.g. published

1 Like

Help Wanted

For one of the next versions of the plugin (probably v1.2), I would like to improve the language support. With v1.0 the plugin introduced ‘fuzzy expressions’ such as

today
last Tuesday
next month

But the support is still very limited (mainly English, German, French, Spanish), while the main functionality is already available in over 20 languages. I would like to change that, but I do not speak any of them. But maybe you can help with just a few minutes of your time:

I have written a little HOWTO on GitHub, explaining what words and phrases are needed and how to contribute.

Help is needed atm for: Arabic, Bulgarian, Czech, Danish, Finnish, Italian , Japanese, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Serbian, Swedish, Thai, Turkish, Chinese, Taiwan Chinese.

Thank you for helping and sharing! <3

PS: If you speak any other languages, that aren’t supported at all yet, I’d love to include them with your help.

The download link on the Github page links to the develop, rather than master. Thanks for this plugin! Trying it out now.

Ouch, fixed that. Thanks for telling me! :smile:

I’m also struggling with the issue someone posted about above, where date() doesn’t work with relative(). I don’t want to add a duplicate field… can you think of any other workarounds?

Sadly not really as it seems like date()is not chainable at the moment with other field methods. However, in the just released v1.1 I added a Kirbytext tag (relativedate: DATETIME) for relative dates. You could make use of that:

<?php echo kirbytext('(relativedate: ' . $page->date('Y-m-d') . ')') ?>

Helpful: https://github.com/jenssegers/laravel-date

A little (visual) update to this plugin post:

Relative Date for Kirby CMS

The Relative Date plugin for Kirby CMS displays date and time to a human-readable relative format. It converts your absolute date (and time) in something relative and more readable, e.g.:

2 months 3 days ago
5 hours 47 minutes 18 seconds from now

Usage

You can either use it as field method:

<?php echo $page->published()->relative() ?>

Or as Kirbytag:

Published: (relativedate: 2015-02-15)

Languages supported

Arabic, Bulgarian, Catalan, Chinese, Chinese Taiwan, Czech, Danish, Dutch, English, Finnish, French, German, Italian, Japanese, Norwegian, Polish, Portuguese, Portuguese Brazilian, Romanian, Russian, Serbian, Spanish, Swedish, Thai, Turkish – help with them is always appreciated.

Docs & Download: https://github.com/distantnative/relative-date
See it in use: used in https://www.project-hub.net

Support me: with buying a moral license

4 Likes

Hi distantnative,

I’m from Indonesia.
I want to contribute Indonesian language (Bahasa) for your project. May I?

1 Like

Sure, I’d love that! Have a look at the current language files to create one for Bahasa. For the fuzzy expressions you can read some information here: https://github.com/distantnative/relative-date/issues/32

And if you have questions, please just contact me! :smile:

1 Like

Allright then.
Sure, I’ll let you know for that :grin:

I just want to start this. Please assist me.
Thank you!

On the current state and version 2 of Relative Date: Relative Date v2 – now fuelled by Carbon