def mytimesince(value, arg=None): """Formats a date as the time since that date (i.e. "4 days, 6 hours").""" from gonzo.webapp.templatetags.timesince import mytimesince if not value: return u'' try: if arg: return mytimesince(value, arg) return mytimesince(value) except (ValueError, TypeError): return u''
def hunt_status(hunt): from gonzo.webapp.templatetags.timesince import mytimesince, mytimeuntil state = hunt.get_state() if state == Hunt.State.FUTURE: return "Hunt begins in " + mytimeuntil(hunt.start_time) elif state == Hunt.State.CURRENT: return "Hunt ends in " + mytimeuntil(hunt.end_time) elif state == Hunt.State.VOTING: return "Voting ends in " + mytimeuntil(hunt.vote_end_time) elif state == Hunt.State.FINISHED: return "Hunt ended %s ago" % (mytimesince(hunt.vote_end_time),)