diff --git a/components/PlantList.tsx b/components/PlantList.tsx index 3dd4a4c..5f647dc 100644 --- a/components/PlantList.tsx +++ b/components/PlantList.tsx @@ -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!, ) );