mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-24 07:00:47 -04:00
new chat widget
This commit is contained in:
parent
063eeb8d12
commit
1a9cca0667
44 changed files with 1904 additions and 981 deletions
41
lib/chat/views/date_formatter.dart
Normal file
41
lib/chat/views/date_formatter.dart
Normal file
|
@ -0,0 +1,41 @@
|
|||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class DateFormatter {
|
||||
DateFormatter();
|
||||
|
||||
String chatDateTimeFormat(DateTime dateTime) {
|
||||
final now = DateTime.now();
|
||||
|
||||
final justNow = now.subtract(const Duration(minutes: 1));
|
||||
|
||||
final localDateTime = dateTime.toLocal();
|
||||
|
||||
if (!localDateTime.difference(justNow).isNegative) {
|
||||
return translate('date_formatter.just_now');
|
||||
}
|
||||
|
||||
final roughTimeString = DateFormat.jm().format(dateTime);
|
||||
|
||||
if (localDateTime.day == now.day &&
|
||||
localDateTime.month == now.month &&
|
||||
localDateTime.year == now.year) {
|
||||
return roughTimeString;
|
||||
}
|
||||
|
||||
final yesterday = now.subtract(const Duration(days: 1));
|
||||
|
||||
if (localDateTime.day == yesterday.day &&
|
||||
localDateTime.month == now.month &&
|
||||
localDateTime.year == now.year) {
|
||||
return translate('date_formatter.yesterday');
|
||||
}
|
||||
|
||||
if (now.difference(localDateTime).inDays < 4) {
|
||||
final weekday = DateFormat(DateFormat.WEEKDAY).format(localDateTime);
|
||||
|
||||
return '$weekday, $roughTimeString';
|
||||
}
|
||||
return '${DateFormat.yMd().format(dateTime)}, $roughTimeString';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue