X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2Fallmydata%2Futil%2Ftime_format.py;h=f3cb486a71d23968525e544b9ca0c6501866a2d0;hb=9fabb924867e164e1c6d4d805761db6c39652cf7;hp=f159ebec3e3c5963ef35dad3af3912356485f6b0;hpb=20b77ef4ff0d508434666ac6cc8a51d957e727c1;p=tahoe-lafs%2Ftahoe-lafs.git diff --git a/src/allmydata/util/time_format.py b/src/allmydata/util/time_format.py index f159ebec..f3cb486a 100644 --- a/src/allmydata/util/time_format.py +++ b/src/allmydata/util/time_format.py @@ -4,7 +4,7 @@ import calendar, datetime, re, time def format_time(t): - return time.strftime("%H:%M:%S %d-%b-%Y", t) + return time.strftime("%Y-%m-%d %H:%M:%S", t) def iso_utc_date(now=None, t=time.time): if now is None: @@ -71,3 +71,27 @@ def parse_date(s): # day return int(iso_utc_time_to_seconds(s + "T00:00:00")) +def format_delta(time_1, time_2): + if time_1 is None: + return "N/A" + if time_1 > time_2: + return '-' + delta = int(time_2 - time_1) + seconds = delta % 60 + delta -= seconds + minutes = (delta / 60) % 60 + delta -= minutes * 60 + hours = delta / (60*60) % 24 + delta -= hours * 24 + days = delta / (24*60*60) + if not days: + if not hours: + if not minutes: + return "%ss" % (seconds) + else: + return "%sm %ss" % (minutes, seconds) + else: + return "%sh %sm %ss" % (hours, minutes, seconds) + else: + return "%sd %sh %sm %ss" % (days, hours, minutes, seconds) +