Human Time Difference

Can we get a native implementation of a human readable time option for dates (1 day ago, 8 days ago, 1 week ago, etc.)? Similar to Carbon’s diffForHumans().

2 Likes

+1. I just posted a topic about how to implement this right now but I think it would be a good addition to core. How do you display relative dates (e.g. 1 day ago) in Kirby?

+1. That would be great!

But I need it in German, others in serveral languages…

This with multi language support would be really great!

PHP already offers this functionality (you have to write it up yourself) and as said in the other thread, it would be far to complex for Kirby to have to keep all of the different languages etc inside of itself just for this feature. Better off building it ourselves i think.

1 Like

Maybe something like this (untested, but it might provide something to start from):

UPDATE: I removed the code cause there were quite a few shortfalls still. I’ll try to post it soon once it’s tested

UPDATE2: here is something that seems to work, atm language config is still required, but I’m working on that: https://gist.github.com/distantnative/1699cdd9304cf33c02ef

If anyone has suggestions, improvements, found bugs or can contribute more languages than English and German - help is highly appreciated!

Haven’t tested it yet, but it certainly needs to cater for single minutes, days etc. as well, would look odd if it said “one days ago” or so …

It actually should already… but then again I thought about changing it again from ground up to also cater to things like “today”, “yesterday”, “last week” - at least optionally.

Things that might also be missing:

  • check if current Kirby language is actually supported, atm you run into an error
  • decision if it should only cater to dates or also time
  • possibilities for languages that can’t be represented by adding a string before or after the relative date
  • option for e.g. “one day ago” instead “1 day ago”
  • simpler, easier to read structure
  • language system (own language library file or whatever)
  • more languages
  • t.b.c.

Sorry, you’re right, I should have looked closer :frowning:

Look here: Relative Date & Time (human readable).

It may be your solution!

1 Like

Look here: Relative Date & Time (human readable).

It may be your solution!

@HeinerEF

I’m aware. Thanks. That topic solution was posted in response to this topic. But it’s not a native solution.

I don’t think it needs to be a native solution. I’d much rather things like this be added via plugins.

I think adding all these plugins just leads to the same problem Wordpress has if we’re not careful.

Maybe you’re right. This also just came to me: It might be nice to have a settings area in the panel where we can toggle default <--> human time via a plugin along with other plugin options. Just a thought.

no, the problem with wordpress was a bad base with plugins to fix core issues and too much stuff in the core. By putting things like this that are simply a template function that uses php native functionality we can avoid the bloat.

The problem with WP plugins are bad code and a lack of security. If Wordpress had standards it wouldn’t be as awful.

There is a whole codebase in Kirby that could use native functionality but opts for helper classes and functions. But Kirby markets itself on having a codebase that is inspired from jQuery — easy to write, easy to use. I think this falls inline with that.