Skip to content

Commit

Permalink
update date format tests
Browse files Browse the repository at this point in the history
  • Loading branch information
linusnorton committed Oct 21, 2018
1 parent 341f32b commit dca45b7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "transxchange2gtfs",
"version": "1.0.1",
"version": "1.0.2",
"description": "Converts transxchange data to GTFS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -36,14 +36,14 @@
"@types/csv-parse": "^1.1.11",
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.5",
"@types/node": "^10.11.6",
"@types/node": "^10.12.0",
"@types/rimraf": "^2.0.2",
"@types/xml2js": "^0.4.3",
"chai": "^4.2.0",
"mocha": "^5.2.0",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.1.1"
"typescript": "^3.1.3"
},
"dependencies": {
"autobind-decorator": "^2.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/gtfs/CalendarDatesStream.ts
Expand Up @@ -6,8 +6,8 @@ import {LocalDate, DateTimeFormatter} from "js-joda";
* Extract the calendars dates from the TransXChange journeys
*/
export class CalendarDatesStream extends GTFSFileStream<TransXChangeJourney> {
private datesSeen: Record<string, boolean> = {};
private dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
private readonly datesSeen: Record<string, boolean> = {};
private readonly dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");

protected header = "service_id,date,exception_type";

Expand Down
9 changes: 6 additions & 3 deletions src/gtfs/CalendarStream.ts
Expand Up @@ -6,15 +6,18 @@ import {DateTimeFormatter} from "js-joda";
* Extract the calendars from the TransXChange journeys
*/
export class CalendarStream extends GTFSFileStream<TransXChangeJourney> {
private datesSeen: Record<string, boolean> = {};
private dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
private readonly datesSeen: Record<string, boolean> = {};
private readonly dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");

protected header = "service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date";

protected transform(journey: TransXChangeJourney): void {
if (!this.datesSeen[journey.calendar.id]) {
const from = journey.calendar.startDate.format(this.dateFormatter);
const to = journey.calendar.endDate.format(this.dateFormatter);

this.pushLine(`${journey.calendar.id},${journey.calendar.days},${from},${to}`);
this.datesSeen[journey.calendar.id] = true;
this.pushLine(`${journey.calendar.id},${journey.calendar.days},${journey.calendar.startDate.format(this.dateFormatter)},${journey.calendar.endDate.format(this.dateFormatter)}`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/gtfs/CalendarDatesStream.spec.ts
Expand Up @@ -29,10 +29,10 @@ describe("CalendarDatesStream", () => {
const include = splitCSV(rows[2]);

chai.expect(exclude[0]).to.equal("1");
chai.expect(exclude[1]).to.equal("2018-12-25");
chai.expect(exclude[1]).to.equal("20181225");
chai.expect(exclude[2]).to.equal("2");
chai.expect(include[0]).to.equal("1");
chai.expect(include[1]).to.equal("2018-06-01");
chai.expect(include[1]).to.equal("20180601");
chai.expect(include[2]).to.equal("1");
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/gtfs/CalendarStream.spec.ts
Expand Up @@ -34,8 +34,8 @@ describe("CalendarStream", () => {
chai.expect(friday).to.equal("1");
chai.expect(saturday).to.equal("1");
chai.expect(sunday).to.equal("1");
chai.expect(start_date).to.equal("2018-06-24");
chai.expect(end_date).to.equal("2099-12-31");
chai.expect(start_date).to.equal("20180624");
chai.expect(end_date).to.equal("20991231");
});
});

Expand Down

0 comments on commit dca45b7

Please sign in to comment.