summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index fdb6568b4..251d5672b 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -26,12 +26,13 @@ import json
import cStringIO
import os
+from datetime import datetime, timedelta
from itertools import chain
from flask import (
Flask, request, render_template, url_for, Response, make_response,
redirect, send_from_directory
)
-from flask.ext.babel import Babel
+from flask.ext.babel import Babel, gettext, ngettext, format_date
from searx import settings, searx_dir
from searx.engines import (
search as do_search, categories, engines, get_engines_stats,
@@ -156,6 +157,19 @@ def index():
if engine in favicons:
result['favicon'] = engine
+ # TODO, check if timezone is calculated right
+ if 'publishedDate' in result:
+ if result['publishedDate'] >= datetime.now() - timedelta(days=1):
+ timedifference = datetime.now() - result['publishedDate']
+ minutes = int((timedifference.seconds/60)%60)
+ hours = int(timedifference.seconds/60/60)
+ if hours == 0:
+ result['publishedDate'] = gettext(u'{minutes} minute(s) ago').format(minutes=minutes)
+ else:
+ result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes)
+ else:
+ result['publishedDate'] = format_date(result['publishedDate'])
+
if search.request_data.get('format') == 'json':
return Response(json.dumps({'query': search.query,
'results': search.results}),