19 lines
616 B
Dart
19 lines
616 B
Dart
extension DateTimeFormatting on DateTime {
|
|
// Форматирует дату как "DD/MM/YYYY"
|
|
String toFormattedDate() {
|
|
return "${this.day.toString().padLeft(2, '0')}/${this.month.toString().padLeft(2, '0')}/${this.year}";
|
|
}
|
|
|
|
// Форматирует как "x дней осталось"
|
|
String toDaysLeft() {
|
|
final now = DateTime.now();
|
|
final difference = this.difference(now).inDays;
|
|
if (difference < 0) {
|
|
return "Overdue by ${difference.abs()} days";
|
|
} else if (difference == 0) {
|
|
return "Due today";
|
|
} else {
|
|
return "Due in $difference days";
|
|
}
|
|
}
|
|
} |