diff options
author | Cassidy Dingenskirchen <admin@15318.de> | 2025-06-29 16:58:04 +0200 |
---|---|---|
committer | Cassidy Dingenskirchen <admin@15318.de> | 2025-06-29 16:58:04 +0200 |
commit | b0d565d65bcad0f5cb0cf1342c38f27a9388d4d4 (patch) | |
tree | c54ca684b0f8c235d49076c97b8106f720f3cd5f /lib | |
parent | b33bfcafb7c3b1b670b7ca7b46613a25589aff07 (diff) |
/checkin/add: allow eliding date on intermediate stops
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 32 |
1 files changed, 28 insertions, 4 deletions
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( |