Date_HumanDiff: support for different formats
[email protected] (Christian Weiske)
| Newsgroups | php.pear.dev |
|---|---|
| Message-ID | <20120831222342.5638fc2b@bogo> |
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 ≡=-
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAlBBHU4ACgkQFMhaCCTq+CPJ1gCg7rPeY3HxjKPskFqvjFSqiV0D UHYAn2rGTGDGP9KmOMCITAZRhRz8BOZj =RFdW -----END PGP SIGNATURE-----