diff frontends/src/quick_frontend/quick_chat.py @ 2029:62a99c214b57

primitivus, quick frontend (chat): moved time text generation to QuickChat
author Goffi <goffi@goffi.org>
date Mon, 08 Aug 2016 21:05:04 +0200
parents cdb2591d0b8b
children e3f1bd9dd009
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py	Mon Aug 08 00:50:01 2016 +0200
+++ b/frontends/src/quick_frontend/quick_chat.py	Mon Aug 08 21:05:04 2016 +0200
@@ -25,6 +25,8 @@
 from sat_frontends.quick_frontend.constants import Const as C
 from collections import OrderedDict
 from sat_frontends.tools import jid
+import locale
+import time
 
 ROOM_USER_JOINED = 'ROOM_USER_JOINED'
 ROOM_USER_LEFT = 'ROOM_USER_LEFT'
@@ -99,6 +101,14 @@
                 log.error(u"Can't find message for uid {}".format(self.uid))
                 return ''
 
+    @property
+    def time_text(self):
+        """Return timestamp in a nicely formatted way"""
+        # if the message was sent before today, we print the full date
+        timestamp = time.localtime(self.timestamp)
+        time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M"
+        return time.strftime(time_format, timestamp).decode(locale.getlocale()[1])
+
     def getNick(self, entity):
         """Return nick of an entity when possible"""
         contact_list = self.host.contact_lists[self.profile]
@@ -191,6 +201,7 @@
         self.messages = OrderedDict()  # key: uid, value: Message instance
         self.games = {}  # key=game name (unicode), value=instance of quick_games.RoomGame
         self.subject = subject
+        self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00  %Y"))  # struct_time of day changing time
 
     def postInit(self):
         """Method to be called by frontend after widget is initialised