28 lines
1011 B
Dart
28 lines
1011 B
Dart
/// The graduate system's term number, independent of teaching-week dates.
|
|
class SchoolTerm {
|
|
SchoolTerm(this.id) {
|
|
if (id < 1 || id > 9999) throw ArgumentError('学校学期编号无效');
|
|
}
|
|
final int id;
|
|
String get label {
|
|
final year = 1990 + ((id - 1) ~/ 2);
|
|
return '$year-${year + 1}年${id.isOdd ? '秋' : '春'}';
|
|
}
|
|
|
|
static List<SchoolTerm> get choices =>
|
|
List.generate(73, (index) => SchoolTerm(73 - index));
|
|
Uri get timetableUri =>
|
|
Uri.https('yjsjy.uestc.edu.cn', '/pyxx/pygl/xskbcx/index/$id');
|
|
Uri get examUri =>
|
|
Uri.https('yjsjy.uestc.edu.cn', '/pyxx/pygl/kskcxx/index', {'xq': '$id'});
|
|
Map<String, dynamic> toJson() => {'id': id};
|
|
factory SchoolTerm.fromJson(Map<String, dynamic> json) {
|
|
if (json['id'] is! int) throw const FormatException('学校学期无效');
|
|
return SchoolTerm(json['id'] as int);
|
|
}
|
|
@override
|
|
bool operator ==(Object other) => other is SchoolTerm && other.id == id;
|
|
@override
|
|
int get hashCode => id.hashCode;
|
|
}
|