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) {
|
|
|
|
|
return "${(days / 365).floor()} ${appLocalizations.years}${appLocalizations.ago}";
|
|
|
|
|
}
|
|
|
|
|
if (days >= 30) {
|
|
|
|
|
return "${(days / 30).floor()} ${appLocalizations.months}${appLocalizations.ago}";
|
|
|
|
|
}
|
|
|
|
|
if (days >= 1) {
|
|
|
|
|
return "$days ${appLocalizations.days}${appLocalizations.ago}";
|
|
|
|
|
}
|
|
|
|
|
final hours = difference.inHours;
|
|
|
|
|
if (hours >= 1) {
|
|
|
|
|
return "$hours ${appLocalizations.hours}${appLocalizations.ago}";
|
|
|
|
|
}
|
|
|
|
|
final minutes = difference.inMinutes;
|
|
|
|
|
if (minutes >= 1) {
|
|
|
|
|
return "$minutes ${appLocalizations.minutes}${appLocalizations.ago}";
|
|
|
|
|
}
|
|
|
|
|
return appLocalizations.just;
|
|
|
|
|
}
|
2024-06-08 15:04:18 +08:00
|
|
|
|
|
|
|
|
String get show {
|
|
|
|
|
return toIso8601String().substring(0, 10);
|
|
|
|
|
}
|
|
|
|
|
}
|