diff --git a/lib/Travel/Routing/DE/HAFAS/Connection.pm b/lib/Travel/Routing/DE/HAFAS/Connection.pm index 8d030c5b99ca79e2ae9672e4bd3aac6eaa0718e0..2727be3ceaa8186a2c0e52b0a7ebf70a904fb327 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; diff --git a/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm b/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm index aca0e42683ceb255b12dd11e7971cc84a3b6ff31..cb218943b007835ad098f4df895a9a168a10e0a5 100644 --- a/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm +++ b/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm @@ -153,6 +153,23 @@ sub messages { 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;