Skip to content

Commit

Permalink
Add override support (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkamran80 authored Nov 22, 2022
1 parent a3c13f3 commit bc4ef2b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/screens/schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ class _ScheduleScreenState extends State<ScheduleScreen> {
onPressed: () => _showTimetable(
context,
schedule.daySchedule(
threeLetterDay,
schedule.override == null
? threeLetterDay
: schedule.override!,
),
),
icon: const Icon(
Expand Down
28 changes: 22 additions & 6 deletions lib/utils/schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ class Schedule {
}

List<Period> get daySchedulePeriods => daySchedule(
DateFormat.E()
.format(
DateTime.now(),
)
.toUpperCase(),
override == null
? DateFormat.E()
.format(
DateTime.now(),
)
.toUpperCase()
: override!,
);

Period? get currentPeriod {
Expand Down Expand Up @@ -213,7 +215,21 @@ class Schedule {
return offDays;
}

OffDay? get activeOffDay => offDays.firstWhere((offDay) => offDay.inEffect);
OffDay? get activeOffDay =>
offDays.where((offDay) => offDay.inEffect).firstOrNull;

String? get override {
Function eq = const ListEquality().equals;

for (MapEntry override in schedule["overrides"].entries) {
if (eq(
override.key.split("-").toList().map(int.parse).toList(),
DateTime.now().ymd(),
)) {
return override.value;
}
}
}

bool get currentPeriodExists =>
currentPeriod.runtimeType.toString().toLowerCase() != "null";
Expand Down

0 comments on commit bc4ef2b

Please sign in to comment.