summaryrefslogtreecommitdiff
path: root/lib/util.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-06-27 18:25:22 -0400
committerEvan Prodromou <evan@prodromou.name>2008-06-27 18:25:22 -0400
commitaa8dac17d34414b86642715fc1c1e34d8aee2de9 (patch)
tree7aaae3de1745a3a4c260dd0d5ef2b9e4c6276e89 /lib/util.php
parent453751263b1467a0e726a8fc1e392c6c3c7f754d (diff)
more natural date strings
darcs-hash:20080627222522-84dde-9bef8dc543bbb945b1f05dbeed43924d27f704d1.gz
Diffstat (limited to 'lib/util.php')
-rw-r--r--lib/util.php37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/util.php b/lib/util.php
index 4d55e5a69..c60dc907f 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -726,7 +726,40 @@ function common_path($relative) {
function common_date_string($dt) {
// XXX: do some sexy date formatting
// return date(DATE_RFC822, $dt);
- return $dt;
+ $t = strtotime($dt);
+ $now = time();
+ $diff = $now - $t;
+
+ if ($now < $t) { # that shouldn't happen!
+ return common_simple_date($dt);
+ } else if ($diff < 60) {
+ return _t('a few seconds ago');
+ } else if ($diff < 92) {
+ return _t('about a minute ago');
+ } else if ($diff < 3300) {
+ return _t('about ') . round($diff/60) . _t(' minutes ago');
+ } else if ($diff < 5400) {
+ return _t('about an hour ago');
+ } else if ($diff < 22 * 3600) {
+ return _t('about ') . round($diff/3600) . _t(' hours ago');
+ } else if ($diff < 37 * 3600) {
+ return _t('about a day ago');
+ } else if ($diff < 24 * 24 * 3600) {
+ return _t('about ') . round($diff/(24*3600)) . _t(' days ago');
+ } else if ($diff < 46 * 24 * 3600) {
+ return _t('about a month ago');
+ } else if ($diff < 330 * 24 * 3600) {
+ return _t('about ') . round($diff/(30*24*3600)) . _t(' months ago');
+ } else if ($diff < 480 * 24 * 3600) {
+ return _t('about a year ago');
+ } else {
+ return common_simple_date($dt);
+ }
+}
+
+function common_simple_date($dt) {
+ $t = strtotime($dt);
+ return date(DATE_RFC822, $t);
}
function common_date_w3dtf($dt) {
@@ -1065,6 +1098,8 @@ function common_confirmation_code($bits) {
for ($i = 0; $i < $chars; $i++) {
# XXX: convert to string and back
$num = hexdec(common_good_rand(1));
+ # XXX: randomness is too precious to throw away almost
+ # 40% of the bits we get!
$code .= $codechars[$num%32];
}
return $code;