Public Access
fix(journey): correct calculation of duration
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'utilities.dart';
|
||||
// import './state_helper.dart';
|
||||
// import './db_helper.dart';
|
||||
|
||||
@@ -94,13 +95,15 @@ class Journey {
|
||||
Map<String, Object?> journeyMaps,
|
||||
List<Segment> segmentMaps,
|
||||
) {
|
||||
return Journey(
|
||||
Journey journey = Journey(
|
||||
id: journeyMaps["id"] as int,
|
||||
startStation: journeyMaps["startstation"] as String?,
|
||||
endStation: journeyMaps["endstation"] as String?,
|
||||
segments: segmentMaps,
|
||||
duration: Duration(minutes: 0),
|
||||
);
|
||||
journey.sync();
|
||||
return journey;
|
||||
}
|
||||
|
||||
// from trip API request
|
||||
@@ -134,8 +137,8 @@ class Journey {
|
||||
if (segments.isNotEmpty) {
|
||||
startStation = segments.first.start.stationName;
|
||||
endStation = segments.last.end.stationName;
|
||||
duration = segments.first.start.departureTime.difference(
|
||||
segments.last.end.arrivalTime,
|
||||
duration = segments.last.end.arrivalTime.difference(
|
||||
segments.first.start.departureTime,
|
||||
);
|
||||
} else {
|
||||
// if the journey has no segments yet, at least the startStation should remain,
|
||||
@@ -223,7 +226,6 @@ class Journey {
|
||||
static Future<Journey> fromMapWrapper(Map<String, Object?> journeyMap) async {
|
||||
Future<List<Segment>> segs = _dbGetJourneySegments(journeyMap["id"] as int);
|
||||
Journey res = Journey.fromMap(journeyMap, await segs);
|
||||
res.sync();
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user