Changeset - e2b2791d1e7c
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 13 years ago 2012-10-08 23:28:38
marcin@python-works.com
fixed #597 commits in future get negative age.
3 files changed with 33 insertions and 6 deletions:
0 comments (0 inline, 0 general)
docs/changelog.rst
Show inline comments
 
@@ -33,6 +33,7 @@ fixes
 
  status. Checks now are made also for the repository.
 
- fixes #591 git backend was causing encoding errors when handling binary
 
  files - added a test case for VCS lib tests
 
- fixed #597 commits in future get negative age.
 

	
 
1.4.3 (**2012-09-28**)
 
----------------------
rhodecode/lib/utils2.py
Show inline comments
 
@@ -314,9 +314,14 @@ def age(prevdate):
 

	
 
    order = ['year', 'month', 'day', 'hour', 'minute', 'second']
 
    deltas = {}
 
    future = False
 

	
 
    # Get date parts deltas
 
    now = datetime.datetime.now()
 
    if prevdate > now:
 
        now, prevdate = prevdate, now
 
        future = True
 

	
 
    for part in order:
 
        deltas[part] = getattr(now, part) - getattr(prevdate, part)
 

	
 
@@ -369,10 +374,16 @@ def age(prevdate):
 
            sub_value = 0
 

	
 
        if sub_value == 0:
 
            return _(u'%s ago') % fmt_funcs[part](value)
 

	
 
        return _(u'%s and %s ago') % (fmt_funcs[part](value),
 
            fmt_funcs[sub_part](sub_value))
 
            if future:
 
                return _(u'in %s') % fmt_funcs[part](value)
 
            else:
 
                return _(u'%s ago') % fmt_funcs[part](value)
 
        if future:
 
            return _(u'in %s and %s') % (fmt_funcs[part](value),
 
                fmt_funcs[sub_part](sub_value))
 
        else:
 
            return _(u'%s and %s ago') % (fmt_funcs[part](value),
 
                fmt_funcs[sub_part](sub_value))
 

	
 
    return _(u'just now')
 

	
 
@@ -504,4 +515,4 @@ def obfuscate_url_pw(engine):
 
    url = url.make_url(engine)
 
    if url.password:
 
        url.password = 'XXXXX'
 
    return str(url)
 
\ No newline at end of file
 
    return str(url)
rhodecode/tests/test_libs.py
Show inline comments
 
@@ -129,10 +129,25 @@ class TestLibs(unittest.TestCase):
 
        self.assertEqual(age(n - delt(hours=1)), u'1 hour ago')
 
        self.assertEqual(age(n - delt(hours=24)), u'1 day ago')
 
        self.assertEqual(age(n - delt(hours=24 * 5)), u'5 days ago')
 
        self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[n.month-1] + 2))),
 
        self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[n.month - 1] + 2))),
 
                         u'1 month and 2 days ago')
 
        self.assertEqual(age(n - delt(hours=24 * 400)), u'1 year and 1 month ago')
 

	
 
    def test_age_in_future(self):
 
        import calendar
 
        from rhodecode.lib.utils2 import age
 
        n = datetime.datetime.now()
 
        delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs)
 
        self.assertEqual(age(n), u'just now')
 
        self.assertEqual(age(n + delt(seconds=1)), u'in 1 second')
 
        self.assertEqual(age(n + delt(seconds=60 * 2)), u'in 2 minutes')
 
        self.assertEqual(age(n + delt(hours=1)), u'in 1 hour')
 
        self.assertEqual(age(n + delt(hours=24)), u'in 1 day')
 
        self.assertEqual(age(n + delt(hours=24 * 5)), u'in 5 days')
 
        self.assertEqual(age(n + delt(hours=24 * (calendar.mdays[n.month - 1] + 2))),
 
                         u'in 1 month and 1 days')
 
        self.assertEqual(age(n + delt(hours=24 * 400)), u'in 1 year and 1 month')
 

	
 
    def test_tag_exctrator(self):
 
        sample = (
 
            "hello pta[tag] gog [[]] [[] sda ero[or]d [me =>>< sa]"
0 comments (0 inline, 0 general)