diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java index 9195d51..a362f00 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/GardenSchedule.java @@ -46,7 +46,8 @@ public class GardenSchedule { */ public void planTasksForCrop(Crop crop) throws PlantNotFoundException, HardinessZoneNotSetException, IOException { Plant plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).orElseThrow(PlantNotFoundException::new); - for (GrowthPhase growthPhase : plant.lifecycle()) { + int growPhaseGroup = plant.getGrowphaseGroupForDate(crop.getStartDate()); + for (GrowthPhase growthPhase : plant.lifecycleForGroup(growPhaseGroup)) { for (TaskTemplate taskTemplate : growthPhase.taskTemplates()) { addTask(taskTemplate.generateTask(crop.getStartDate(), crop.getCropId().orElse(0L))); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java index 9cb3d08..5fb6dff 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java @@ -3,6 +3,7 @@ package ch.zhaw.gartenverwaltung.types; import javafx.scene.image.Image; import java.time.LocalDate; +import java.time.MonthDay; import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; @@ -39,6 +40,16 @@ public record Plant( .collect(Collectors.toList()); } + public int getGrowphaseGroupForDate(LocalDate date) { + for(GrowthPhase growthPhase : lifecycle){ + MonthDay plantingDate = MonthDay.of(date.getMonth().getValue(), date.getDayOfMonth()); + if(plantingDate.isAfter(growthPhase.startDate()) && plantingDate.isBefore(growthPhase.endDate())){ + return growthPhase.group(); + } + } + return 0; // TODO implement + } + /** * get sow date from given harvest day from lifecycle group * @param harvestDate date of the harvest