Skip to content

Instantly share code, notes, and snippets.

View Ph3nol's full-sized avatar
🦄
Riding a Unicorn. From ::1 to the moon.

Cédric Dugat Ph3nol

🦄
Riding a Unicorn. From ::1 to the moon.
View GitHub Profile
@Ph3nol
Ph3nol / RelDate.php
Created December 5, 2011 08:02 — forked from arnaud-lb/RelDate.php
4 lines relative date formatter with DateInterval and Symfony2 Translator
<?php
use Symfony\Component\Translation\TranslatorInterface;
function format(\DateTime $date, TranslatorInterface $translator)
{
$diff = date_create()->diff($date);
$seconds = $diff->days * 86400 + $diff->h * 3600 + $diff->i * 60 + $diff->s;
$format = $translator->transChoice('reldate', $seconds);