diff options
Diffstat (limited to 'lib/Travel/Routing/DE/HAFAS/Connection')
-rw-r--r-- | lib/Travel/Routing/DE/HAFAS/Connection/Section.pm | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm b/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm index aca0e42..cb21894 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; |