Skip to content

Commit 76c1579

Browse files
msglist: Follow user settings for message timestamps
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"
1 parent b421570 commit 76c1579

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/widgets/message_list.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,10 @@ class MessageWithPossibleSender extends StatelessWidget {
13341334

13351335
Widget? senderRow;
13361336
if (item.showSender) {
1337-
final time = _kMessageTimestampFormat
1337+
final userSettings = store.userSettings;
1338+
final is24HourFormat = userSettings?.twentyFourHourTime;
1339+
final timeFormat = DateFormat(getTimeFormat(is24HourFormat ?? false), ZulipLocalizations.of(context).localeName);
1340+
final time = timeFormat
13381341
.format(DateTime.fromMillisecondsSinceEpoch(1000 * message.timestamp));
13391342
senderRow = Row(
13401343
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -1438,4 +1441,6 @@ class MessageWithPossibleSender extends StatelessWidget {
14381441
}
14391442

14401443
// TODO(i18n): web seems to ignore locale in formatting time, but we could do better
1441-
final _kMessageTimestampFormat = DateFormat('h:mm aa', 'en_US');
1444+
String getTimeFormat(bool is24Hour) {
1445+
return is24Hour ? 'HH:mm' : 'h:mm aa';
1446+
}

0 commit comments

Comments
 (0)