diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-07-01 19:44:09 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-07-01 19:44:09 +0200 |
commit | 7b01cae7d5b76db82799a8a1618dbb20cfd7dec1 (patch) | |
tree | 448af7d6e20b538fc42f6e94c77c826753ee64e9 /lib/Travelynx/Helper | |
parent | 255d0610f1b5b62b7dd409eeba6c63da3fac4092 (diff) |
Pass scheduled arrival and departure times to Traewelling API1.20.2
This ensures unambiguous checkins for ring lines. See
https://github.com/Traewelling/traewelling/commit/eaf975a3337a151c4759428747342ce49eadea47
Diffstat (limited to 'lib/Travelynx/Helper')
-rw-r--r-- | lib/Travelynx/Helper/Traewelling.pm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Travelynx/Helper/Traewelling.pm b/lib/Travelynx/Helper/Traewelling.pm index 7bac88a..88b91a0 100644 --- a/lib/Travelynx/Helper/Traewelling.pm +++ b/lib/Travelynx/Helper/Traewelling.pm @@ -38,6 +38,20 @@ sub new { return bless( \%opt, $class ); } +sub epoch_to_dt_or_undef { + my ($epoch) = @_; + + if ( not $epoch ) { + return undef; + } + + return DateTime->from_epoch( + epoch => $epoch, + time_zone => 'Europe/Berlin', + locale => 'de-DE', + ); +} + sub parse_datetime { my ( $self, $dt ) = @_; @@ -309,12 +323,24 @@ sub checkin { 'Authorization' => "Bearer $opt{token}", }; + my $departure_ts = epoch_to_dt_or_undef( $opt{dep_ts} ); + my $arrival_ts = epoch_to_dt_or_undef( $opt{arr_ts} ); + + if ($departure_ts) { + $departure_ts = $departure_ts->rfc3339; + } + if ($arrival_ts) { + $arrival_ts = $arrival_ts->rfc3339; + } + my $request = { tripID => $opt{trip_id}, lineName => $opt{train_type} . ' ' . ( $opt{train_line} // $opt{train_no} ), start => q{} . $opt{dep_eva}, destination => q{} . $opt{arr_eva}, + departure => $departure_ts, + arrival => $arrival_ts, toot => $opt{data}{toot} ? \1 : \0, tweet => $opt{data}{tweet} ? \1 : \0, }; |