Date_HumanDiff: support for different formats

From: Date: Fri, 31 Aug 2012 20:23:42 +0000
Subject: Date_HumanDiff: support for different formats
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-55028@lists.php.net to get a copy of this message
Hi, Date_HumanDiff generates human readable time differences from timestamps, e.g. "3 hours ago" or "just now". I want to implement more options now since I got some requests for it, and think that they are needed. First, I need support for negative differences: "in 4 hours". This is a no-brainer. Second, I'd like to add a "short" mode: "in 3h", "5m ago". Further, I guess that it'd be helpful to have the time difference only, without "ago" and "in". And an option to get both the time difference as well as a past/future indicator. I thought about something like that: $dh = new Date_HumanDiff(); $dh->get(time() - 60));// "a minute ago" $dh->setFormat('short'); $dh->get(time() - 60));// "1m ago" $dh->setFormat('short')->setMode('diffonly'); $dh->get(time() - 60));// "1m" $dh->setFormat('short')->setMode('array'); $dh->get(time() - 60));// array('+', '1m') In tabular form: Format: long (default) Difference Full mode Diff only mode Array mode negative in 3 days 3 days array('-', '3 days') near zero just now just now array(0, 'just now') positive 3 hours ago 3 hours array('+', '3 hours') Format: short Difference Full mode Diff only mode Array mode negative in 3d 3d array('-', '3d') near zero now now array(0, 'now') positive 3h ago 3h array('+', '3h') Now my questions: 1. Is that sensible? 2. What other formats/modes should be supported? 3. Are the words "mode" and "format" good choices? Are there better ones? Always keep in mind that the strings need to be translatable and have to work for all languages. -- Regards/Mit freundlichen Grüßen Christian Weiske -=≡ Geeking around in the name of science since 1982 ≡=-

Attachment: [application/pgp-signature] signature.asc
« previous php.pear.dev (#55028) next »