From adcd918d40fb3e45d7e3c2239104ab95de003c14 Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED]>
Date: Tue, 15 Apr 2008 22:43:49 -0400
Subject: [PATCH] Improve formatting of relative dates

This limits disply of relative dates to units that are
within max_levels of magnitude from the primary unit.  In
other words, (years, months), (weeks, days), or (hours, min),
but not (weeks, hours) if max_levels is 2.

It also changes the appearance of just created entries and
adds the "ago" suffix to indicate the passage of time.
---
 misc.py |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/misc.py b/misc.py
index 652930e..bcfd596 100644
--- a/misc.py
+++ b/misc.py
@@ -93,7 +93,8 @@ units = [['%d year',   '%d years',   356 * 24 * 60 * 60],
 
 AND = _(' and ')
 COMMA = _(', ')
-RIGHT_NOW = _('Right now')
+NOW = _('Seconds ago')
+AGO = _(' ago')
 
 # Explanation of the following hack:
 # The xgettext utility extracts plural forms by reading the strings included as
@@ -119,29 +120,29 @@ def _get_elapsed_string(timestamp, max_levels=2):
     levels = 0
     result = ''
     elapsed_seconds = int(time.time() - timestamp)
+
     for name_singular, name_plural, factor in units:
         elapsed_units = elapsed_seconds / factor
         if elapsed_units > 0:
 
             if levels > 0:
-                if max_levels - levels == 1:
-                    result += AND
-                else:
-                    result += COMMA
+                result += COMMA
 
             result += gettext.ngettext(name_singular, name_plural,
                     elapsed_units) % elapsed_units
 
             elapsed_seconds -= elapsed_units * factor
-            levels += 1
             
-            if levels == max_levels:
-                break
+        if result != '':
+            levels += 1
 
+        if levels == max_levels:
+            break
+            
     if levels == 0:
-        return RIGHT_NOW
+        return NOW
 
-    return result
+    return result + AGO
 
 def get_date(jobject):
     """ Convert from a string in iso format to a more human-like format. """
-- 
1.5.3.3

_______________________________________________
Sugar mailing list
Sugar@lists.laptop.org
http://lists.laptop.org/listinfo/sugar

Reply via email to