@tmlmobilidade/generate-offer-files 20250626.1514.36 → 20250626.1908.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +3 -18
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -3,7 +3,7 @@ import LOGGER from '@helperkits/logger';
|
|
|
3
3
|
import TIMETRACKER from '@helperkits/timer';
|
|
4
4
|
import { JsonWriter } from '@helperkits/writer';
|
|
5
5
|
import { validateOperationalDate } from '@tmlmobilidade/types';
|
|
6
|
-
import { Dates } from '@tmlmobilidade/utils';
|
|
6
|
+
import { Dates, getOperationalDatesFromRange } from '@tmlmobilidade/utils';
|
|
7
7
|
import { parse as csvParser } from 'csv-parse';
|
|
8
8
|
import extract from 'extract-zip';
|
|
9
9
|
import fs from 'fs';
|
|
@@ -101,7 +101,7 @@ export async function generateOfferOutput(filePath, startDate, endDate, outputDi
|
|
|
101
101
|
// If we're here, it means the service_id is valid between the given dates.
|
|
102
102
|
// For the configured weekly schedule, create the individual operational dates
|
|
103
103
|
// for each day of the week that is active.
|
|
104
|
-
const allOperationalDatesInRange =
|
|
104
|
+
const allOperationalDatesInRange = getOperationalDatesFromRange(serviceIdStartDate, serviceIdEndDate);
|
|
105
105
|
const validOperationalDates = [];
|
|
106
106
|
for (const currentDate of allOperationalDatesInRange) {
|
|
107
107
|
const dayOfWeek = Dates.fromOperationalDate(currentDate, 'Europe/Lisbon').toFormat('c');
|
|
@@ -393,7 +393,7 @@ export async function generateOfferOutput(filePath, startDate, endDate, outputDi
|
|
|
393
393
|
throw new Error('✖︎ Error processing "stop_times.txt" file.');
|
|
394
394
|
}
|
|
395
395
|
/* * */
|
|
396
|
-
/*
|
|
396
|
+
/* OUTPUT FILES */
|
|
397
397
|
//
|
|
398
398
|
// Actually construct the OfferJourney and OfferStop objects
|
|
399
399
|
// and write them to the output files. This is the final step of the process.
|
|
@@ -621,18 +621,3 @@ const convertMetersOrKilometersToMeters = (value, ballpark) => {
|
|
|
621
621
|
}
|
|
622
622
|
//
|
|
623
623
|
};
|
|
624
|
-
/* * */
|
|
625
|
-
export function getIndividualDatesFromRange(start, end) {
|
|
626
|
-
if (end < start)
|
|
627
|
-
throw new Error(`End date "${end}" must be after start date "${start}"`);
|
|
628
|
-
// Parse the start and end dates to ensure they are in the correct format
|
|
629
|
-
const startDate = Dates.fromOperationalDate(start, 'Europe/Lisbon');
|
|
630
|
-
const endDate = Dates.fromOperationalDate(end, 'Europe/Lisbon');
|
|
631
|
-
const dates = [];
|
|
632
|
-
let current = startDate;
|
|
633
|
-
while (current.operational_date <= endDate.operational_date) {
|
|
634
|
-
dates.push(current.operational_date);
|
|
635
|
-
current = current.plus({ days: 1 });
|
|
636
|
-
}
|
|
637
|
-
return dates;
|
|
638
|
-
}
|