Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix DST change issues #94

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/gtfs/command/AddLateNightServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import {Schedule} from "../native/Schedule";
import {IdGenerator} from "../native/OverlayRecord";

/**
* Loop through every schedule and add a copy of any early morning services to the previous day.
* Loop through every schedule and replace any early morning services with a copy on the previous day.
*
* GTFS specification defines "time" as starting from noon minus 12 hours, which is normally midnight
* but may be different by 1 hour on the day when the summer time zone changes, in order to avoid
* a DST change happening inside a service day.
*
* Therefore, trains which depart before the change on changeover days should be recorded as on the
* previous service day instead.
*/
export function addLateNightServices(schedules: Schedule[], idGenerator: IdGenerator): Schedule[] {
const result: Schedule[] = [];

for (const schedule of schedules) {
result.push(schedule);
const departureHour = parseInt(schedule.stopTimes[0].departure_time.substr(0, 2), 10);

if (departureHour <= 1) {
Expand All @@ -20,6 +26,8 @@ export function addLateNightServices(schedules: Schedule[], idGenerator: IdGener
}

result.push(newSchedule);
} else {
result.push(schedule);
}
}

Expand Down
24 changes: 11 additions & 13 deletions test/gtfs/command/AddLateNightServices.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ describe("AddLateNightServices", () => {

const schedules = addLateNightServices(baseSchedules, idGenerator());

chai.expect(schedules[0].calendar.runsFrom.isSame("20181001")).to.be.true;
chai.expect(schedules[0].calendar.runsTo.isSame("20181031")).to.be.true;
chai.expect(schedules[1].calendar.runsFrom.isSame("20180930")).to.be.true;
chai.expect(schedules[1].calendar.runsTo.isSame("20181030")).to.be.true;
chai.expect(schedules[1].calendar.days[0]).to.equal(1);
chai.expect(schedules[1].calendar.days[1]).to.equal(1);
chai.expect(schedules[1].calendar.days[2]).to.equal(1);
chai.expect(schedules[1].calendar.days[3]).to.equal(1);
chai.expect(schedules[1].calendar.days[4]).to.equal(0);
chai.expect(schedules[1].calendar.days[5]).to.equal(0);
chai.expect(schedules[1].calendar.days[6]).to.equal(1);
chai.expect(schedules[2].calendar.runsFrom.isSame("20181001")).to.be.true;
chai.expect(schedules[2].calendar.runsTo.isSame("20181031")).to.be.true;
chai.expect(schedules[0].calendar.runsFrom.isSame("20180930")).to.be.true;
chai.expect(schedules[0].calendar.runsTo.isSame("20181030")).to.be.true;
chai.expect(schedules[0].calendar.days[0]).to.equal(1);
chai.expect(schedules[0].calendar.days[1]).to.equal(1);
chai.expect(schedules[0].calendar.days[2]).to.equal(1);
chai.expect(schedules[0].calendar.days[3]).to.equal(1);
chai.expect(schedules[0].calendar.days[4]).to.equal(0);
chai.expect(schedules[0].calendar.days[5]).to.equal(0);
chai.expect(schedules[0].calendar.days[6]).to.equal(1);
chai.expect(schedules[1].calendar.runsFrom.isSame("20181001")).to.be.true;
chai.expect(schedules[1].calendar.runsTo.isSame("20181031")).to.be.true;
});

});
Expand Down
Loading