##// END OF EJS Templates
fixed #597 commits in future get negative age.
marcink -
r2902:e2b2791d beta
parent child Browse files
Show More
@@ -33,6 +33,7 b' fixes'
33 status. Checks now are made also for the repository.
33 status. Checks now are made also for the repository.
34 - fixes #591 git backend was causing encoding errors when handling binary
34 - fixes #591 git backend was causing encoding errors when handling binary
35 files - added a test case for VCS lib tests
35 files - added a test case for VCS lib tests
36 - fixed #597 commits in future get negative age.
36
37
37 1.4.3 (**2012-09-28**)
38 1.4.3 (**2012-09-28**)
38 ----------------------
39 ----------------------
@@ -314,9 +314,14 b' def age(prevdate):'
314
314
315 order = ['year', 'month', 'day', 'hour', 'minute', 'second']
315 order = ['year', 'month', 'day', 'hour', 'minute', 'second']
316 deltas = {}
316 deltas = {}
317 future = False
317
318
318 # Get date parts deltas
319 # Get date parts deltas
319 now = datetime.datetime.now()
320 now = datetime.datetime.now()
321 if prevdate > now:
322 now, prevdate = prevdate, now
323 future = True
324
320 for part in order:
325 for part in order:
321 deltas[part] = getattr(now, part) - getattr(prevdate, part)
326 deltas[part] = getattr(now, part) - getattr(prevdate, part)
322
327
@@ -369,10 +374,16 b' def age(prevdate):'
369 sub_value = 0
374 sub_value = 0
370
375
371 if sub_value == 0:
376 if sub_value == 0:
372 return _(u'%s ago') % fmt_funcs[part](value)
377 if future:
373
378 return _(u'in %s') % fmt_funcs[part](value)
374 return _(u'%s and %s ago') % (fmt_funcs[part](value),
379 else:
375 fmt_funcs[sub_part](sub_value))
380 return _(u'%s ago') % fmt_funcs[part](value)
381 if future:
382 return _(u'in %s and %s') % (fmt_funcs[part](value),
383 fmt_funcs[sub_part](sub_value))
384 else:
385 return _(u'%s and %s ago') % (fmt_funcs[part](value),
386 fmt_funcs[sub_part](sub_value))
376
387
377 return _(u'just now')
388 return _(u'just now')
378
389
@@ -504,4 +515,4 b' def obfuscate_url_pw(engine):'
504 url = url.make_url(engine)
515 url = url.make_url(engine)
505 if url.password:
516 if url.password:
506 url.password = 'XXXXX'
517 url.password = 'XXXXX'
507 return str(url) No newline at end of file
518 return str(url)
@@ -129,10 +129,25 b' class TestLibs(unittest.TestCase):'
129 self.assertEqual(age(n - delt(hours=1)), u'1 hour ago')
129 self.assertEqual(age(n - delt(hours=1)), u'1 hour ago')
130 self.assertEqual(age(n - delt(hours=24)), u'1 day ago')
130 self.assertEqual(age(n - delt(hours=24)), u'1 day ago')
131 self.assertEqual(age(n - delt(hours=24 * 5)), u'5 days ago')
131 self.assertEqual(age(n - delt(hours=24 * 5)), u'5 days ago')
132 self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[n.month-1] + 2))),
132 self.assertEqual(age(n - delt(hours=24 * (calendar.mdays[n.month - 1] + 2))),
133 u'1 month and 2 days ago')
133 u'1 month and 2 days ago')
134 self.assertEqual(age(n - delt(hours=24 * 400)), u'1 year and 1 month ago')
134 self.assertEqual(age(n - delt(hours=24 * 400)), u'1 year and 1 month ago')
135
135
136 def test_age_in_future(self):
137 import calendar
138 from rhodecode.lib.utils2 import age
139 n = datetime.datetime.now()
140 delt = lambda *args, **kwargs: datetime.timedelta(*args, **kwargs)
141 self.assertEqual(age(n), u'just now')
142 self.assertEqual(age(n + delt(seconds=1)), u'in 1 second')
143 self.assertEqual(age(n + delt(seconds=60 * 2)), u'in 2 minutes')
144 self.assertEqual(age(n + delt(hours=1)), u'in 1 hour')
145 self.assertEqual(age(n + delt(hours=24)), u'in 1 day')
146 self.assertEqual(age(n + delt(hours=24 * 5)), u'in 5 days')
147 self.assertEqual(age(n + delt(hours=24 * (calendar.mdays[n.month - 1] + 2))),
148 u'in 1 month and 1 days')
149 self.assertEqual(age(n + delt(hours=24 * 400)), u'in 1 year and 1 month')
150
136 def test_tag_exctrator(self):
151 def test_tag_exctrator(self):
137 sample = (
152 sample = (
138 "hello pta[tag] gog [[]] [[] sda ero[or]d [me =>>< sa]"
153 "hello pta[tag] gog [[]] [[] sda ero[or]d [me =>>< sa]"
General Comments 0
You need to be logged in to leave comments. Login now