diff options
-rwxr-xr-x | lib/Travelynx/Controller/Traveling.pm | 32 | ||||
-rw-r--r-- | templates/add_intransit.html.ep | 4 |
2 files changed, 30 insertions, 6 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( diff --git a/templates/add_intransit.html.ep b/templates/add_intransit.html.ep index 193ec50..a044917 100644 --- a/templates/add_intransit.html.ep +++ b/templates/add_intransit.html.ep @@ -21,7 +21,7 @@ <li>Eingabe der Fahrt als „Typ Linie Nummer“ oder „Typ Nummer“, z.B. „ICE 100“, „S 1 31133“ oder „ABR RE11 26720“</li> <li>Wenn Nummer nicht bekannt oder vorhanden: einen beliebigen Integer eintragen, z.B. „S 5X 0“ oder „U 11 0“</li> - <li>Zeitangaben im Format YYYY-MM-DDTHH:MM.</li> + <li>Zeitangaben im Format YYYY-MM-DDTHH:MM. Bei den Zwischenhalten kann auch nur HH:MM angegeben werden</li> <li>Das ausgewählte Backend bestimmt die verfügbaren Halte für Start, Ziel und Route. Siehe auch <a href="/static/stops.csv">stops.csv</a></li> </ul> </div> @@ -69,7 +69,7 @@ %= text_area 'route', id => 'route', class => 'materialize-textarea' <label for="route">Halte (optional)</label><br/> Eine Station pro Zeile, wahlweise Unterwegshalte oder komplette Route<br/> - Format: <i>Name</i> oder <i>Name</i> @ <i>Zeitpunkt</i> (inkl. Datum, siehe oben) + Format: <i>Name</i> oder <i>Name</i> @ <i>Zeitpunkt</i> (Format siehe oben, ein ggf. ausgelassenes Datum wird ergänzt) </div> </div> <div class="row"> |