PMU/lib/weekManager.dart

54 lines
1.2 KiB
Dart

import 'package:intl/intl.dart';
import 'main.dart';
class WeekManager {
final DateTime _deadline;
DateTime _currentDate;
Weekday _currentDay;
WeekManager(this._deadline, this._currentDate)
: _currentDay = _getCurrentDayOfWeek(_currentDate);
DateTime get deadline => _deadline;
DateTime get currentDate => _currentDate;
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 formatDate(DateTime date) {
DateFormat formatter = DateFormat('dd-MM-yyyy');
return formatter.format(date);
}
void incrementCurrentDate() {
_currentDate = _currentDate.add(const Duration(days: 1));
}
void updateCurrentDay() {
_currentDay = _getCurrentDayOfWeek(_currentDate);
}
}