Skip to content

Commit

Permalink
Merge 7114f48 into 8bd29ec
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrojas87 committed Jan 25, 2020
2 parents 8bd29ec + 7114f48 commit db5f81b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 55 deletions.
4 changes: 2 additions & 2 deletions lib/URIStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ var URIStrategy = function (baseUris, stopsdb) {
stop: 'http://example.org/stops/{stops.stop_id}',
route: 'http://example.org/routes/{routes.route_id}',
trip:
'http://example.org/trips/{trips.trip_id}/{trips.startTime(YYYYMMDD)}',
'http://example.org/trips/{trips.trip_id}/{trips.startTime(yyyyMMdd)}',
connection:
'http://example.org/connections/{trips.startTime(YYYYMMDD)}/{connection.departureStop}/{trips.trip_id}'
'http://example.org/connections/{trips.startTime(yyyyMMdd)}/{connection.departureStop}/{trips.trip_id}'
};
if (!baseUris) {
baseUris = defaultBaseUris;
Expand Down
11 changes: 6 additions & 5 deletions lib/services/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const Transform = require('stream').Transform,
util = require('util'),
StreamIterator = require('../StreamIterator'),
{format, addDays, eachDay, isSameDay } = require('date-fns');
{format, addDays, eachDayOfInterval, isSameDay } = require('date-fns');

var CalendarToServices = function (calendarDatesStream, options) {
Transform.call(this, {objectMode : true});
Expand Down Expand Up @@ -94,14 +94,15 @@ CalendarToServices.prototype._processCalendarDates = function (calendar, service

CalendarToServices.prototype._transform = function (calendar, encoding, done) {
//Step one: parse and expand the calendar in memory
//GTFS specification declares a date as YYYYMMDD. No other formats possible. Parsing with substr should be safe. Mind that timezones don’t matter here. They only matter in the ConnectionsBuilder
//GTFS specification declares a date as yyyyMMdd. No other formats possible. Parsing with substr should be safe. Mind that timezones don’t matter here. They only matter in the ConnectionsBuilder
var startDate = new Date(calendar['start_date'].substr(0,4), parseInt(calendar['start_date'].substr(4,2))-1, calendar['start_date'].substr(6,2));
var endDate = new Date(calendar['end_date'].substr(0,4), parseInt(calendar['end_date'].substr(4,2))-1, calendar['end_date'].substr(6,2));
var expanded = [];
let days = eachDay(startDate, endDate);
let days = eachDayOfInterval({ start: startDate, end: endDate });

for (let d of days) {
if (calendar[format(d,'dddd').toLowerCase()] === '1') {
expanded.push(format(d,'YYYYMMDD'));
if (calendar[format(d, 'iiii').toLowerCase()] === '1') {
expanded.push(format(d,'yyyyMMdd'));
}
}
//Step two: match potential exceptions
Expand Down
78 changes: 32 additions & 46 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"JSONStream": "^1.3.5",
"asynciterator": "^2.0.1",
"commander": "^2.20.0",
"date-fns": "^1.30.1",
"date-fns": "^2.9.0",
"fast-csv": "^3.0.1",
"jsonld-stream": "^1.0.4",
"level": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion test/URIStrategy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('URIStrategy', () => {
'http://example.org/connections/{trip_startTime}/{departureStop}/{trip_id}',
resolve: {
trip_id: 'connection.trip.trip_id',
trip_startTime: "format(connection.trip.startTime, 'YYYYMMDDTHHmm');",
trip_startTime: 'format(connection.trip.startTime, "yyyyMMdd\'T\'HHmm");',
departureStop: 'connection.departureStop',
},
});
Expand Down

0 comments on commit db5f81b

Please sign in to comment.