Files
flisp_app/lib/utils/todo_utils.dart

46 lines
1.3 KiB
Dart

import 'package:flisp_app/models/todo.dart';
import 'package:intl/intl.dart';
List<Todo> getActiveTodos(TodoTab currentTab, List<Todo> todos) {
switch (currentTab) {
case TodoTab.active:
return todos.where((todo) => !todo.isCompleted).toList();
case TodoTab.completed:
return todos.where((todo) => todo.isCompleted).toList();
case TodoTab.today:
final today = DateTime.now();
return todos
.where(
(todo) =>
todo.dueDate != null &&
todo.dueDate!.year == today.year &&
todo.dueDate!.month == today.month &&
todo.dueDate!.day == today.day,
)
.toList();
default:
return todos;
}
}
// 格式化截止日期
String formatDueDate(DateTime dueDate, bool isToday, bool isTomorrow) {
if (isToday) return '今天截止';
if (isTomorrow) return '明天截止';
final now = DateTime.now();
final difference = dueDate.difference(DateTime(now.year, now.month, now.day));
if (difference.inDays < 7) {
return '${difference.inDays}天后截止';
}
return DateFormat("MM-dd").format(dueDate);
}
bool isSameDay(DateTime date1, DateTime date2) {
return date1.year == date2.year &&
date1.month == date2.month &&
date1.day == date2.day;
}