import 'dart:math'; import 'package:intl/intl.dart'; import 'main.dart'; class WeekManager { DateTime deadline; DateTime currentDate; Weekday _currentDay; WeekManager(this.deadline) : currentDate = DateTime.now(), _currentDay = _getCurrentDayOfWeek(DateTime.now()); Weekday get currentDay => _currentDay; static Weekday _getCurrentDayOfWeek(DateTime date) { switch (date.weekday) { case 1: return Weekday.Monday; case 2: return Weekday.Tuesday; case 3: return Weekday.Wednesday; case 4: return Weekday.Thursday; case 5: return Weekday.Friday; case 6: return Weekday.Saturday; case 7: return Weekday.Sunday; default: return Weekday.Monday; } } int get daysUntilDeadline { return deadline.difference(currentDate).inDays; } String get formattedDeadline { DateFormat formatter = DateFormat('dd-MM-yyyy'); return formatter.format(deadline); } String get formattedCurrentDate { DateFormat formatter = DateFormat('dd-MM-yyyy'); return formatter.format(currentDate); } void updateCurrentDay() { _currentDay = _getCurrentDayOfWeek(currentDate); } void updateCurrentDate() { final random = Random(); currentDate = DateTime.now().add(Duration(days: random.nextInt(365))); } void incrementCurrentDate() { currentDate = currentDate.add(const Duration(days: 1)); } }