← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~stevenk/launchpad/in-a-moment into lp:launchpad

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/in-a-moment into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #147428 in Launchpad itself: "Extremely recent times like "0 seconds ago" and "2 seconds ago" are silly"
  https://bugs.launchpad.net/launchpad/+bug/147428

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/in-a-moment/+merge/66462

Change the TALES approximatedate formatter to return 'a moment' if the time is ten seconds or less.

I have changed, rather than outright deleted the doctest for it, since it is actually quite pleasant for a doctest.
-- 
https://code.launchpad.net/~stevenk/launchpad/in-a-moment/+merge/66462
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/in-a-moment into lp:launchpad.
=== modified file 'lib/lp/app/browser/tales.py'
--- lib/lp/app/browser/tales.py	2011-06-17 18:08:30 +0000
+++ lib/lp/app/browser/tales.py	2011-06-30 13:16:53 +0000
@@ -2089,8 +2089,14 @@
             amount = minutes
             unit = 'minute'
         else:
-            amount = seconds
-            unit = 'second'
+            if seconds <= 10:
+                result += 'a moment'
+                if not future:
+                    result += ' ago'
+                return result
+            else:
+                amount = seconds
+                unit = 'second'
         if amount != 1:
             unit += 's'
         result += '%s %s' % (amount, unit)

=== modified file 'lib/lp/app/doc/displaying-dates.txt'
--- lib/lp/app/doc/displaying-dates.txt	2011-06-23 13:10:40 +0000
+++ lib/lp/app/doc/displaying-dates.txt	2011-06-30 13:16:53 +0000
@@ -51,17 +51,35 @@
     >>> ztapi.provideAdapter(
     ...     datetime, IPathAdapter, TestDateTimeFormatterAPI, 'testfmt')
 
+A time that is ten seconds or less will be displayed as an approximate:
+
+    >>> t = fixed_time + timedelta(0, 5, 0)
+    >>> test_tales('t/testfmt:approximatedate', t=t)
+    'in a moment'
+    >>> t = fixed_time + timedelta(0, 9, 0)
+    >>> test_tales('t/testfmt:approximatedate', t=t)
+    'in a moment'
+    >>> print (test_tales('t/testfmt:approximatedate', t=t) ==
+    ...        test_tales('t/testfmt:displaydate', t=t))
+    True
+    >>> t = fixed_time_utc - timedelta(0, 10, 0)
+    >>> test_tales('t/testfmt:approximatedate', t=t)
+    'a moment ago'
+    >>> print (test_tales('t/testfmt:approximatedate', t=t) ==
+    ...        test_tales('t/testfmt:displaydate', t=t))
+    True
+
 A time that is very close to the present will be displayed in seconds:
 
-    >>> t = fixed_time + timedelta(0, 5, 0)
+    >>> t = fixed_time + timedelta(0, 11, 0)
     >>> test_tales('t/testfmt:approximatedate', t=t)
-    'in 5 seconds'
+    'in 11 seconds'
     >>> print (test_tales('t/testfmt:approximatedate', t=t) ==
     ...        test_tales('t/testfmt:displaydate', t=t))
     True
-    >>> t = fixed_time_utc - timedelta(0, 5, 0)
+    >>> t = fixed_time_utc - timedelta(0, 25, 0)
     >>> test_tales('t/testfmt:approximatedate', t=t)
-    '5 seconds ago'
+    '25 seconds ago'
     >>> print (test_tales('t/testfmt:approximatedate', t=t) ==
     ...        test_tales('t/testfmt:displaydate', t=t))
     True