fix(api_handler): fix wrong date being shown for journeys going past midnight

This commit is contained in:
fbachus
2026-08-01 00:54:33 +02:00
parent 2b7b943ea2
commit 77949f6da6
3 changed files with 18 additions and 11 deletions
+4 -10
View File
@@ -5,14 +5,7 @@ import 'dart:core';
import 'dart:convert';
import 'transport_helper.dart';
String timeOf(DateTime fullDT) {
// doing it this way so we always get two digits on the hour
String full = fullDT.toString();
List<String> splits = full.split(" ")[1].split(":");
String time = '${splits[0]}:${splits[1]}';
return time;
}
import 'utilities.dart';
class ApiHandler {
// TODO: Split next line for better Error Handling
@@ -79,7 +72,7 @@ class ApiHandler {
static Future<List<Departure>> departures(
String stationId, {
int? maxDepartures = -1,
DateTime? time,
DateTime? datetime,
int? duration = 0,
}) async {
String urlPath = '/api/fahrinfo/latest/departureBoard';
@@ -88,8 +81,9 @@ class ApiHandler {
Uri url = Uri.https(baseUrl, urlPath, {
'accessId': accessID,
'id': stationString,
'date': dateOf(datetime ?? DateTime.now()),
'time': timeOf(
time ?? DateTime.now(),
datetime ?? DateTime.now(),
), //time from which departures will be shown
'duration': duration.toString(), //interval time in minutes
'maxJourneys': maxDepartures.toString(),
+1 -1
View File
@@ -292,7 +292,7 @@ class _ChooseDeparturePageState extends State<ChooseDeparturePage> {
void loadDepartures(Station startStation) async {
departureList = await ApiHandler.departures(
startStation.id,
time: widget.arrival?.arrivalTime ?? DateTime.now(),
datetime: widget.arrival?.arrivalTime ?? DateTime.now(),
);
setState(() {});
}
+13
View File
@@ -0,0 +1,13 @@
String timeOf(DateTime fullDT) {
// doing it this way so we always get two digits on the hour
String full = fullDT.toString();
List<String> splits = full.split(" ")[1].split(":");
String time = '${splits[0]}:${splits[1]}';
return time;
}
String dateOf(DateTime fullDT) {
String full = fullDT.toString();
String date = full.split(" ")[0];
return date;
}