Skip to content

Commit

Permalink
Renamed time caching functions
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Nov 14, 2024
1 parent 8e21558 commit 8a1e125
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Updated
- Renamed time caching functions

### Fixed
- Better GTFS export for currency

Expand Down
23 changes: 12 additions & 11 deletions src/lib/import-gtfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ interface Dictionary<T> {
}
type Tuple = [seconds: number | null, date: string | null];

const dateCache: Dictionary<Tuple> = {};
const timeCache: Dictionary<Tuple> = {};

const calculateAndCacheDate = (value: string): Tuple => {
const cached = dateCache[value];
if (cached != null) {
const formatAndCacheTime = (value: string): Tuple => {
const cached = timeCache[value];
if (cached !== undefined) {
return cached;
}

const seconds = calculateSecondsFromMidnight(value);
const date = padLeadingZeros(value);
const computed: Tuple = [seconds, date];
dateCache[value] = computed;
const timeAsSecondsFromMidnight = calculateSecondsFromMidnight(value);
const timeAsString = padLeadingZeros(value);
const computed: Tuple = [timeAsSecondsFromMidnight, timeAsString];
timeCache[value] = computed;
return computed;
};

Expand Down Expand Up @@ -304,9 +304,10 @@ const formatGtfsLine = (
for (const [timeColumnName, timestampColumnName] of TIME_COLUMN_PAIRS) {
const value = formattedLine[timeColumnName];
if (value) {
const [seconds, date] = calculateAndCacheDate(value);
formattedLine[timestampColumnName] = seconds;
formattedLine[timeColumnName] = date;
const [timeAsSecondsFromMidnight, timeAsString] =
formatAndCacheTime(value);
formattedLine[timestampColumnName] = timeAsSecondsFromMidnight;
formattedLine[timeColumnName] = timeAsString;
}
}

Expand Down

0 comments on commit 8a1e125

Please sign in to comment.