Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP library to generate user friendly relative timestamps

Tags:

date

php

time

I'm looking for a PHP library that generates user-friendly representations of times - for example "two hours ago" when the timestamp is time() - 2 * 3600.

There are several existing questions with answers and blog posts (1, 2, 3), but all only contain code snippets - not a library I can install and upgrade.

Django has one, Python also has a standalone lib, Javascript has several (1, 2, 3), too - where is the PHP library?


A library should have the following things:

  • documentation
  • PEAR installable
  • regular releases
  • (optional) translations
like image 577
cweiske Avatar asked Apr 16 '12 08:04

cweiske


3 Answers

Since there didn't seem to be any library, I've made one myself and got it included in PEAR:

Date_HumanDiff, http://pear.php.net/package/Date_HumanDiff

Code is at http://github.com/pear/Date_HumanDiff

like image 188
cweiske Avatar answered Oct 12 '22 23:10

cweiske


I know Kohana has one, you can propably port it easily.

The function is called fuzzy_span().

See http://kohanaframework.org/3.3/guide-api/Date#fuzzy_span

like image 36
LHolleman Avatar answered Oct 13 '22 00:10

LHolleman


Kohana Date class provides fuzzy_span() method for this. But it can't reply you exact values like "10 minutes"

like image 41
s.webbandit Avatar answered Oct 13 '22 01:10

s.webbandit