Files
MWClash/lib/common/datetime.dart

53 lines
1.2 KiB
Dart
Raw Normal View History

import 'package:fl_clash/common/app_localizations.dart';
2024-04-30 23:38:49 +08:00
extension DateTimeExtension on DateTime {
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;
}
String get lastUpdateTimeDesc {
final currentDateTime = DateTime.now();
final difference = currentDateTime.difference(this);
final days = difference.inDays;
if (days >= 365) {
final years = (days / 365).floor();
return appLocalizations.yearsAgo(years);
}
if (days >= 30) {
final months = (days / 30).floor();
return appLocalizations.monthsAgo(months);
}
if (days >= 1) {
return appLocalizations.daysAgo(days);
}
final hours = difference.inHours;
if (hours >= 1) {
return appLocalizations.hoursAgo(hours);
}
final minutes = difference.inMinutes;
if (minutes >= 1) {
return appLocalizations.minutesAgo(minutes);
}
return appLocalizations.justNow;
}
String get show {
return toString().substring(0, 10);
}
String get showFull {
return toString().substring(0, 19);
}
String get showTime {
return toString().substring(10, 19);
}
}