diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-02-02 09:25:08 +0100 | 
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-02-02 09:25:08 +0100 | 
| commit | 16cc00fc542b6c7b62c1e5a6f4ce61918ffc6473 (patch) | |
| tree | 83601ed85a1d7a96f288d4869f4821c55bbaece4 | |
| parent | 3e4cf94ab130e346a1e14affa27fdcb3ca42b79d (diff) | |
Connection, Connection/Segment: convert DateTime to epoch and Duration to minutes
Fixes --json
| -rw-r--r-- | lib/Travel/Routing/DE/DBRIS/Connection.pm | 14 | ||||
| -rw-r--r-- | lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm | 20 | 
2 files changed, 34 insertions, 0 deletions
| diff --git a/lib/Travel/Routing/DE/DBRIS/Connection.pm b/lib/Travel/Routing/DE/DBRIS/Connection.pm index 82373a6..b090e01 100644 --- a/lib/Travel/Routing/DE/DBRIS/Connection.pm +++ b/lib/Travel/Routing/DE/DBRIS/Connection.pm @@ -156,6 +156,20 @@ sub TO_JSON {  	my $ret = { %{$self} }; +	delete $ret->{strptime_obj}; + +	for my $k (qw(sched_dep rt_dep dep sched_arr rt_arr arr)) { +		if ( $ret->{$k} ) { +			$ret->{$k} = $ret->{$k}->epoch; +		} +	} + +	for my $k (qw(sched_duration rt_duration duration)) { +		if ( $ret->{$k} ) { +			$ret->{$k} = $ret->{$k}->in_units('minutes'); +		} +	} +  	return $ret;  } diff --git a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm index 11e0bf5..896b506 100644 --- a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm +++ b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm @@ -201,4 +201,24 @@ sub transfer_notes {  	return @{ $self->{transfer_notes} // [] };  } +sub TO_JSON { +	my ($self) = @_; + +	my $ret = { %{$self} }; + +	for my $k (qw(sched_dep rt_dep dep sched_arr rt_arr arr)) { +		if ( $ret->{$k} ) { +			$ret->{$k} = $ret->{$k}->epoch; +		} +	} + +	for my $k (qw(sched_duration rt_duration duration transfer_duration)) { +		if ( $ret->{$k} ) { +			$ret->{$k} = $ret->{$k}->in_units('minutes'); +		} +	} + +	return $ret; +} +  1; | 
