fix(chat): time

This commit is contained in:
mso7nueh
2025-06-16 13:41:39 +03:00
parent 44d6487709
commit 3b2c4fdff5
2 changed files with 23 additions and 15 deletions

View File

@@ -8,31 +8,39 @@ extension DateTimeExtension on DateTime {
String pattern = dateTimeFormatPattern,
String? locale,
]) {
final localDate = isUtc ? toLocal() : this;
if (locale != null && locale.isNotEmpty) {
initializeDateFormatting(locale);
}
return DateFormat(pattern, locale).format(this);
return DateFormat(pattern, locale).format(localDate);
}
bool isYesterday(DateTime date) {
final DateTime localDate = date.isUtc ? date.toLocal() : date;
final yesterday = DateTime.now().subtract(const Duration(days: 1));
return yesterday.day == localDate.day && yesterday.month == localDate.month && yesterday.year == localDate.year;
}
bool isToday(DateTime date) {
final DateTime localDate = date.isUtc ? date.toLocal() : date;
bool isYesterday() {
final localDate = isUtc ? toLocal() : this;
final now = DateTime.now();
return now.day == localDate.day && now.month == localDate.month && now.year == localDate.year;
final yesterday = DateTime(now.year, now.month, now.day).subtract(const Duration(days: 1));
return localDate.year == yesterday.year &&
localDate.month == yesterday.month &&
localDate.day == yesterday.day;
}
bool isToday() {
final localDate = isUtc ? toLocal() : this;
final now = DateTime.now();
return now.year == localDate.year &&
now.month == localDate.month &&
now.day == localDate.day;
}
}
String calculateDifference(DateTime dateTime) {
if (dateTime.isToday(dateTime)) {
final localDateTime = dateTime.isUtc ? dateTime.toLocal() : dateTime;
if (localDateTime.isToday()) {
return 'Сегодня';
} else if (dateTime.isYesterday(dateTime)) {
} else if (localDateTime.isYesterday()) {
return 'Вчера';
} else {
return dateTime.format('d MMMM', 'ru');
return localDateTime.format('d MMMM', 'ru');
}
}

View File

@@ -39,7 +39,7 @@ class ChatBubbleWidget extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(right: 4, bottom: 4),
child: Text(
sendTime.format('hh:mm'),
sendTime.format('HH:mm', 'ru'),
style: const TextStyle(
color: Color(0xFF7B8794),
height: 1,
@@ -144,7 +144,7 @@ class ChatBubbleWidget extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(left: 4, bottom: 4),
child: Text(
sendTime.format('hh:mm'),
sendTime.format('HH:mm', 'ru'),
style: const TextStyle(
color: Color(0xFF7B8794),
height: 1,