From 1e050d7fa82e869e084b0369dde5ce8aa38c143a Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 11 Aug 2013 12:08:01 +0200 Subject: [PATCH] utils/str.py: Use already existing function utils.gen.timeElapsed instead of redundant one. --- src/utils/str.py | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/utils/str.py b/src/utils/str.py index b926e876b..ccce229f7 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -417,42 +417,6 @@ def timestamp(t): t = time.time() return time.ctime(t) -# adapted from -# https://github.com/liudmil-mitev/experiments/blob/master/time/humanize_time.py -def timedelta(amount, units='second'): - ''' - Divide `amount` in time periods. - Useful for making time intervals more human readable. - - >>> humanize_time(173, "hour") - [(1, 'week'), (5, 'hours')] - >>> humanize_time(17313, "second") - [(4, 'hours'), (48, 'minutes'), (33, 'seconds')] - >>> humanize_time(90, "week") - [(1, 'year'), (10, 'months'), (2, 'weeks')] - >>> humanize_time(42, "month") - [(3, 'years'), (6, 'months')] - >>> humanize_time(500, "day") - [(1, 'year'), (5, 'months'), (3, 'weeks'), (3, 'days')] - ''' - INTERVALS = [1, 60, 3600, 86400, 604800, 2419200, 29030400] - NAMES = (_('second'), _('minute'), _('hour'), _('day'), - _('week'), _('month'), _('year')) - - result = [] - - unit = NAMES.index(units) - # Convert to seconds - amount = amount * INTERVALS[unit] - - for i in range(len(NAMES)-1, -1, -1): - a = int(amount // INTERVALS[i]) - if a > 0: - result.append(nItems(a, NAMES[i])) - amount -= a * INTERVALS[i] - - return ' '.join(result) - _formatRe = re.compile('%((?:\d+)?\.\d+f|[bfhiLnpqrsStTuv%])') def format(s, *args, **kwargs): """w00t. @@ -543,7 +507,8 @@ def format(s, *args, **kwargs): elif char == 't': return timestamp(args.pop()) elif char == 'T': - return timedelta(args.pop()) + from gen import timeElapsed + return timeElapsed(args.pop()) elif char == 'u': import supybot.conf as conf return conf.supybot.reply.format.url() % args.pop()