Skip to content

Commit

Permalink
Merge pull request #95 from linkedconnections/development
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
julianrojas87 committed Jan 25, 2020
2 parents 8bd29ec + 6b620d0 commit 79e2473
Show file tree
Hide file tree
Showing 5 changed files with 1,740 additions and 2,270 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
Loading

0 comments on commit 79e2473

Please sign in to comment.