Mercurial > kallithea
comparison rhodecode/lib/utils2.py @ 3536:ed48d17836a4 beta
WIP: Changelog view
author | Leonardo <leo@unity3d.com> |
---|---|
date | Thu, 07 Mar 2013 14:48:23 +0100 |
parents | 24ffe239e3d7 |
children | 6e8027c2f49c |
comparison
equal
deleted
inserted
replaced
3535:2792019caf67 | 3536:ed48d17836a4 |
---|---|
347 after_cursor_execute) | 347 after_cursor_execute) |
348 | 348 |
349 return engine | 349 return engine |
350 | 350 |
351 | 351 |
352 def age(prevdate): | 352 def age(prevdate, show_short_version=False): |
353 """ | 353 """ |
354 turns a datetime into an age string. | 354 turns a datetime into an age string. |
355 If show_short_version is True, then it will generate a not so accurate but shorter string, | |
356 example: 2days ago, instead of 2 days and 23 hours ago. | |
357 | |
355 | 358 |
356 :param prevdate: datetime object | 359 :param prevdate: datetime object |
360 :param show_short_version: if it should aproximate the date and return a shorter string | |
357 :rtype: unicode | 361 :rtype: unicode |
358 :returns: unicode words describing age | 362 :returns: unicode words describing age |
359 """ | 363 """ |
360 now = datetime.datetime.now() | 364 now = datetime.datetime.now() |
361 now = now.replace(microsecond=0) | 365 now = now.replace(microsecond=0) |
421 sub_part = order[i + 1] | 425 sub_part = order[i + 1] |
422 sub_value = deltas[sub_part] | 426 sub_value = deltas[sub_part] |
423 else: | 427 else: |
424 sub_value = 0 | 428 sub_value = 0 |
425 | 429 |
426 if sub_value == 0: | 430 if sub_value == 0 or show_short_version: |
427 if future: | 431 if future: |
428 return _(u'in %s') % fmt_funcs[part](value) | 432 return _(u'in %s') % fmt_funcs[part](value) |
429 else: | 433 else: |
430 return _(u'%s ago') % fmt_funcs[part](value) | 434 return _(u'%s ago') % fmt_funcs[part](value) |
431 if future: | 435 if future: |