[geeklog-cvs] geeklog: Fixed COM_formatTimeString to correctly handle interval...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun May 30 05:24:54 EDT 2010
changeset 7945:032a3a9f7279
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/032a3a9f7279
user: Dirk Haun <dirk at haun-online.de>
date: Sun May 30 11:06:23 2010 +0200
description:
Fixed COM_formatTimeString to correctly handle intervals bigger than 4 weeks (bug #0001158)
diffstat:
language/english.php | 4 +++-
language/english_utf-8.php | 4 +++-
public_html/docs/history | 2 ++
public_html/lib-common.php | 42 ++++++++++++++++++------------------------
4 files changed, 26 insertions(+), 26 deletions(-)
diffs (117 lines):
diff -r 9fb7d4fd3169 -r 032a3a9f7279 language/english.php
--- a/language/english.php Sun May 30 09:29:02 2010 +0200
+++ b/language/english.php Sun May 30 11:06:23 2010 +0200
@@ -1543,11 +1543,13 @@
'days' => 'days',
'weeks' => 'weeks',
'months' => 'months',
+ 'years' => 'years',
'minute' => 'minute',
'hour' => 'hour',
'day' => 'day',
'week' => 'week',
- 'month' => 'month'
+ 'month' => 'month',
+ 'year' => 'year'
);
$LANG_MONTH = array(
diff -r 9fb7d4fd3169 -r 032a3a9f7279 language/english_utf-8.php
--- a/language/english_utf-8.php Sun May 30 09:29:02 2010 +0200
+++ b/language/english_utf-8.php Sun May 30 11:06:23 2010 +0200
@@ -1543,11 +1543,13 @@
'days' => 'days',
'weeks' => 'weeks',
'months' => 'months',
+ 'years' => 'years',
'minute' => 'minute',
'hour' => 'hour',
'day' => 'day',
'week' => 'week',
- 'month' => 'month'
+ 'month' => 'month',
+ 'year' => 'year'
);
$LANG_MONTH = array(
diff -r 9fb7d4fd3169 -r 032a3a9f7279 public_html/docs/history
--- a/public_html/docs/history Sun May 30 09:29:02 2010 +0200
+++ b/public_html/docs/history Sun May 30 11:06:23 2010 +0200
@@ -3,6 +3,8 @@
??? ?, 2010 (1.7.1)
-----------
+- Fixed COM_formatTimeString to correctly handle intervals bigger than 4 weeks
+ (bug #0001158) [Dirk]
- Call PLG_templateSetVars for the Advanced Search form [Dirk]
- Make sure we keep the current status of the user's Advanced Editor option
even when Advanced Editor is disabled for the site (Thanks, Markus) [Dirk]
diff -r 9fb7d4fd3169 -r 032a3a9f7279 public_html/lib-common.php
--- a/public_html/lib-common.php Sun May 30 09:29:02 2010 +0200
+++ b/public_html/lib-common.php Sun May 30 11:06:23 2010 +0200
@@ -4453,47 +4453,41 @@
* @param string $type type (translated string) of new item
* @param int $amount amount of things that have been found.
*/
-function COM_formatTimeString( $time_string, $time, $type = '', $amount = 0 )
+function COM_formatTimeString($time_string, $time, $type = '', $amount = 0)
{
global $LANG_WHATSNEW;
$retval = $time_string;
// This is the amount you have to divide the previous by to get the
- // different time intervals: hour, day, week, months
- $time_divider = array( 60, 60, 24, 7, 30 );
+ // different time intervals: minute, hour, day, week, month, year
+ $time_divider = array(60, 60, 24, 7, 4, 12);
// These are the respective strings to the numbers above. They have to match
// the strings in $LANG_WHATSNEW (i.e. these are the keys for the array -
// the actual text strings are taken from the language file).
- $time_description = array( 'minute', 'hour', 'day', 'week', 'month' );
- $times_description = array( 'minutes', 'hours', 'days', 'weeks', 'months' );
-
- $time_dividers = count( $time_divider );
- for( $s = 0; $s < $time_dividers; $s++ )
- {
+ $time_description = array('minute', 'hour', 'day', 'week', 'month', 'year');
+ $times_description = array('minutes', 'hours', 'days', 'weeks', 'months', 'years');
+
+ $time_dividers = count($time_divider);
+ for ($s = 0; $s < $time_dividers; $s++) {
$time = $time / $time_divider[$s];
- if( $time < $time_divider[$s + 1] )
- {
- if( $time == 1 )
- {
- if( $s == 0 )
- {
+ if (($s + 1 >= $time_dividers) || ($time < $time_divider[$s + 1])) {
+ $time = intval($time);
+ if ($time == 1) {
+ if ($s == 0) {
$time_str = $time_description[$s];
- }
- else // go back to the previous unit, e.g. 1 day -> 24 hours
- {
+ } else {
+ // go back to the previous unit, e.g. 1 day -> 24 hours
$time_str = $times_description[$s - 1];
$time *= $time_divider[$s];
}
- }
- else
- {
+ } else {
$time_str = $times_description[$s];
}
- $fields = array( '%n', '%i', '%t', '%s' );
- $values = array( $amount, $type, $time, $LANG_WHATSNEW[$time_str] );
- $retval = str_replace( $fields, $values, $retval );
+ $fields = array('%n', '%i', '%t', '%s');
+ $values = array($amount, $type, $time, $LANG_WHATSNEW[$time_str]);
+ $retval = str_replace($fields, $values, $retval);
break;
}
}
More information about the geeklog-cvs
mailing list