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