return $cache[$year][$month];
}
+ /**
+ * Returns a relative, natural language representation of a timestamp
+ * TODO: Wider range of values ... maybe future time as well?
+ *
+ * @param integer $timestamp The timestamp
+ * @param string $format Format to display time if timestamp is more
+ * then 1 day old.
+ *
+ * @return string The relative time (i.e. 2 minutes ago)
+ */
+ public static function relativeDateTime($timestamp, $format = '%x')
+ {
+ $delta = time() - $timestamp;
+ if ($delta < 60) {
+ return sprintf("%d %s", $delta, ngettext("second ago", "seconds ago", $delta));
+ }
+ $delta = round($delta / 60);
+ if ($delta < 60) {
+ return sprintf("%d %s", $delta, ngettext("minute ago", "minutes ago", $delta));
+ }
+
+ $delta = round($delta / 60);
+ if ($delta < 24) {
+ return sprintf("%d %s", $delta, ngettext("hour ago", "hours ago", $delta));
+ }
+
+ if ($delta > 24 && $delta < 48) {
+ $date = new Horde_Date($timestamp);
+ return sprintf(_("yesterday at %s"), $date->strftime("%l:%M %p"));
+ }
+
+ // Default to the user specified date format.
+ $date = new Horde_Date($timestamp);
+
+ return $date->strftime($GLOBALS['prefs']->getValue('date_format'));
+ }
+
}