2024-06-03 18:02:05 +08:00
|
|
|
import 'package:fl_clash/common/app_localizations.dart';
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
extension DateTimeExtension on DateTime {
|
2024-06-03 18:02:05 +08:00
|
|
|
bool get isBeforeNow {
|
2024-04-30 23:38:49 +08:00
|
|
|
return isBefore(DateTime.now());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isBeforeSecure(DateTime? dateTime) {
|
|
|
|
|
if (dateTime == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-06-03 18:02:05 +08:00
|
|
|
|
|
|
|
|
String get lastUpdateTimeDesc {
|
|
|
|
|
final currentDateTime = DateTime.now();
|
|
|
|
|
final difference = currentDateTime.difference(this);
|
|
|
|
|
final days = difference.inDays;
|
|
|
|
|
if (days >= 365) {
|
2025-10-14 15:13:52 +08:00
|
|
|
final years = (days / 365).floor();
|
|
|
|
|
return appLocalizations.yearsAgo(years);
|
2024-06-03 18:02:05 +08:00
|
|
|
}
|
|
|
|
|
if (days >= 30) {
|
2025-10-14 15:13:52 +08:00
|
|
|
final months = (days / 30).floor();
|
|
|
|
|
return appLocalizations.monthsAgo(months);
|
2024-06-03 18:02:05 +08:00
|
|
|
}
|
|
|
|
|
if (days >= 1) {
|
2025-10-14 15:13:52 +08:00
|
|
|
return appLocalizations.daysAgo(days);
|
2024-06-03 18:02:05 +08:00
|
|
|
}
|
|
|
|
|
final hours = difference.inHours;
|
|
|
|
|
if (hours >= 1) {
|
2025-10-14 15:13:52 +08:00
|
|
|
return appLocalizations.hoursAgo(hours);
|
2024-06-03 18:02:05 +08:00
|
|
|
}
|
|
|
|
|
final minutes = difference.inMinutes;
|
|
|
|
|
if (minutes >= 1) {
|
2025-10-14 15:13:52 +08:00
|
|
|
return appLocalizations.minutesAgo(minutes);
|
2024-06-03 18:02:05 +08:00
|
|
|
}
|
2025-10-14 15:13:52 +08:00
|
|
|
return appLocalizations.justNow;
|
2024-06-03 18:02:05 +08:00
|
|
|
}
|
2024-06-07 17:22:55 +08:00
|
|
|
|
|
|
|
|
String get show {
|
2025-06-07 01:48:34 +08:00
|
|
|
return toString().substring(0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get showFull {
|
|
|
|
|
return toString().substring(0, 19);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get showTime {
|
|
|
|
|
return toString().substring(10, 19);
|
2024-06-07 17:22:55 +08:00
|
|
|
}
|
|
|
|
|
}
|