Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/main/java/org/mtransit/parser/gtfs/GReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,30 @@ private static void processFrequency(

private static final Set<String> AVAILABLE_TIME_ZONE_IDS = ZoneId.getAvailableZoneIds(); // cache because it returns new set copy every time

private static final String TIME_ZONE_UTC_7_FOREVER = "America/Phoenix";
private static final String TIME_ZONE_UTC_6_FOREVER = "America/Regina";
private static final String TIME_ZONE_UTC_5_FOREVER = "America/Cancun";

private static final Map<String, String> TIME_ZONES_OVERRIDES = Map.of(
// Canada - BC
"America/Vancouver", TIME_ZONE_UTC_7_FOREVER,
"Canada/Pacific", TIME_ZONE_UTC_7_FOREVER, // Legacy Alias (Pointer)
// Canada - AB
"America/Edmonton", TIME_ZONE_UTC_6_FOREVER,
"Canada/Mountain", TIME_ZONE_UTC_6_FOREVER, // Legacy Alias (Pointer)
// Canada - NT
"America/Yellowknife", TIME_ZONE_UTC_6_FOREVER,
"America/Inuvik", TIME_ZONE_UTC_6_FOREVER,
// Canada - MB
"America/Winnipeg", TIME_ZONE_UTC_5_FOREVER,
"Canada/Central", TIME_ZONE_UTC_5_FOREVER, // Legacy Alias (Pointer)
// Canada - ON
"America/Rainy_River", TIME_ZONE_UTC_5_FOREVER // (different from the rest of ON)
);
Comment thread
mmathieum marked this conversation as resolved.
Resolved

private static void processAgency(GAgencyTools agencyTools, GSpec gSpec, HashMap<String, String> line) {
try {
final GAgency gAgency = GAgency.fromLine(line, AVAILABLE_TIME_ZONE_IDS, agencyTools.getAgencyDefaultLanguage());
final GAgency gAgency = GAgency.fromLine(line, AVAILABLE_TIME_ZONE_IDS, TIME_ZONES_OVERRIDES, agencyTools.getAgencyDefaultLanguage());
if (agencyTools.excludeAgency(gAgency)) {
MTLog.logDebug("processAgency() > SKIP (exclude agency)");
return;
Expand Down Expand Up @@ -558,8 +579,8 @@ private static void processStop(GAgencyTools agencyTools, GSpec gSpec, Map<Strin
MTLog.log("Generic node stop ignored (%s).", line); // not lat/lng?
return;
}
final GStop gStop = skipDataCleanup ? GStop.fromLine(line, agencyTimezone, AVAILABLE_TIME_ZONE_IDS)
: GStop.fromLine(line, agencyTimezone, AVAILABLE_TIME_ZONE_IDS, agencyTools);
final GStop gStop = skipDataCleanup ? GStop.fromLine(line, agencyTimezone, AVAILABLE_TIME_ZONE_IDS, TIME_ZONES_OVERRIDES)
: GStop.fromLine(line, agencyTimezone, AVAILABLE_TIME_ZONE_IDS, TIME_ZONES_OVERRIDES, agencyTools);
if (agencyTools.excludeStop(gStop)) {
//noinspection DiscouragedApi
logExclude("Exclude stop: %s.", line.get(GStop.STOP_ID));
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/mtransit/parser/gtfs/data/GAgency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,18 @@ data class GAgency(
private const val AGENCY_EMAIL = "agency_email" // Optional

@JvmStatic
fun fromLine(line: Map<String, String>, availableZoneIds: Set<String>, defaultLanguage: String?) = GAgency(
fun fromLine(
line: Map<String, String>,
availableZoneIds: Set<String>,
timeZonesOverrides: Map<String, String>,
defaultLanguage: String?,
) = GAgency(
agencyId = line[AGENCY_ID].orEmpty(),
agencyName = line[AGENCY_NAME] ?: throw MTLog.Fatal("Invalid GAgency from $line!"),
agencyUrl = line[AGENCY_URL] ?: throw MTLog.Fatal("Invalid GAgency from $line!"),
agencyTimezone = line[AGENCY_TIMEZONE]?.trim()
?.takeIf { it.isNotBlank() }
?.let { timeZonesOverrides[it] ?: it }
Comment thread
mmathieum marked this conversation as resolved.
Resolved
Comment thread
mmathieum marked this conversation as resolved.
Resolved
?.takeIf { availableZoneIds.contains(it) }
?: throw MTLog.Fatal("Invalid GAgency from $line!"),
agencyLang = line[AGENCY_LANG]?.takeIf { it.isNotBlank() } ?: defaultLanguage?.takeIf { it.isNotBlank() },
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/mtransit/parser/gtfs/data/GStop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ data class GStop(

@JvmOverloads
@JvmStatic
fun fromLine(line: Map<String, String>, agencyTimezone: String?, availableZoneIds: Set<String>, agencyTools: GAgencyTools? = null) = GStop(
fun fromLine(
line: Map<String, String>,
agencyTimezone: String?,
availableZoneIds: Set<String>,
timeZonesOverrides: Map<String, String>,
agencyTools: GAgencyTools? = null,
) = GStop(
stopId = line[STOP_ID]?.trim()
?.let { agencyTools?.cleanStopOriginalId(it) ?: it }
?: throw MTLog.Fatal("Invalid GStop from $line!"),
Expand All @@ -138,6 +144,7 @@ data class GStop(
?.let { agencyTools?.cleanStopOriginalId(it) ?: it },
stopTimezone = line[STOP_TIMEZONE]?.trim()
?.takeIf { it.isNotBlank() }
?.let { timeZonesOverrides[it] ?: it }
?.also { gStopTimezone ->
if (!availableZoneIds.contains(gStopTimezone)) {
throw MTLog.Fatal("Invalid stop timezone in $line!")
Expand Down
Loading