A 26-Hour Rail Leg Across Spring-Forward
A 26-Hour Rail Leg Across Spring-Forward
A train departs New York at 20:00 on 9 March 2024 and its scheduled running time is 26 hours. Clocks spring forward at 02:00 that night. When does it arrive?
The naive approach
// The naive approach: add a day and two hours to the wall clock
const departure = "2024-03-09T20:00:00"; // local wall time
// "one day later" is 2024-03-10T20:00:00, plus two hours is 22:00
const arrival = "2024-03-10T22:00:00";
// The train has run 25 elapsed hours at 22:00 on the 10th, not 26.
// The published arrival is an hour early, and every connection off it is wrong.Watch it break
The naive approach silently produces wrong results — there is no GMT equivalent to demonstrate because the failure is not using GMT.
Why
The night of 9 March 2024 is 23 hours long in New York. "A day later" on the wall clock is only 23 elapsed hours, so a wall-clock addition of one day and two hours puts the train in the station after 25 hours of running, an hour before it is really there. A running time is *elapsed* time: the train does not go faster because the clocks changed. `transitTime` adds the duration as exact time in the departure's own zone, so a `D` component is 24 hours exactly and the arrival's wall clock shows whatever offset is in force when it gets there.
The gmt approach
import { transitTime } from "@northguild/gmt/transport";
transitTime("2024-03-09T20:00:00-05:00[America/New_York]", "PT26H");
// "2024-03-10T23:00:00-04:00[America/New_York]" — 26 elapsed hours, EDT on arrival
// P1DT2H is the same 26 hours: a day is 24 exact hours here, not "tomorrow"
transitTime("2024-03-09T20:00:00-05:00[America/New_York]", "P1DT2H");
// "2024-03-10T23:00:00-04:00[America/New_York]"Same widget, working
The wall-clock addition is what addZoned does on
purpose: its date part moves the wall clock, which is right for “the same meeting next week”
and wrong for a running time. Both are correct; they answer different questions. See
Recurring Meeting Across DST for the case where the
wall clock is what should hold, and Transport: Legs and
Dwell for the rest of the leg rules.