Procházet zdrojové kódy

improve published Date output

Thomas Pointhuber před 11 roky
rodič
revize
794165d19c
1 změnil soubory, kde provedl 17 přidání a 3 odebrání
  1. 17
    3
      searx/webapp.py

+ 17
- 3
searx/webapp.py Zobrazit soubor

@@ -161,10 +161,24 @@ def index():
161 161
         if 'publishedDate' in result:
162 162
             if result['publishedDate'].date() == datetime.now().date():
163 163
                 timedifference = datetime.now()-result['publishedDate']
164
-                if timedifference.seconds < 60*60:
165
-                    result['publishedDate'] = gettext(u'{0:d} minutes ago').format(timedifference.seconds/60)
164
+                minutes = int((timedifference.seconds/60)%60)
165
+                hours = int(timedifference.seconds/60/60)
166
+                if hours == 0:
167
+                    if minutes == 1:
168
+                        result['publishedDate'] = gettext(u'1 minute ago')
169
+                    else:
170
+                        result['publishedDate'] = gettext(u'{minutes} minutes ago').format(minutes=minutes)
166 171
                 else:
167
-                    result['publishedDate'] = gettext(u'{0:d} hours ago').format(timedifference.seconds/60/60)
172
+                    if hours == 1:
173
+                        if minutes == 1:
174
+                            result['publishedDate'] = gettext(u'1 hour, 1 minute ago')
175
+                        else:
176
+                            result['publishedDate'] = gettext(u'1 hour, {minutes} minutes ago').format(minutes=minutes)
177
+                    else:
178
+                        if minutes == 1:
179
+                            result['publishedDate'] = gettext(u'{hours} hours, 1 minutes ago').format(hours=hours)
180
+                        else:
181
+                            result['publishedDate'] = gettext(u'{hours} hours, {minutes} minutes ago').format(hours=hours, minutes=minutes)
168 182
             else:
169 183
                 result['publishedDate'] = format_date(result['publishedDate'])
170 184