gtfs 4.17.1 → 4.17.3

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.
@@ -1059,7 +1059,6 @@ var riderCategories = {
1059
1059
  {
1060
1060
  name: "is_default_fare_category",
1061
1061
  type: "integer",
1062
- required: true,
1063
1062
  min: 0,
1064
1063
  max: 1
1065
1064
  },
@@ -3354,16 +3353,6 @@ function convertLongTimeToDate(longDate) {
3354
3353
  Long.fromBits(low, high, unsigned).toNumber() * 1e3
3355
3354
  ).toISOString();
3356
3355
  }
3357
- function calculateSecondsFromMidnight(time) {
3358
- if (!time || typeof time !== "string") {
3359
- return null;
3360
- }
3361
- const [hours, minutes, seconds] = time.split(":").map(Number);
3362
- if ([hours, minutes, seconds].some(isNaN) || minutes >= 60 || seconds >= 60) {
3363
- return null;
3364
- }
3365
- return hours * 3600 + minutes * 60 + seconds;
3366
- }
3367
3356
  function padLeadingZeros(time) {
3368
3357
  const split = time.split(":").map((d) => String(Number(d)).padStart(2, "0"));
3369
3358
  if (split.length !== 3) {
@@ -3588,18 +3577,6 @@ async function updateGtfsRealtimeData(task) {
3588
3577
  }
3589
3578
 
3590
3579
  // src/lib/import-gtfs.ts
3591
- var timeCache = {};
3592
- var formatAndCacheTime = (value) => {
3593
- const cached = timeCache[value];
3594
- if (cached !== void 0) {
3595
- return cached;
3596
- }
3597
- const timeAsSecondsFromMidnight = calculateSecondsFromMidnight(value);
3598
- const timeAsString = padLeadingZeros(value);
3599
- const computed = [timeAsSecondsFromMidnight, timeAsString];
3600
- timeCache[value] = computed;
3601
- return computed;
3602
- };
3603
3580
  var getTextFiles = async (folderPath) => {
3604
3581
  const files = await readdir(folderPath);
3605
3582
  return files.filter((filename) => filename.slice(-3) === "txt");
@@ -3711,7 +3688,16 @@ var createGtfsTables = (db) => {
3711
3688
  );
3712
3689
  if (column.type === "time") {
3713
3690
  sqlColumnCreateStatements.push(
3714
- `${getTimestampColumnName(column.name)} INTEGER`
3691
+ `${getTimestampColumnName(column.name)} INTEGER GENERATED ALWAYS AS (
3692
+ CASE
3693
+ WHEN ${column.name} IS NULL OR ${column.name} = '' THEN NULL
3694
+ ELSE CAST(
3695
+ substr(${column.name}, 1, instr(${column.name}, ':') - 1) * 3600 +
3696
+ substr(${column.name}, instr(${column.name}, ':') + 1, 2) * 60 +
3697
+ substr(${column.name}, -2) AS INTEGER
3698
+ )
3699
+ END
3700
+ ) STORED`
3715
3701
  );
3716
3702
  }
3717
3703
  }
@@ -3756,9 +3742,6 @@ var formatGtfsLine = (line, model, totalLineCount) => {
3756
3742
  let value = line[name];
3757
3743
  if (value === "" || value === void 0 || value === null) {
3758
3744
  formattedLine[name] = null;
3759
- if (type === "time") {
3760
- formattedLine[getTimestampColumnName(name)] = null;
3761
- }
3762
3745
  if (required) {
3763
3746
  throw new Error(
3764
3747
  `Missing required value in ${filenameBase}.${filenameExtension} for ${name} on line ${lineNumber}.`
@@ -3774,9 +3757,7 @@ var formatGtfsLine = (line, model, totalLineCount) => {
3774
3757
  );
3775
3758
  }
3776
3759
  } else if (type === "time") {
3777
- const [timeAsSecondsFromMidnight, timeAsString] = formatAndCacheTime(value);
3778
- value = timeAsString;
3779
- formattedLine[getTimestampColumnName(name)] = timeAsSecondsFromMidnight ?? null;
3760
+ value = padLeadingZeros(value);
3780
3761
  }
3781
3762
  if (type === "json") {
3782
3763
  value = JSON.stringify(value);
@@ -3809,19 +3790,7 @@ var importGtfsFiles = (db, task) => mapSeries2(
3809
3790
  return;
3810
3791
  }
3811
3792
  task.log(`Importing - ${filename}\r`);
3812
- const columns = model.schema.flatMap((column) => {
3813
- if (column.type === "time") {
3814
- return [
3815
- column,
3816
- {
3817
- name: getTimestampColumnName(column.name),
3818
- type: "integer",
3819
- index: true
3820
- }
3821
- ];
3822
- }
3823
- return column;
3824
- });
3793
+ const columns = model.schema;
3825
3794
  const prefixedColumns = new Set(
3826
3795
  columns.filter((column) => column.prefix).map((column) => column.name)
3827
3796
  );