switch to absolute times when old enough
This commit is contained in:
@@ -848,40 +848,30 @@ def utility_processor():
|
||||
# Try the sane thing first
|
||||
dt = (n - t) // 10**9
|
||||
if dt < 1:
|
||||
return "less than a second"
|
||||
return "less than a second ago"
|
||||
if dt < 2:
|
||||
return f"1 second"
|
||||
return f"1 second ago"
|
||||
if dt < 60:
|
||||
return f"{dt} seconds"
|
||||
return f"{dt} seconds ago"
|
||||
if dt < 119:
|
||||
return f"1 minute"
|
||||
return f"1 minute ago"
|
||||
if dt < 3600:
|
||||
return f"{dt // 60} minutes"
|
||||
if dt < 3600 * 2:
|
||||
return f"1 hour"
|
||||
return f"{dt // 60} minutes ago"
|
||||
if dt < 3600 * 24:
|
||||
return f"{dt // 3600} hours"
|
||||
return f"{dt // 3600} hours ago"
|
||||
if dt < 3600 * 24 * 7:
|
||||
return f"{dt // (3600 * 24)} days ago"
|
||||
if dt < 3600 * 24 * 31:
|
||||
return f"{dt // (3600 * 24)} days"
|
||||
return f"{dt // (3600 * 24 * 7)} weeks ago"
|
||||
|
||||
# Try some very rough estimate, whatever
|
||||
f = lambda x: datetime.utcfromtimestamp(x // 10**9)
|
||||
n, t = f(n), f(t)
|
||||
|
||||
def f(x, y, s):
|
||||
return f'{y - x} {s}{"s" if y - x > 1 else ""}'
|
||||
|
||||
if t.year < n.year:
|
||||
return f(t.year, n.year, "year")
|
||||
if t.month < n.month:
|
||||
return f(t.month, n.month, "month")
|
||||
assert False, "unreachable"
|
||||
as_datetime = datetime.fromtimestamp(t // 10**9)
|
||||
return as_datetime.strftime("%Y-%m-%d %H:%M")
|
||||
|
||||
def format_since(t):
|
||||
n = time.time_ns()
|
||||
if n < t:
|
||||
return "in a distant future"
|
||||
return _format_time_delta(n, t) + " ago"
|
||||
return _format_time_delta(n, t)
|
||||
|
||||
def format_until(t):
|
||||
n = time.time_ns()
|
||||
@@ -890,7 +880,7 @@ def utility_processor():
|
||||
return _format_time_delta(t, n)
|
||||
|
||||
def format_time(t):
|
||||
return datetime.utcfromtimestamp(t / 10**9).replace(microsecond=0)
|
||||
return datetime.fromtimestamp(t / 10**9).replace(microsecond=0)
|
||||
|
||||
def rand_password():
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user