44 lines
985 B
Dart
44 lines
985 B
Dart
enum BalState { pending, ongoing, ended }
|
|
|
|
class Bal {
|
|
Bal({
|
|
required this.id,
|
|
required this.name,
|
|
required this.state,
|
|
required this.startTime,
|
|
required this.endTime,
|
|
});
|
|
|
|
int id;
|
|
String name;
|
|
BalState state;
|
|
DateTime startTime;
|
|
DateTime endTime;
|
|
|
|
factory Bal.fromJSON(Map<String, dynamic> json) => Bal(
|
|
id: json["id"],
|
|
name: json["name"],
|
|
state: switch (json["state"]) {
|
|
"Pending" => BalState.pending,
|
|
"Ongoing" => BalState.ongoing,
|
|
_ => BalState.ended,
|
|
},
|
|
startTime: DateTime.fromMillisecondsSinceEpoch(
|
|
json["start_timestamp"] * 1000,
|
|
isUtc: true,
|
|
).toLocal(),
|
|
endTime: DateTime.fromMillisecondsSinceEpoch(
|
|
json["end_timestamp"] * 1000,
|
|
isUtc: true,
|
|
).toLocal(),
|
|
);
|
|
|
|
int compareTo(Bal other) {
|
|
if (state.index == other.state.index) {
|
|
return 0;
|
|
} else if (state.index > other.state.index) {
|
|
return state.index;
|
|
}
|
|
return -state.index;
|
|
}
|
|
}
|