Skip to content

Commit

Permalink
ignore stop_timezone when calculating arrivals/departures πŸ›βœ…
Browse files Browse the repository at this point in the history
Apparently, stop_timezone was only ever intended for displaying local date+time.
The current operating practice has been clarified in google/transit#322.
  • Loading branch information
derhuerst committed Apr 7, 2023
1 parent 513566c commit c3decaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
16 changes: 6 additions & 10 deletions lib/stop_times.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ WITH stop_times_based AS NOT MATERIALIZED (
drop_off_type,
shape_dist_traveled,
timepoint,
coalesce(stations.stop_timezone, stops.stop_timezone, agency.agency_timezone) as tz,
agency.agency_timezone as tz,
arrival_time,
(
make_timestamptz(
date_part('year', "date")::int,
date_part('month', "date")::int,
date_part('day', "date")::int,
12, 0, 0,
coalesce(stations.stop_timezone, stops.stop_timezone, agency.agency_timezone)
agency.agency_timezone
)
- interval '12 hours'
+ arrival_time
Expand All @@ -148,7 +148,7 @@ WITH stop_times_based AS NOT MATERIALIZED (
date_part('month', "date")::int,
date_part('day', "date")::int,
12, 0, 0,
coalesce(stations.stop_timezone, stops.stop_timezone, agency.agency_timezone)
agency.agency_timezone
)
- interval '12 hours'
+ departure_time
Expand Down Expand Up @@ -304,7 +304,7 @@ WITH stop_times_based AS NOT MATERIALIZED (
date_part('month'::text, "date")::integer,
date_part('day'::text, "date")::integer,
12, 0, 0::double precision,
coalesce(from_station_tz, from_stop_tz, agency_timezone)
agency_timezone
) - '12:00:00'::interval + departure_time AS t_departure,
departure_time,
from_stop_sequence,
Expand All @@ -319,7 +319,7 @@ WITH stop_times_based AS NOT MATERIALIZED (
date_part('month'::text, "date")::integer,
date_part('day'::text, "date")::integer,
12, 0, 0::double precision,
coalesce(to_station_tz, to_stop_tz, agency_timezone)
agency_timezone
) - '12:00:00'::interval + arrival_time AS t_arrival,
arrival_time,
to_drop_off_type,
Expand All @@ -343,10 +343,8 @@ WITH stop_times_based AS NOT MATERIALIZED (
from_stops.stop_id as from_stop_id,
from_stops.stop_name as from_stop_name,
from_stops.stop_timezone as from_stop_tz,
from_stations.stop_id as from_station_id,
from_stations.stop_name as from_station_name,
from_stations.stop_timezone as from_station_tz,
stop_times.stop_headsign as from_stop_headsign,
stop_times.pickup_type as from_pickup_type,
stop_times.departure_time as departure_time,
Expand All @@ -362,10 +360,8 @@ WITH stop_times_based AS NOT MATERIALIZED (
to_stop_times.stop_headsign as to_stop_headsign,
to_stop_times.stop_id as to_stop_id,
to_stops.stop_name as to_stop_name,
to_stops.stop_timezone as to_stop_tz,
to_stations.stop_id as to_station_id,
to_stations.stop_name as to_station_name,
to_stations.stop_timezone as to_station_tz
to_stations.stop_name as to_station_name
FROM "${opt.schema}".trips
LEFT JOIN "${opt.schema}".routes ON trips.route_id = routes.route_id
LEFT JOIN "${opt.schema}".agency ON routes.agency_id = agency.agency_id
Expand Down
8 changes: 4 additions & 4 deletions test/amtrak-gtfs-2021-10-06.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ and date = '2021-11-26'
order by t_arrival
EOF)
# 2021-11-26T15:15:00-06:00
# 2021-11-26T15:15:00-05:00
arr1=$(psql --csv -t -c "$query" | head -n 1)
if [[ "$arr1" != "1637961300" ]]; then
if [[ "$arr1" != "1637957700" ]]; then
echo "invalid 1st t_arrival: $arr1" 1>&2
exit 1
fi
# 2021-11-27T13:45:00-06:00
# 2021-11-27T13:45:00-05:00
arrN=$(psql --csv -t -c "$query" | tail -n 1)
if [[ "$arrN" != "1638042300" ]]; then
if [[ "$arrN" != "1638038700" ]]; then
echo "invalid 2nd t_arrival: $arrN" 1>&2
exit 1
fi

0 comments on commit c3decaa

Please sign in to comment.