From 16cc00fc542b6c7b62c1e5a6f4ce61918ffc6473 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 2 Feb 2025 09:25:08 +0100 Subject: Connection, Connection/Segment: convert DateTime to epoch and Duration to minutes Fixes --json --- lib/Travel/Routing/DE/DBRIS/Connection.pm | 14 ++++++++++++++ lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'lib/Travel/Routing/DE/DBRIS') diff --git a/lib/Travel/Routing/DE/DBRIS/Connection.pm b/lib/Travel/Routing/DE/DBRIS/Connection.pm index 82373a6..b090e01 100644 --- a/lib/Travel/Routing/DE/DBRIS/Connection.pm +++ b/lib/Travel/Routing/DE/DBRIS/Connection.pm @@ -156,6 +156,20 @@ sub TO_JSON { my $ret = { %{$self} }; + delete $ret->{strptime_obj}; + + for my $k (qw(sched_dep rt_dep dep sched_arr rt_arr arr)) { + if ( $ret->{$k} ) { + $ret->{$k} = $ret->{$k}->epoch; + } + } + + for my $k (qw(sched_duration rt_duration duration)) { + if ( $ret->{$k} ) { + $ret->{$k} = $ret->{$k}->in_units('minutes'); + } + } + return $ret; } diff --git a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm index 11e0bf5..896b506 100644 --- a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm +++ b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm @@ -201,4 +201,24 @@ sub transfer_notes { return @{ $self->{transfer_notes} // [] }; } +sub TO_JSON { + my ($self) = @_; + + my $ret = { %{$self} }; + + for my $k (qw(sched_dep rt_dep dep sched_arr rt_arr arr)) { + if ( $ret->{$k} ) { + $ret->{$k} = $ret->{$k}->epoch; + } + } + + for my $k (qw(sched_duration rt_duration duration transfer_duration)) { + if ( $ret->{$k} ) { + $ret->{$k} = $ret->{$k}->in_units('minutes'); + } + } + + return $ret; +} + 1; -- cgit v1.2.3