From b0d565d65bcad0f5cb0cf1342c38f27a9388d4d4 Mon Sep 17 00:00:00 2001 From: Cassidy Dingenskirchen Date: Sun, 29 Jun 2025 16:58:04 +0200 Subject: /checkin/add: allow eliding date on intermediate stops --- lib/Travelynx/Controller/Traveling.pm | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'lib/Travelynx/Controller/Traveling.pm') diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm index 30c9d60..74bb5c6 100755 --- a/lib/Travelynx/Controller/Traveling.pm +++ b/lib/Travelynx/Controller/Traveling.pm @@ -2621,6 +2621,11 @@ sub add_intransit_form { locale => 'de_DE', time_zone => 'Europe/Berlin' ); + my $time_parser = DateTime::Format::Strptime->new( + pattern => '%H:%M', + locale => 'de_DE', + time_zone => 'Europe/Berlin' + ); my %opt; my %trip; @@ -2708,7 +2713,7 @@ sub add_intransit_form { if ( $trip{route} ) { my @unknown_stations; - my $prev_epoch; + my $prev_ts = $trip{sched_departure}; for my $station ( @{ $trip{route} } ) { my $ts; my %station_data; @@ -2717,11 +2722,30 @@ sub add_intransit_form { ) { $station = $+{stop}; - $ts = $parser->parse_datetime( $+{timestamp} ); - if ( $ts and $ts->epoch > $prev_epoch ) { + # attempt to parse "07:08" short timestamp first + $ts = $time_parser->parse_datetime( $+{timestamp} ); + if ( $ts ) { + # fill in last stop's (or at the first stop, our departure's) + # date to complete the datetime + $ts = $ts->set( + year => $prev_ts->year, + month => $prev_ts->month, + day => $prev_ts->day + ); + # if we go back in time with this, assume we went + # over midnight and add a day, e.g. in case of a stop + # at 23:00 followed by one at 01:30 + if ($ts < $prev_ts) { + $ts = $ts->add( days => 1 ); + } + } else { + # do a full datetime parse + $ts = $parser->parse_datetime( $+{timestamp} ); + } + if ( $ts and $ts >= $prev_ts ) { $station_data{sched_arr} = $ts->epoch; $station_data{sched_dep} = $ts->epoch; - $prev_epoch = $ts->epoch; + $prev_ts = $ts; } else { $self->render( -- cgit v1.2.3