Skip to content

Commit

Permalink
added logic for filtering late and early months
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezryr committed Oct 26, 2024
1 parent 164db4a commit de99f08
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions components/PlantList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,51 @@ export const PlantList = ({
}
};

// Handle late/early month logic -- Set late/early month to just the month
let indoorsStart = plant.indoors_start;
let indoorsEnd = plant.indoors_end;
let outdoorsStart = plant.outdoors_start;
let outdoorsEnd = plant.outdoors_end;

/// If field is not null and starts with 'LATE' or 'EARLY,
// get substring after 'LATE_ or 'EARLY_'
if (
indoorsStart &&
(indoorsStart.startsWith('LATE') || indoorsStart.startsWith('EARLY'))
) {
indoorsStart = indoorsStart.substring(5);
}
if (
indoorsEnd &&
(indoorsEnd.startsWith('LATE') || indoorsEnd.startsWith('EARLY'))
) {
indoorsEnd = indoorsEnd.substring(5);
}
if (
outdoorsStart &&
(outdoorsStart.startsWith('LATE') || outdoorsStart.startsWith('EARLY'))
) {
outdoorsStart = outdoorsStart.substring(5);
}
if (
outdoorsEnd &&
(outdoorsEnd.startsWith('LATE') || outdoorsEnd.startsWith('EARLY'))
) {
outdoorsEnd = outdoorsEnd.substring(5);
}

// Checks if either indoor_start to indoor_end or outdoor_start to outdoor_end
// is within the valid range
// exclamation marks to assert values are not undefined
return (
isInRange(
monthToIndex.get(plant.indoors_start)!,
monthToIndex.get(plant.indoors_end)!,
monthToIndex.get(indoorsStart)!,
monthToIndex.get(indoorsEnd)!,
validIndexes!,
) ||
isInRange(
monthToIndex.get(plant.outdoors_start)!,
monthToIndex.get(plant.outdoors_end)!,
monthToIndex.get(outdoorsStart)!,
monthToIndex.get(outdoorsEnd)!,
validIndexes!,
)
);
Expand Down

0 comments on commit de99f08

Please sign in to comment.