rat/filters.py

17 lines
577 B
Python
Raw Permalink Normal View History

2023-07-11 11:32:13 +00:00
from datetime import datetime, timedelta
# Convert a timestamp to a humand readable date format.
@app.template_filter('date')
def _jinja2_filter_datetime(ts, fmt='%Y年%m月%d%H点%m分'):
return datetime.fromtimestamp(ts).strftime(fmt)
# Convert a integer to the one with separator like 1,000,000.
@app.template_filter('intsep')
def _jinja2_filter_intsep(i):
return f'{int(i):,}'
# Convert a duration in seconds to human readable duration.
@app.template_filter('secdur')
def __jinja2_filter_secdur(delta_t):
return str(timedelta(seconds=int(delta_t)))