diff options
author | Haakon Meland Eriksen <haakon.eriksen@far.no> | 2016-02-24 17:44:27 +0100 |
---|---|---|
committer | Haakon Meland Eriksen <haakon.eriksen@far.no> | 2016-02-24 17:44:27 +0100 |
commit | ddeab48f9b314eed067c31086945acee33964d37 (patch) | |
tree | a814d6244991017af57ea03670d45d9ca1286cc0 /include/datetime.php | |
parent | cc264b2d60049a844fe17322fbcb367712a7071f (diff) | |
parent | 039eb585240a5fa106ede00a055036458a4f5393 (diff) | |
download | volse-hubzilla-ddeab48f9b314eed067c31086945acee33964d37.tar.gz volse-hubzilla-ddeab48f9b314eed067c31086945acee33964d37.tar.bz2 volse-hubzilla-ddeab48f9b314eed067c31086945acee33964d37.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'include/datetime.php')
-rw-r--r-- | include/datetime.php | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/include/datetime.php b/include/datetime.php index 1d10e7ad7..bfd806f32 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -269,15 +269,16 @@ function relative_date($posted_date, $format = null) { return t('less than a second ago'); } - $a = array( 12 * 30 * 24 * 60 * 60 => array( t('year'), t('years')), - 30 * 24 * 60 * 60 => array( t('month'), t('months')), - 7 * 24 * 60 * 60 => array( t('week'), t('weeks')), - 24 * 60 * 60 => array( t('day'), t('days')), - 60 * 60 => array( t('hour'), t('hours')), - 60 => array( t('minute'), t('minutes')), - 1 => array( t('second'), t('seconds')) + $a = array( 12 * 30 * 24 * 60 * 60 => 'y', + 30 * 24 * 60 * 60 => 'm', + 7 * 24 * 60 * 60 => 'w', + 24 * 60 * 60 => 'd', + 60 * 60 => 'h', + 60 => 'i', + 1 => 's' ); + foreach ($a as $secs => $str) { $d = $etime / $secs; if ($d >= 1) { @@ -285,11 +286,43 @@ function relative_date($posted_date, $format = null) { if (! $format) $format = t('%1$d %2$s ago', 'e.g. 22 hours ago, 1 minute ago'); - return sprintf($format, $r, (($r == 1) ? $str[0] : $str[1])); + return sprintf($format, $r, plural_dates($str,$r)); } } } +function plural_dates($k,$n) { + + switch($k) { + case 'y': + return tt('year','years',$n,'relative_date'); + break; + case 'm': + return tt('month','months',$n,'relative_date'); + break; + case 'w': + return tt('week','weeks',$n,'relative_date'); + break; + case 'd': + return tt('day','days',$n,'relative_date'); + break; + case 'h': + return tt('hour','hours',$n,'relative_date'); + break; + case 'i': + return tt('minute','minutes',$n,'relative_date'); + break; + case 's': + return tt('second','seconds',$n,'relative_date'); + break; + default: + return; + } +} + + + + /** * @brief Returns timezone correct age in years. * |