|
|
@ -13,7 +13,6 @@ MINUTE = Unit("minute", 60) |
|
|
|
HOUR = Unit("hour", MINUTE.nsecs * 60) |
|
|
|
DAY = Unit("day", HOUR.nsecs * 24) |
|
|
|
WEEK = Unit("week", DAY.nsecs * 7) |
|
|
|
MONTH = Unit("month", DAY.nsecs * 30) |
|
|
|
|
|
|
|
|
|
|
|
@register.filter |
|
|
@ -21,7 +20,11 @@ def hc_duration(td): |
|
|
|
remaining_seconds = int(td.total_seconds()) |
|
|
|
result = [] |
|
|
|
|
|
|
|
for unit in (MONTH, WEEK, DAY, HOUR, MINUTE): |
|
|
|
for unit in (WEEK, DAY, HOUR, MINUTE): |
|
|
|
if unit == WEEK and remaining_seconds % unit.nsecs != 0: |
|
|
|
# Say "8 days" instead of "1 week 1 day" |
|
|
|
continue |
|
|
|
|
|
|
|
v, remaining_seconds = divmod(remaining_seconds, unit.nsecs) |
|
|
|
if v == 1: |
|
|
|
result.append("1 %s" % unit.name) |
|
|
|