diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-12-10 08:29:49 +0100 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-12-10 08:29:49 +0100 |
commit | b60e5eef740af4954313d22eca17983d34774d32 (patch) | |
tree | 4c998215ce452a288f396d9b9948f70ec2dc8025 /lib | |
parent | e73b97dd2472e50867a6a6fb7ab6c4021b884023 (diff) |
Connection, Section: Add TO_JSON method
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Travel/Routing/DE/HAFAS/Connection.pm | 17 | ||||
-rw-r--r-- | lib/Travel/Routing/DE/HAFAS/Connection/Section.pm | 17 |
2 files changed, 34 insertions, 0 deletions
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; 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; |