From b60e5eef740af4954313d22eca17983d34774d32 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 10 Dec 2023 08:29:49 +0100 Subject: Connection, Section: Add TO_JSON method --- lib/Travel/Routing/DE/HAFAS/Connection.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/Travel/Routing/DE/HAFAS/Connection.pm') diff --git a/lib/Travel/Routing/DE/HAFAS/Connection.pm b/lib/Travel/Routing/DE/HAFAS/Connection.pm index 8d030c5..2727be3 100644 --- a/lib/Travel/Routing/DE/HAFAS/Connection.pm +++ b/lib/Travel/Routing/DE/HAFAS/Connection.pm @@ -160,6 +160,23 @@ sub sections { return; } +sub TO_JSON { + my ($self) = @_; + + my $ret = { %{$self} }; + + for my $k ( keys %{$ret} ) { + if ( ref( $ret->{$k} ) eq 'DateTime' ) { + $ret->{$k} = $ret->{$k}->epoch; + } + if ( ref( $ret->{$k} ) eq 'DateTime::Duration' ) { + $ret->{$k} = [ $ret->{$k}->in_units( 'days', 'hours', 'minutes' ) ]; + } + } + + return $ret; +} + # }}} 1; -- cgit v1.2.3