From ef5d75fccec72506f5da2bfa10f2786c9c0492fd Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 17 Oct 2022 09:51:27 +0200 Subject: Journey: TO_JSON: convert DateTime to epoch --- lib/Travel/Status/DE/HAFAS/Journey.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib/Travel/Status/DE') diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm index 8dafb82..0e3d52f 100644 --- a/lib/Travel/Status/DE/HAFAS/Journey.pm +++ b/lib/Travel/Status/DE/HAFAS/Journey.pm @@ -266,7 +266,23 @@ sub route { sub TO_JSON { my ($self) = @_; - return { %{$self} }; + my $ret = { %{$self} }; + + for my $k ( keys %{$ret} ) { + if ( ref( $ret->{$k} ) eq 'DateTime' ) { + $ret->{$k} = $ret->{$k}->epoch; + } + } + + for my $stop ( @{ $ret->{route} } ) { + for my $k ( keys %{$stop} ) { + if ( ref( $stop->{$k} ) eq 'DateTime' ) { + $stop->{$k} = $stop->{$k}->epoch; + } + } + } + + return $ret; } sub type { -- cgit v1.2.3