aurcache/frontend/lib/utils/time_formatter.dart
lukas-heiligenbrunner 80e2299dc8 sync every hour the latest version of packages with aur
display current version and if outdated in ui
display correct time in output log
2024-01-01 23:07:52 +01:00

21 lines
665 B
Dart

extension TimeFormatter on DateTime {
String readableDuration() {
final now = DateTime.now();
final duration = now.difference(this);
if (duration.inSeconds < 60) {
return '${duration.inSeconds} seconds ago';
} else if (duration.inMinutes < 60) {
return '${duration.inMinutes} minutes ago';
} else if (duration.inHours < 24) {
return '${duration.inHours} hours ago';
} else if (duration.inDays < 30) {
return '${duration.inDays} days ago';
} else if ((duration.inDays / 30) < 12) {
return '${duration.inDays ~/ 30} months ago';
} else {
return '${duration.inDays ~/ 365} years ago';
}
}
}