RE: [PEAR-DEV] Date_HumanDiff: support for different formats
[email protected] (Васил Рангелов)
| Newsgroups | php.pear.dev |
|---|---|
| Message-ID | <[email protected]> |
How about making the "mode" part of the format? Perhaps separate it with space or something, like:
$dh->setFormat('short');
$dh->get(time() - 60);// "1m ago"
$dh->setFormat('short diffonly');
$dh->get(time() - 60);// "1m"
$dh->setFormat('short array');
$dh->get(time() - 60);// array('+', '1m');
Also, IMHO, an object (or at least an associative array) would be nicer than a numeric array, though I guess you could add that as just an alternative option to "array".
It might also be worth to have an option to separate the unit from the number (disabled by default). So something like:
$dh->setFormat('short diffonly array unit-separated');
$dh->get(time() - 60));// array('+', 1, 'm');
BTW, I'm not sure if the signs make sense. I'd expect an event in the past to use "-" as a sign, and event in the future to use "+". The signs only make sense in the context of "time remaining" rather than the more general "time relative to the present".
-----Original Message-----
From: Christian Weiske [mailto:[email protected]]
Sent: Friday, August 31, 2012 11:24 PM
To: pear-dev
Subject: [PEAR-DEV] Date_HumanDiff: support for different formats
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 ≡=-