From 76c1579787e4ff241cbbe10ea83e9a77e2937545 Mon Sep 17 00:00:00 2001 From: Gaurav Kushwaha Date: Tue, 11 Mar 2025 20:31:44 +0530 Subject: [PATCH] msglist: Follow user settings for message timestamps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Earlier, timestamps were always formatted as 12-hour (h:mm aa), ignoring the user's preference `twentyFourHourTime` in settings. Now, the code retrieves the user's setting and selects the appropriate format: • 24-hour format: "HH:mm" • 12-hour format: "h:mm aa" --- lib/widgets/message_list.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/widgets/message_list.dart b/lib/widgets/message_list.dart index 7a95d10177..f6e13417bb 100644 --- a/lib/widgets/message_list.dart +++ b/lib/widgets/message_list.dart @@ -1334,7 +1334,10 @@ class MessageWithPossibleSender extends StatelessWidget { Widget? senderRow; if (item.showSender) { - final time = _kMessageTimestampFormat + final userSettings = store.userSettings; + final is24HourFormat = userSettings?.twentyFourHourTime; + final timeFormat = DateFormat(getTimeFormat(is24HourFormat ?? false), ZulipLocalizations.of(context).localeName); + final time = timeFormat .format(DateTime.fromMillisecondsSinceEpoch(1000 * message.timestamp)); senderRow = Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -1438,4 +1441,6 @@ class MessageWithPossibleSender extends StatelessWidget { } // TODO(i18n): web seems to ignore locale in formatting time, but we could do better -final _kMessageTimestampFormat = DateFormat('h:mm aa', 'en_US'); +String getTimeFormat(bool is24Hour) { + return is24Hour ? 'HH:mm' : 'h:mm aa'; +} \ No newline at end of file