summaryrefslogtreecommitdiff
path: root/lib/Travel/Status/DE
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2023-02-04 23:13:44 +0100
committerDaniel Friesel <derf@finalrewind.org>2023-02-04 23:13:44 +0100
commit4d5aff8a8d7cd196d153967b31c035745dc11123 (patch)
treed177ce03a21854504b6d9924b7be88ec194da0c7 /lib/Travel/Status/DE
parent8a88c4fd9e1a86930d2578ba9d8f81a1d27e7750 (diff)
Journey: refactor day change handling into helper function
Diffstat (limited to 'lib/Travel/Status/DE')
-rw-r--r--lib/Travel/Status/DE/HAFAS/Journey.pm62
1 files changed, 34 insertions, 28 deletions
diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm
index 2cd8075..f3c1c28 100644
--- a/lib/Travel/Status/DE/HAFAS/Journey.pm
+++ b/lib/Travel/Status/DE/HAFAS/Journey.pm
@@ -100,20 +100,14 @@ sub new {
if ( not defined $timestr ) {
next;
}
- if ( length($timestr) == 8 ) {
-
- # arrival time includes a day offset
- my $offset_date = $hafas->{now}->clone;
- $offset_date->add( days => substr( $timestr, 0, 2, q{} ) );
- $offset_date = $offset_date->strftime('%Y%m%d');
- $timestr = $hafas->{strptime_obj}
- ->parse_datetime("${offset_date}T${timestr}");
- }
- else {
- $timestr
- = $hafas->{strptime_obj}
- ->parse_datetime("${date}T${timestr}");
- }
+
+ $timestr = handle_day_change(
+ input => $timestr,
+ date => $date,
+ strp_obj => $hafas->{strptime_obj},
+ now => $hafas->{now}
+ );
+
}
my $arr_delay
@@ -214,20 +208,14 @@ sub new {
if ( not defined $timestr ) {
next;
}
- if ( length($timestr) == 8 ) {
-
- # arrival time includes a day offset
- my $offset_date = $hafas->{now}->clone;
- $offset_date->add( days => substr( $timestr, 0, 2, q{} ) );
- $offset_date = $offset_date->strftime('%Y%m%d');
- $timestr = $hafas->{strptime_obj}
- ->parse_datetime("${offset_date}T${timestr}");
- }
- else {
- $timestr
- = $hafas->{strptime_obj}
- ->parse_datetime("${date}T${timestr}");
- }
+
+ $timestr = handle_day_change(
+ input => $timestr,
+ date => $date,
+ strp_obj => $hafas->{strptime_obj},
+ now => $hafas->{now}
+ );
+
}
my $datetime_s = $time_s;
@@ -268,6 +256,24 @@ sub new {
# }}}
+sub handle_day_change {
+ my (%opt) = @_;
+ my $date = $opt{date};
+ my $timestr = $opt{input};
+ if ( length($timestr) == 8 ) {
+
+ # arrival time includes a day offset
+ my $offset_date = $opt{now}->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}");
+ }
+ else {
+ $timestr = $opt{strp_obj}->parse_datetime("${date}T${timestr}");
+ }
+ return $timestr;
+}
+
# {{{ Accessors
# Legacy