From a128a04bb71541fc0720935354d11dc6753b4f79 Mon Sep 17 00:00:00 2001 From: Nico Alt <nicoalt@posteo.org> Date: Thu, 2 Apr 2020 12:00:00 +0000 Subject: [PATCH] Include date in message timestamps if not of today Before, there was no indication to which day a message belongs. --- briar-gtk/briar_gtk/widgets/private_message.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/briar-gtk/briar_gtk/widgets/private_message.py b/briar-gtk/briar_gtk/widgets/private_message.py index 72d3749..c434c95 100644 --- a/briar-gtk/briar_gtk/widgets/private_message.py +++ b/briar-gtk/briar_gtk/widgets/private_message.py @@ -5,7 +5,7 @@ # Initial version based on GNOME Fractal # https://gitlab.gnome.org/GNOME/fractal/-/tags/4.2.2 -import datetime +from datetime import datetime from gettext import gettext as _ from gi.repository import Gtk @@ -55,15 +55,23 @@ class PrivateMessageWidget(Gtk.ListBoxRow): return username_event_box @staticmethod - def _create_date_info(time): - date_label = Gtk.Label.new( - datetime.datetime.fromtimestamp(time).strftime("%I:%M")) + def _create_date_info(timestamp): + time = PrivateMessageWidget._make_timestamp_readable(timestamp) + date_label = Gtk.Label.new(time) date_label.set_justify(Gtk.Justification.RIGHT) date_label.set_valign(Gtk.Align.START) date_label.set_halign(Gtk.Align.END) date_label.get_style_context().add_class("timestamp") return date_label + @staticmethod + def _make_timestamp_readable(timestamp): + time = datetime.fromtimestamp(timestamp) + current_time = datetime.today() + if time.date() == current_time.date(): + return time.strftime("%I:%M") + return time.strftime("%x %I:%M") + @staticmethod def _create_info(username_info, date_info): info = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0) -- GitLab