Transport: Multi-leg Scheduling
A multi-modal move, truck to ship to rail, is published as one departure plus a duration per leg, with a handling time at each handoff. The naive approach that adds hours on a clock loses hours at the handoffs. Every leg boundary here is an exact instant, and local times are rendered only at the edges.
import { crossingTime, scheduleDelivery } from "@northguild/gmt/transport";Both live in @northguild/gmt/transport/calculate, beside
transitTime and dwellTime.
Every handoff is an exact instant: scheduleDelivery
Section titled “Every handoff is an exact instant: scheduleDelivery”scheduleDelivery(legs, options?) chains
one to four legs. Each leg’s arrival plus its dwellAfter is the next leg’s departure.
arrival is a UTC instant. localArrival is that instant in the leg’s timeZone, exactly as
etaAtZone renders it. eta is the last leg’s
localArrival. A single leg is exactly transitTime composed with etaAtZone.
import { etaAtZone, scheduleDelivery, transitTime } from "@northguild/gmt/transport";
scheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT36H", timeZone: "Asia/Tokyo" }]);// { eta: "2024-06-17T07:00:00+09:00[Asia/Tokyo]",// legTimes: [{ arrival: "2024-06-16T22:00:00Z", localArrival: "2024-06-17T07:00:00+09:00[Asia/Tokyo]", dwellAfter: "PT0S" }] }
transitTime("2024-06-15T10:00:00Z", "PT36H"); // "2024-06-16T22:00:00Z"etaAtZone("2024-06-16T22:00:00Z", "Asia/Tokyo"); // "2024-06-17T07:00:00+09:00[Asia/Tokyo]"A two-leg journey with a two-hour dwell at the first stop: the second leg leaves at 12:00Z, two hours after the first arrives.
scheduleDelivery([ { departure: "2024-06-15T00:00:00Z", duration: "PT10H", timeZone: "UTC", dwellAfter: "PT2H" }, { duration: "PT5H", timeZone: "Asia/Tokyo" },]);// { eta: "2024-06-16T02:00:00+09:00[Asia/Tokyo]",// legTimes: [{ arrival: "2024-06-15T10:00:00Z", localArrival: "2024-06-15T10:00:00+00:00[UTC]", dwellAfter: "PT2H" },// { arrival: "2024-06-15T17:00:00Z", localArrival: "2024-06-16T02:00:00+09:00[Asia/Tokyo]", dwellAfter: "PT0S" }] }The journey — a truck to London, a ship to Tokyo, a train onward — chained in one call:
const truck = { departure: "2024-03-29T08:00:00+01:00[Europe/Berlin]", duration: "PT44H", timeZone: "Europe/London", dwellAfter: "PT2H", mode: "truck" };const ship = { duration: "P11D", timeZone: "Asia/Tokyo", dwellAfter: "PT24H", mode: "ship" };const rail = { duration: "PT2H30M", timeZone: "Asia/Tokyo", mode: "rail" };
scheduleDelivery([truck, ship, rail]);// { eta: "2024-04-12T16:30:00+09:00[Asia/Tokyo]",// legTimes: [// { arrival: "2024-03-31T03:00:00Z", localArrival: "2024-03-31T04:00:00+01:00[Europe/London]", dwellAfter: "PT2H", mode: "truck" },// { arrival: "2024-04-11T05:00:00Z", localArrival: "2024-04-11T14:00:00+09:00[Asia/Tokyo]", dwellAfter: "PT24H", mode: "ship" },// { arrival: "2024-04-12T07:30:00Z", localArrival: "2024-04-12T16:30:00+09:00[Asia/Tokyo]", dwellAfter: "PT0S", mode: "rail" } ] }The ship has no departure of its own: it leaves when the truck’s arrival plus its two-hour
dwell allows. The truck lands at 04:00 in London, three hours after the clocks sprang
forward that morning. An offset table holding London’s winter +00:00 reads that arrival as
03:00, an hour early, and every handoff time after it inherits the error. Open the whole journey
in the Delivery Scheduler to see the itinerary flag the
London arrival 1 h early against that offset table’s reading.
The Date Line. A westbound leg out of Tahiti at 23:00 on Friday 14 June lands in Auckland at 02:30 on Sunday 16 June, after 5 hours 30 minutes of elapsed time.
scheduleDelivery([{ departure: "2024-06-14T23:00:00-10:00[Pacific/Tahiti]", duration: "PT5H30M", timeZone: "Pacific/Auckland" }]);// { eta: "2024-06-16T02:30:00+12:00[Pacific/Auckland]", … }Eastbound, a flight out of Auckland at 17:00 on 17 June lands in Tahiti at 00:30 the same date — sixteen and a half wall-clock hours before it left, by the clocks alone.
scheduleDelivery([ { departure: "2024-06-17T17:00:00+12:00[Pacific/Auckland]", duration: "PT5H30M", timeZone: "Pacific/Tahiti", dwellAfter: "PT3H", mode: "air" }, { duration: "PT44H", timeZone: "Pacific/Rarotonga", mode: "ship" },]);// { eta: "2024-06-18T23:30:00-10:00[Pacific/Rarotonga]",// legTimes: [{ arrival: "2024-06-17T10:30:00Z", localArrival: "2024-06-17T00:30:00-10:00[Pacific/Tahiti]", dwellAfter: "PT3H", mode: "air" },// { arrival: "2024-06-19T09:30:00Z", localArrival: "2024-06-18T23:30:00-10:00[Pacific/Rarotonga]", dwellAfter: "PT0S", mode: "ship" }] }Nothing special happens at the Date Line, because each end here is only an instant rendered in a zone.
A scheduled departure is a connection, and dwell is the minimum connect time
Section titled “A scheduled departure is a connection, and dwell is the minimum connect time”A later leg with its own departure is a scheduled connection the cargo waits for.
dwellAfter is the handling time at the handoff — the minimum connect time. A departure
earlier than the previous arrival plus its dwell is a missed connection and returns null, not
a negative wait. A departure exactly on it passes: equal passes.
scheduleDelivery([ { departure: "2024-06-15T00:00:00Z", duration: "PT10H", timeZone: "UTC", dwellAfter: "PT2H" }, { departure: "2024-06-15T11:00:00Z", duration: "PT1H", timeZone: "UTC" },]);// null — the second leg is scheduled to leave inside the first's two-hour handoff
scheduleDelivery([ { departure: "2024-06-15T00:00:00Z", duration: "PT10H", timeZone: "UTC", dwellAfter: "PT2H" }, { departure: "2024-06-15T12:00:00Z", duration: "PT1H", timeZone: "UTC" },]);// { eta: "2024-06-15T13:00:00+00:00[UTC]", … } — scheduled exactly when the dwell ends: equal passesdwellAfter is echoed as written: "PT90M" stays "PT90M", and it reads "PT0S" when you
omit it. The last leg’s dwell is validated and echoed, but moves nothing, because no leg
follows it to move.
scheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT1H", timeZone: "UTC", dwellAfter: "PT5H" }]);// { eta: "2024-06-15T11:00:00+00:00[UTC]", legTimes: [{ …, dwellAfter: "PT5H" }] } — the eta is unchangedscheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT1H", timeZone: "UTC", dwellAfter: "P1M" }]);// null — still validatedOpen the handoff on its own in the Connection Checker.
Which departure the cargo can make: nextDeparture
Section titled “Which departure the cargo can make: nextDeparture”A scheduled departure is often the answer to “which departure can this cargo still make”.
nextDeparture reads it off a timetable list or a service every N minutes, after the minimum
connection time, and returns the entry exactly as written so it goes straight into the leg. See
the guide section
and the Departure Board.
A departure is exact, or a local time read in a known zone
Section titled “A departure is exact, or a local time read in a known zone”The first leg needs a departure that is an instant or a zoned string.
scheduleDelivery([{ departure: "2024-06-15T10:00:00", duration: "PT1H", timeZone: "UTC" }]); // null — no offset or zonescheduleDelivery([{ duration: "PT1H", timeZone: "UTC" }]); // null — no departure at allstartTimeZone reads a zoneless first departure as a published local time. It is ignored when
the departure is already exact, and an invalid startTimeZone returns null even when nothing
needs it.
scheduleDelivery([{ departure: "2024-06-15T10:00:00", duration: "PT1H", timeZone: "UTC" }], { startTimeZone: "Asia/Kolkata" });// { eta: "2024-06-15T05:30:00+00:00[UTC]", … } — read as 10:00 in Kolkata
scheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT1H", timeZone: "UTC" }], { startTimeZone: "Asia/Kolkata" });// { eta: "2024-06-15T11:00:00+00:00[UTC]", … } — already exact: the option is ignored
scheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT1H", timeZone: "UTC" }], { startTimeZone: "Mars/Olympus_Mons" });// null — an invalid startTimeZone returns null even unusedA timetable prints a local time at every hub, not just at the origin. A zoneless departure on a
later leg is read in the previous leg’s timeZone, because that is where the leg leaves from.
startTimeZone never applies to it, and the missed-connection check still runs.
scheduleDelivery([ { departure: "2024-06-15T00:00:00Z", duration: "PT10H", timeZone: "Asia/Tokyo" }, { departure: "2024-06-15T20:00:00", duration: "PT1H", timeZone: "UTC" },]);// { eta: "2024-06-15T12:00:00+00:00[UTC]", … } — leg 1 lands in Tokyo at 19:00, and leg 2's// printed 20:00 is read on Tokyo's clock: 11:00Z
scheduleDelivery([ { departure: "2024-06-15T00:00:00Z", duration: "PT10H", timeZone: "Asia/Tokyo" }, { departure: "2024-06-15T18:30:00", duration: "PT1H", timeZone: "UTC" },]);// null — 18:30 in Tokyo is 09:30Z, before leg 1 lands: a missed connectionA bracket that contradicts its offset returns null.
scheduleDelivery([{ departure: "2024-06-15T10:00:00+00:00[Europe/London]", duration: "PT1H", timeZone: "UTC" }]);// null — London is +01:00 in June: the bracket and the offset disagreeThe resolution rule, stated once: an ambiguous wall time (a fall-back night’s repeated hour) resolves to the earlier instant, and a nonexistent one (a spring-forward night’s skipped hour) resolves to the later instant. Writing the offset picks the other pass of a repeated hour — but names no instant in a skipped one, because none exists.
// 02:30 on Sydney's fall-back night, with no offset: the earlier passscheduleDelivery([{ departure: "2024-04-07T02:30:00[Australia/Sydney]", duration: "PT1H", timeZone: "Australia/Sydney" }]);// { eta: "2024-04-07T02:30:00+10:00[Australia/Sydney]", … } — it left 15:30Z
// The same 02:30, with +10:00 written: the later passscheduleDelivery([{ departure: "2024-04-07T02:30:00+10:00[Australia/Sydney]", duration: "PT1H", timeZone: "Australia/Sydney" }]);// { eta: "2024-04-07T03:30:00+10:00[Australia/Sydney]", … } — it left 16:30Z
// 01:30 on London's spring-forward night never shows: it resolves to 02:30scheduleDelivery([{ departure: "2024-03-31T01:30:00[Europe/London]", duration: "PT1H", timeZone: "Europe/London" }]);// { eta: "2024-03-31T03:30:00+01:00[Europe/London]", … } — it left 01:30Z, 02:30 BST
// Writing an offset into the skipped hour still names nothing: nullscheduleDelivery([{ departure: "2024-03-31T01:30:00+00:00[Europe/London]", duration: "PT1H", timeZone: "Europe/London" }], { startTimeZone: "Europe/London" });// null — no offset names a time the clock skippedOne exception applies at a hub. A printed timetable never says which pass of a repeated hour it means, so on any leg but the first a repeated hour takes the earliest pass the cargo can catch: the first at or after the previous arrival plus its dwell. When neither pass is that late, it takes the earlier pass, and the connection is missed.
// Leg 1 lands in London at 01:00 GMT (01:00Z), after the 01:30 BST pass has gonescheduleDelivery([ { departure: "2024-10-27T01:00:00Z", duration: "PT0S", timeZone: "Europe/London" }, { departure: "2024-10-27T01:30:00", duration: "PT1H", timeZone: "UTC" },]);// { eta: "2024-10-27T02:30:00+00:00[UTC]", … } — it left at the later pass, 01:30 GMT (01:30Z)Read a printed timetable this way in the Timetable Reader, and see the general DST rule in the DST Inspector.
Tags, zones and the sentinels
Section titled “Tags, zones and the sentinels”mode, origin and destination are opaque tags echoed onto each LegTime, and absent when
not supplied. timeZone is the caller’s fact: GMT resolves no port or station code to a zone. A
fixed offset is accepted as a zone, but observes no DST.
scheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT1H", timeZone: "UTC", mode: "truck", origin: "CHI", destination: "LAX" }]);// { …, legTimes: [{ …, mode: "truck", origin: "CHI", destination: "LAX" }] } — all three echoed
scheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT1H", timeZone: "+09:00" }]);// { eta: "2024-06-15T20:00:00+09:00[+09:00]", … } — a fixed offset, no DSTEvery sentinel and its neighbour: an empty schedule is valid input, not an error; a zero-length
leg passes; a negative leg, a calendar-unit duration, a negative dwell and a non-array input
all return null.
scheduleDelivery([]); // { eta: "", legTimes: [] } — valid input, not an errorscheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "PT0S", timeZone: "UTC" }]);// { eta: "2024-06-15T10:00:00+00:00[UTC]", … } — a zero-length leg passesscheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "-PT1H", timeZone: "UTC" }]); // null — negative legscheduleDelivery([{ departure: "2024-06-15T10:00:00Z", duration: "P1M", timeZone: "UTC" }]); // null — calendar unitsscheduleDelivery([ { departure: "2024-06-15T10:00:00Z", duration: "PT1H", timeZone: "UTC", dwellAfter: "-PT1H" }, { duration: "PT1H", timeZone: "UTC" },]); // null — negative dwellscheduleDelivery("legs"); // null — not an arrayA crossing is exact time on the authority’s clock: crossingTime
Section titled “A crossing is exact time on the authority’s clock: crossingTime”crossingTime(entry, exit, targetZone) times a
crossing — a canal transit, a strait passage, a border queue — logged as two instants and read
on the clock of the place that administers it. duration is exact elapsed time with hours as
the largest unit.
crossingTime("2024-06-15T08:00:00Z", "2024-06-15T17:30:00Z", "Europe/Berlin");// { duration: "PT9H30M", enter: "2024-06-15T10:00:00+02:00[Europe/Berlin]", exit: "2024-06-15T19:30:00+02:00[Europe/Berlin]" }
// Seven elapsed hours, while the wall clocks read 00:00 and 08:00crossingTime("2024-03-31T00:00:00Z", "2024-03-31T07:00:00Z", "Europe/London");// { duration: "PT7H", enter: "2024-03-31T00:00:00+00:00[Europe/London]", exit: "2024-03-31T08:00:00+01:00[Europe/London]" }
// One elapsed hour; both ends read 02:30, and the offsets tell them apartcrossingTime("2024-04-06T15:30:00Z", "2024-04-06T16:30:00Z", "Australia/Sydney");// { duration: "PT1H", enter: "2024-04-07T02:30:00+11:00[Australia/Sydney]", exit: "2024-04-07T02:30:00+10:00[Australia/Sydney]" }targetZone is always the rendering zone, and the inputs take no bracket. A fixed
offset renders with no DST: the spring-forward night on a fixed +00:00 reads 07:00, not
London’s 08:00.
crossingTime("2024-06-15T08:00:00+02:00", "2024-06-15T17:30:00+02:00", "America/Panama");// { duration: "PT9H30M", enter: "2024-06-15T01:00:00-05:00[America/Panama]", exit: "2024-06-15T10:30:00-05:00[America/Panama]" } — the offset fixes each instant
crossingTime("2024-03-31T00:00:00Z", "2024-03-31T07:00:00Z", "+00:00");// { duration: "PT7H", enter: "2024-03-31T00:00:00+00:00[+00:00]", exit: "2024-03-31T07:00:00+00:00[+00:00]" } — 07:00, not London's 08:00A zero-length crossing is PT0S. An exit before its entry, an unknown zone, or a zoneless time
all return null.
crossingTime("2024-06-15T10:00:00Z", "2024-06-15T10:00:00Z", "Asia/Tokyo");// { duration: "PT0S", enter: "2024-06-15T19:00:00+09:00[Asia/Tokyo]", exit: "2024-06-15T19:00:00+09:00[Asia/Tokyo]" }crossingTime("2024-06-16T01:00:00Z", "2024-06-15T22:30:00Z", "Europe/London"); // null — exit before entrycrossingTime("2024-06-15T22:30:00Z", "2024-06-16T01:00:00Z", "Europe/Londres"); // null — unknown zonecrossingTime("2024-06-15T22:30:00", "2024-06-16T01:00:00Z", "Europe/London"); // null — entry has no offset: not a momentcrossingTime counts no calendar days — a crossing that needs a day count is a dwell; see
dwellTime. Open a crossing in the
Crossing Clock.
The exported types
Section titled “The exported types”Crossing, Leg, LegTime,
ScheduleDeliveryOptions and DeliverySchedule are
exported as types, for the legs you pass in and the schedule you get back.
See it break, then work
Section titled “See it break, then work”- Delivery Scheduler: a truck, a ship and a train across the spring-forward
- Connection Checker: slide the handling time across the boundary
- Timetable Reader: one printed time, two instants
- Crossing Clock: seven hours that read as eight
- A Connection Missed at the Spring-Forward Handoff
- Transport mistakes: multi-leg scheduling
© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.