Mercurial > kallithea
comparison rhodecode/lib/utils2.py @ 2902:e2b2791d1e7c beta
fixed #597 commits in future get negative age.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 08 Oct 2012 23:28:38 +0200 |
parents | 12fce5e499d5 |
children | 5085e51fba3a |
comparison
equal
deleted
inserted
replaced
2901:f4c09b57a070 | 2902:e2b2791d1e7c |
---|---|
312 :returns: unicode words describing age | 312 :returns: unicode words describing age |
313 """ | 313 """ |
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 |
323 # Fix negative offsets (there is 1 second between 10:59:59 and 11:00:00, | 328 # Fix negative offsets (there is 1 second between 10:59:59 and 11:00:00, |
324 # not 1 hour, -59 minutes and -59 seconds) | 329 # not 1 hour, -59 minutes and -59 seconds) |
367 sub_value = deltas[sub_part] | 372 sub_value = deltas[sub_part] |
368 else: | 373 else: |
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 |
379 | 390 |
380 def uri_filter(uri): | 391 def uri_filter(uri): |