summaryrefslogtreecommitdiff
path: root/searx/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/utils.py')
-rw-r--r--searx/utils.py28
1 files changed, 10 insertions, 18 deletions
diff --git a/searx/utils.py b/searx/utils.py
index 3651cc389..b8561b84b 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -1,11 +1,10 @@
# import htmlentitydefs
-import locale
-import dateutil.parser
import cStringIO
import csv
import os
import re
+from babel.dates import format_date
from codecs import getincrementalencoder
from HTMLParser import HTMLParser
from random import choice
@@ -195,23 +194,16 @@ def get_result_templates(base_path):
return result_templates
-def format_date_by_locale(date_string, locale_string):
+def format_date_by_locale(date, locale_string):
# strftime works only on dates after 1900
- parsed_date = dateutil.parser.parse(date_string)
- if parsed_date.year <= 1900:
- return parsed_date.isoformat().split('T')[0]
-
- orig_locale = locale.getlocale()[0]
- try:
- locale.setlocale(locale.LC_ALL, locale_string)
- except:
- logger.warning('cannot set locale: {0}'.format(locale_string))
- formatted_date = parsed_date.strftime(locale.nl_langinfo(locale.D_FMT))
- try:
- locale.setlocale(locale.LC_ALL, orig_locale)
- except:
- logger.warning('cannot set original locale: {0}'.format(orig_locale))
- return formatted_date
+
+ if date.year <= 1900:
+ return date.isoformat().split('T')[0]
+
+ if locale_string == 'all':
+ locale_string = settings['ui']['default_locale'] or 'en_US'
+
+ return format_date(date, locale=locale_string)
def dict_subset(d, properties):