mirror of
https://github.com/krille-chan/fluffychat
synced 2024-07-04 08:33:31 +00:00
fix: Correctly localize time of date
This commit is contained in:
parent
cdd32e7002
commit
2b630aca4d
|
@ -34,14 +34,8 @@ extension DateTimeExtension on DateTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a simple time String.
|
/// Returns a simple time String.
|
||||||
/// TODO: Add localization
|
String localizedTimeOfDay(BuildContext context) =>
|
||||||
String localizedTimeOfDay(BuildContext context) {
|
DateFormat.Hm(L10n.of(context)!.localeName).format(this);
|
||||||
if (MediaQuery.of(context).alwaysUse24HourFormat) {
|
|
||||||
return '${_z(hour)}:${_z(minute)}';
|
|
||||||
} else {
|
|
||||||
return '${_z(hour % 12 == 0 ? 12 : hour % 12)}:${_z(minute)} ${hour > 11 ? "pm" : "am"}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns [localizedTimeOfDay()] if the ChatTime is today, the name of the week
|
/// Returns [localizedTimeOfDay()] if the ChatTime is today, the name of the week
|
||||||
/// day if the ChatTime is this week and a date string else.
|
/// day if the ChatTime is this week and a date string else.
|
||||||
|
@ -91,6 +85,4 @@ extension DateTimeExtension on DateTime {
|
||||||
localizedTimeOfDay(context),
|
localizedTimeOfDay(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String _z(int i) => i < 10 ? '0${i.toString()}' : i.toString();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue