PMU/lib/weekManager.dart

54 lines
1.2 KiB
Dart
Raw Normal View History

2024-09-10 23:39:25 +04:00
import 'package:intl/intl.dart';
import 'main.dart';
class WeekManager {
2024-09-11 15:25:59 +04:00
final DateTime _deadline;
DateTime _currentDate;
2024-09-10 23:39:25 +04:00
Weekday _currentDay;
2024-09-11 15:25:59 +04:00
WeekManager(this._deadline, this._currentDate)
: _currentDay = _getCurrentDayOfWeek(_currentDate);
2024-09-10 23:39:25 +04:00
2024-09-11 15:25:59 +04:00
DateTime get deadline => _deadline;
DateTime get currentDate => _currentDate;
2024-09-10 23:39:25 +04:00
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 {
2024-09-11 15:25:59 +04:00
return _deadline.difference(_currentDate).inDays;
2024-09-10 23:39:25 +04:00
}
2024-09-11 15:25:59 +04:00
String formatDate(DateTime date) {
2024-09-10 23:39:25 +04:00
DateFormat formatter = DateFormat('dd-MM-yyyy');
2024-09-11 15:25:59 +04:00
return formatter.format(date);
2024-09-10 23:39:25 +04:00
}
2024-09-11 15:25:59 +04:00
void incrementCurrentDate() {
_currentDate = _currentDate.add(const Duration(days: 1));
2024-09-10 23:39:25 +04:00
}
void updateCurrentDay() {
2024-09-11 15:25:59 +04:00
_currentDay = _getCurrentDayOfWeek(_currentDate);
2024-09-10 23:39:25 +04:00
}
}