From 1d0177480eae96aadf4ade0aa28bd42b32f35e63 Mon Sep 17 00:00:00 2001 From: aldacron Date: Tue, 16 May 2017 01:04:08 -0700 Subject: [PATCH] updated time display --- nyaa/routes.py | 12 ++++++++++++ nyaa/templates/search_results.html | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nyaa/routes.py b/nyaa/routes.py index edc302b..6cee9c4 100644 --- a/nyaa/routes.py +++ b/nyaa/routes.py @@ -98,6 +98,18 @@ def _generate_query_string(term, category, filter, user): return params +@app.template_filter('utc_time') +def get_utc_timestamp(datetime_str): + ''' Returns a UTC POSIX timestamp, as seconds ''' + UTC_EPOCH = datetime.utcfromtimestamp(0) + return int((datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S') - UTC_EPOCH).total_seconds()) + + +@app.template_filter('display_time') +def get_display_time(datetime_str): + return datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S').strftime('%Y-%m-%d %H:%M') + + @app.route('/rss', defaults={'rss': True}) @app.route('/', defaults={'rss': False}) def home(rss): diff --git a/nyaa/templates/search_results.html b/nyaa/templates/search_results.html index cc0988f..4b5663f 100644 --- a/nyaa/templates/search_results.html +++ b/nyaa/templates/search_results.html @@ -74,7 +74,7 @@ {{ torrent.filesize | filesizeformat(True) }} {% if use_elastic %} - {{ torrent.created_time }} + {{ torrent.created_time | display_time }} {% else %} {{ torrent.created_time.strftime('%Y-%m-%d %H:%M') }} {% endif %}