mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
- Show "Just now" for notifications 2 minutes old or less - Auto-refresh the list every minute, preserving the active filter Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
880 B
Dart
29 lines
880 B
Dart
import 'package:intl/intl.dart';
|
|
|
|
class FriendlyDateFormatter {
|
|
FriendlyDateFormatter();
|
|
|
|
String format(DateTime dateTime) {
|
|
DateTime now = DateTime.now();
|
|
Duration timeSince = now.difference(dateTime);
|
|
DateTime today = DateTime(now.year, now.month, now.day);
|
|
DateTime yesterday = DateTime(now.year, now.month, now.day - 1);
|
|
DateTime dateTimeWithoutTime = DateTime(
|
|
dateTime.year,
|
|
dateTime.month,
|
|
dateTime.day,
|
|
);
|
|
|
|
if (timeSince.inMinutes <= 2) return 'Just now';
|
|
if (timeSince.inMinutes < 60) return '${timeSince.inMinutes} minutes ago';
|
|
if (dateTimeWithoutTime == today) {
|
|
return 'Today at ${DateFormat.Hm().format(dateTime)}';
|
|
}
|
|
if (dateTimeWithoutTime == yesterday) {
|
|
return 'Yesterday at ${DateFormat.Hm().format(dateTime)}';
|
|
}
|
|
|
|
return DateFormat.yMMMMd().add_Hm().format(dateTime);
|
|
}
|
|
}
|