From 44329a5c08efd55c85cabbf799ccfc8fafde7045 Mon Sep 17 00:00:00 2001 From: w568w <1278297578@qq.com> Date: Thu, 29 Feb 2024 10:41:49 +0800 Subject: [PATCH] fix: #331 --- lib/repository/fdu/bus_repository.dart | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/repository/fdu/bus_repository.dart b/lib/repository/fdu/bus_repository.dart index fc5ddb6f7..278282052 100644 --- a/lib/repository/fdu/bus_repository.dart +++ b/lib/repository/fdu/bus_repository.dart @@ -80,21 +80,24 @@ class BusScheduleItem implements Comparable { BusScheduleItem(this.id, this.start, this.end, this.startTime, this.endTime, this.direction, this.holidayRun); - factory BusScheduleItem.fromRawJson( - Map json) => + factory BusScheduleItem.fromRawJson(Map json) => BusScheduleItem( json['id'], CampusEx.fromChineseName(json['start']), CampusEx.fromChineseName(json['end']), - (json['stime'] as String).isNotEmpty - ? VagueTime.onlyMMSS(json['stime']) - : null, - (json['etime'] as String).isNotEmpty - ? VagueTime.onlyMMSS(json['etime']) - : null, + _parseTime(json['stime']), + _parseTime(json['etime']), BusDirection.values[int.parse(json['arrow'])], int.parse(json['holiday']) != 0); + // Some times are using "." as separator, so we need to parse it manually + static VagueTime? _parseTime(String time) { + if (time.isEmpty) { + return null; + } + return VagueTime.onlyMMSS(time.replaceAll(".", ":")); + } + @override int compareTo(BusScheduleItem other) => realStartTime!.compareTo(other.realStartTime!);