From e584c22c8bf1c12d0170e3e4e53282a00bc355f4 Mon Sep 17 00:00:00 2001 From: kaanelloed <11068249+kaanelloed@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:03:00 -0400 Subject: [PATCH 1/2] chore: use time format based on system settings --- lib/utils/date_time_extension.dart | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/utils/date_time_extension.dart b/lib/utils/date_time_extension.dart index dcd4aa851..65a6246df 100644 --- a/lib/utils/date_time_extension.dart +++ b/lib/utils/date_time_extension.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:fluffychat/l10n/l10n.dart'; +import 'package:fluffychat/utils/platform_infos.dart'; /// Provides extra functionality for formatting the time. extension DateTimeExtension on DateTime { @@ -28,10 +29,9 @@ extension DateTimeExtension on DateTime { difference(prevTime) < const Duration(hours: 1); /// Returns a simple time String. - String localizedTimeOfDay(BuildContext context) => - L10n.of(context).alwaysUse24HourFormat == 'true' - ? DateFormat('HH:mm', L10n.of(context).localeName).format(this) - : DateFormat('h:mm a', L10n.of(context).localeName).format(this); + String localizedTimeOfDay(BuildContext context) => use24HourFormat(context) + ? DateFormat('HH:mm', L10n.of(context).localeName).format(this) + : DateFormat('h:mm a', L10n.of(context).localeName).format(this); /// Returns [localizedTimeOfDay()] if the ChatTime is today, the name of the week /// day if the ChatTime is this week and a date string else. @@ -76,4 +76,19 @@ extension DateTimeExtension on DateTime { localizedTimeOfDay(context), ); } + + /// Check if time needs to be in 24h format + bool use24HourFormat(BuildContext context) { + final mediaQuery24h = MediaQuery.alwaysUse24HourFormatOf(context); + + final l10n24h = L10n.of(context).alwaysUse24HourFormat == 'true'; + + if (PlatformInfos.isAndroid) { + return mediaQuery24h; + } else if (PlatformInfos.isIOS) { + return mediaQuery24h || l10n24h; + } + + return l10n24h; + } } From 046b3b8b14dec13119f28376b3f7c87c9606717a Mon Sep 17 00:00:00 2001 From: kaanelloed <11068249+kaanelloed@users.noreply.github.com> Date: Mon, 8 Sep 2025 10:00:12 -0400 Subject: [PATCH 2/2] chore: add a link to the platforms' different behaviors for the 24h format --- lib/utils/date_time_extension.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils/date_time_extension.dart b/lib/utils/date_time_extension.dart index 65a6246df..ece0a5c49 100644 --- a/lib/utils/date_time_extension.dart +++ b/lib/utils/date_time_extension.dart @@ -83,6 +83,7 @@ extension DateTimeExtension on DateTime { final l10n24h = L10n.of(context).alwaysUse24HourFormat == 'true'; + // https://github.com/krille-chan/fluffychat/pull/1457#discussion_r1836817914 if (PlatformInfos.isAndroid) { return mediaQuery24h; } else if (PlatformInfos.isIOS) {