feat: add validated semester and lesson calculations
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
enum CourseSource { school, file, demo }
|
||||
|
||||
class Course {
|
||||
Course({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.teacher,
|
||||
required this.room,
|
||||
required this.weekday,
|
||||
required this.startPeriod,
|
||||
required this.endPeriod,
|
||||
required Set<int> weeks,
|
||||
required this.source,
|
||||
}) : weeks = Set.unmodifiable(weeks) {
|
||||
if ([id, name, teacher, room].any((value) => value.trim().isEmpty) ||
|
||||
weekday < 1 ||
|
||||
weekday > 7 ||
|
||||
startPeriod < 1 ||
|
||||
endPeriod > 11 ||
|
||||
endPeriod < startPeriod ||
|
||||
weeks.isEmpty ||
|
||||
weeks.any((week) => week < 1 || week > 30)) {
|
||||
throw ArgumentError('课程字段、节次或周次无效');
|
||||
}
|
||||
}
|
||||
final String id, name, teacher, room;
|
||||
final int weekday, startPeriod, endPeriod;
|
||||
final Set<int> weeks;
|
||||
final CourseSource source;
|
||||
}
|
||||
Reference in New Issue
Block a user