summaryrefslogtreecommitdiff
path: root/lib/Travel
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-08-22 00:23:36 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-08-22 00:23:36 +0200
commit139f52fbda84da76cb2a8ee5e878e41b6bfe70f8 (patch)
treefae74792da7562afd0ee5280f5806c396783dc82 /lib/Travel
parent120a9f0fac93592d051842f42e48ccae4cf65687 (diff)
Fix datetime calculation when crossing midnight after midnight
Previously, this module generated timestamps that were 24h in the future whenever requesting a journey that crosses midnight after midnight.
Diffstat (limited to 'lib/Travel')
-rw-r--r--lib/Travel/Status/DE/HAFAS/Journey.pm14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm
index 9dd5561..952a990 100644
--- a/lib/Travel/Status/DE/HAFAS/Journey.pm
+++ b/lib/Travel/Status/DE/HAFAS/Journey.pm
@@ -9,6 +9,7 @@ use 5.014;
no if $] >= 5.018, warnings => 'experimental::smartmatch';
use parent 'Class::Accessor';
+use DateTime::Format::Strptime;
use List::Util qw(any);
use Travel::Status::DE::HAFAS::Stop;
@@ -88,6 +89,12 @@ sub new {
}
}
+ my $date_ref = ( split( qr{[|]}, $jid ) )[4];
+ my $datetime_ref = DateTime::Format::Strptime->new(
+ pattern => '%d%m%Y',
+ time_zone => 'Europe/Berlin'
+ )->parse_datetime($date_ref);
+
my $class = $product->{cls};
my @stops;
@@ -114,7 +121,7 @@ sub new {
input => $timestr,
date => $date,
strp_obj => $hafas->{strptime_obj},
- now => $hafas->{now}
+ ref => $datetime_ref
);
}
@@ -177,7 +184,6 @@ sub new {
}
my $ref = {
- datetime_now => $hafas->{now},
id => $jid,
name => $name,
number => $train_no,
@@ -232,7 +238,7 @@ sub new {
input => $timestr,
date => $date,
strp_obj => $hafas->{strptime_obj},
- now => $hafas->{now}
+ ref => $datetime_ref,
);
}
@@ -282,7 +288,7 @@ sub handle_day_change {
if ( length($timestr) == 8 ) {
# arrival time includes a day offset
- my $offset_date = $opt{now}->clone;
+ my $offset_date = $opt{ref}->clone;
$offset_date->add( days => substr( $timestr, 0, 2, q{} ) );
$offset_date = $offset_date->strftime('%Y%m%d');
$timestr = $opt{strp_obj}->parse_datetime("${offset_date}T${timestr}");