Merge commit '046b3b8b14dec13119f28376b3f7c87c9606717a' into fluffychat-merge-2

This commit is contained in:
ggurdin 2026-02-03 14:41:33 -05:00
commit 953e9281e6
No known key found for this signature in database
GPG key ID: A01CB41737CBB478

View file

@ -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,20 @@ 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';
// https://github.com/krille-chan/fluffychat/pull/1457#discussion_r1836817914
if (PlatformInfos.isAndroid) {
return mediaQuery24h;
} else if (PlatformInfos.isIOS) {
return mediaQuery24h || l10n24h;
}
return l10n24h;
}
}