-
Notifications
You must be signed in to change notification settings - Fork 11
/
session.dart
191 lines (170 loc) · 8.39 KB
/
session.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// FLUTTER / DART / THIRD-PARTIES
// Package imports:
import 'package:xml/xml.dart';
/// Data-class that represent a session of courses.
class Session {
/// Short name of the session (like H2020)
final String shortName;
/// Complete name of the session (like Hiver 2020)
final String name;
/// Start date of the session, date when the first course is given
final DateTime startDate;
/// End date of the session
final DateTime endDate;
/// End date of the courses for this session, date when the last course is given
final DateTime endDateCourses;
/// Date when the registration for the session start.
final DateTime startDateRegistration;
/// Date when the registration for the session end.
final DateTime deadlineRegistration;
/// Date when the cancellation of a course with refund start
final DateTime startDateCancellationWithRefund;
/// Date when the cancellation of a course with refund end
final DateTime deadlineCancellationWithRefund;
/// Date when the cancellation of a course with refund end for the new students
final DateTime deadlineCancellationWithRefundNewStudent;
/// Date when the cancellation of a course without refund start for the new students
final DateTime startDateCancellationWithoutRefundNewStudent;
/// Date when the cancellation of a course without refund end for the new students
final DateTime deadlineCancellationWithoutRefundNewStudent;
/// Date when the cancellation of the ASEQ end.
final DateTime deadlineCancellationASEQ;
Session(
{required this.shortName,
required this.name,
required this.startDate,
required this.endDate,
required this.endDateCourses,
required this.startDateRegistration,
required this.deadlineRegistration,
required this.startDateCancellationWithRefund,
required this.deadlineCancellationWithRefund,
required this.deadlineCancellationWithRefundNewStudent,
required this.startDateCancellationWithoutRefundNewStudent,
required this.deadlineCancellationWithoutRefundNewStudent,
required this.deadlineCancellationASEQ});
/// Create a new [Session] instance from a [XMLElement] received from [SignetsApi]
factory Session.fromXmlNode(XmlElement node) => Session(
shortName: node.getElement("abrege")!.innerText,
name: node.getElement("auLong")!.innerText,
startDate: DateTime.parse(node.getElement("dateDebut")!.innerText),
endDate: DateTime.parse(node.getElement("dateFin")!.innerText),
endDateCourses:
DateTime.parse(node.getElement("dateFinCours")!.innerText),
startDateRegistration:
DateTime.parse(node.getElement("dateDebutChemiNot")!.innerText),
deadlineRegistration:
DateTime.parse(node.getElement("dateFinChemiNot")!.innerText),
startDateCancellationWithRefund: DateTime.parse(
node.getElement("dateDebutAnnulationAvecRemboursement")!.innerText),
deadlineCancellationWithRefund: DateTime.parse(
node.getElement("dateFinAnnulationAvecRemboursement")!.innerText),
deadlineCancellationWithRefundNewStudent: DateTime.parse(node
.getElement("dateFinAnnulationAvecRemboursementNouveauxEtudiants")!
.innerText),
startDateCancellationWithoutRefundNewStudent: DateTime.parse(node
.getElement("dateDebutAnnulationSansRemboursementNouveauxEtudiants")!
.innerText),
deadlineCancellationWithoutRefundNewStudent: DateTime.parse(node
.getElement("dateFinAnnulationSansRemboursementNouveauxEtudiants")!
.innerText),
deadlineCancellationASEQ: DateTime.parse(
node.getElement("dateLimitePourAnnulerASEQ")!.innerText));
/// Create a new [Session] instance from a JSON file
factory Session.fromJson(Map<String, dynamic> json) => Session(
shortName: json["shortName"] as String,
name: json["name"] as String,
startDate: DateTime.parse(json["startDate"] as String),
endDate: DateTime.parse(json["endDate"] as String),
endDateCourses: DateTime.parse(json["endDateCourses"] as String),
startDateRegistration:
DateTime.parse(json["startDateRegistration"] as String),
deadlineRegistration:
DateTime.parse(json["deadlineRegistration"] as String),
startDateCancellationWithRefund:
DateTime.parse(json["startDateCancellationWithRefund"] as String),
deadlineCancellationWithRefund:
DateTime.parse(json["deadlineCancellationWithRefund"] as String),
deadlineCancellationWithRefundNewStudent: DateTime.parse(
json["deadlineCancellationWithRefundNewStudent"] as String),
startDateCancellationWithoutRefundNewStudent: DateTime.parse(
json["startDateCancellationWithoutRefundNewStudent"] as String),
deadlineCancellationWithoutRefundNewStudent: DateTime.parse(
json["deadlineCancellationWithoutRefundNewStudent"] as String),
deadlineCancellationASEQ:
DateTime.parse(json["deadlineCancellationASEQ"] as String));
Map<String, dynamic> toJson() => {
'shortName': shortName,
'name': name,
'startDate': startDate.toString(),
'endDate': endDate.toString(),
'endDateCourses': endDateCourses.toString(),
'startDateRegistration': startDateRegistration.toString(),
'deadlineRegistration': deadlineRegistration.toString(),
'startDateCancellationWithRefund':
startDateCancellationWithRefund.toString(),
'deadlineCancellationWithRefund':
deadlineCancellationWithRefund.toString(),
'deadlineCancellationWithRefundNewStudent':
deadlineCancellationWithRefundNewStudent.toString(),
'startDateCancellationWithoutRefundNewStudent':
startDateCancellationWithoutRefundNewStudent.toString(),
'deadlineCancellationWithoutRefundNewStudent':
deadlineCancellationWithoutRefundNewStudent.toString(),
'deadlineCancellationASEQ': deadlineCancellationASEQ.toString()
};
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Session &&
runtimeType == other.runtimeType &&
shortName == other.shortName &&
name == other.name &&
startDate == other.startDate &&
endDate == other.endDate &&
endDateCourses == other.endDateCourses &&
startDateRegistration == other.startDateRegistration &&
deadlineRegistration == other.deadlineRegistration &&
startDateCancellationWithRefund ==
other.startDateCancellationWithRefund &&
deadlineCancellationWithRefund ==
other.deadlineCancellationWithRefund &&
deadlineCancellationWithRefundNewStudent ==
other.deadlineCancellationWithRefundNewStudent &&
startDateCancellationWithoutRefundNewStudent ==
other.startDateCancellationWithoutRefundNewStudent &&
deadlineCancellationWithoutRefundNewStudent ==
other.deadlineCancellationWithoutRefundNewStudent &&
deadlineCancellationASEQ == other.deadlineCancellationASEQ;
@override
int get hashCode =>
shortName.hashCode ^
name.hashCode ^
startDate.hashCode ^
endDate.hashCode ^
endDateCourses.hashCode ^
startDateRegistration.hashCode ^
deadlineRegistration.hashCode ^
startDateCancellationWithRefund.hashCode ^
deadlineCancellationWithRefund.hashCode ^
deadlineCancellationWithRefundNewStudent.hashCode ^
startDateCancellationWithoutRefundNewStudent.hashCode ^
deadlineCancellationWithoutRefundNewStudent.hashCode ^
deadlineCancellationASEQ.hashCode;
@override
String toString() {
return 'Session{shortName: $shortName, '
'name: $name, '
'startDate: $startDate, '
'endDate: $endDate, '
'endDateCourses: $endDateCourses, '
'startDateRegistration: $startDateRegistration, '
'deadlineRegistration: $deadlineRegistration, '
'startDateCancellationWithRefund: $startDateCancellationWithRefund, '
'deadlineCancellationWithRefund: $deadlineCancellationWithRefund, '
'deadlineCancellationWithRefundNewStudent: $deadlineCancellationWithRefundNewStudent, '
'startDateCancellationWithoutRefundNewStudent: $startDateCancellationWithoutRefundNewStudent, '
'deadlineCancellationWithoutRefundNewStudent: $deadlineCancellationWithoutRefundNewStudent, '
'deadlineCancellationASEQ: $deadlineCancellationASEQ}';
}
}