From b952cd38e7286be5b0198b4c24ad92eadd2c279c Mon Sep 17 00:00:00 2001
From: Marco Matthies <71844+marcom@users.noreply.github.com>
Date: Mon, 19 Aug 2024 06:52:36 +0200
Subject: [PATCH] Deal with missing minsowdate or maxsowdate for crop

---
 src/farm/farm.jl | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/farm/farm.jl b/src/farm/farm.jl
index 5d024dd..3bc3109 100644
--- a/src/farm/farm.jl
+++ b/src/farm/farm.jl
@@ -64,7 +64,11 @@ function stepagent!(farmer::BasicFarmer, model::SimulationModel)
                 @sow("no growth")
                 cycle!(farmer.croprotations[f]) # advance the crop rotation
                 nextcrop = model.crops[farmer.croprotations[f][1]]
-                farmer.sowdates[f] = @rand(nextcrop.minsowdate:nextcrop.maxsowdate)
+                if ! (ismissing(nextcrop.minsowdate) || ismissing(nextcrop.maxsowdate))
+                    farmer.sowdates[f] = @rand(nextcrop.minsowdate:nextcrop.maxsowdate)
+                else
+                    @warn "minsowdate and/or maxsowdate is `missing` for crop \"$(ctype.name)\", not assigning sowdates"
+                end
             end
         elseif cropname(field) == "no growth" && model.date == farmer.sowdates[f]
             # if a field has been harvested, check if the next crop can be sown
-- 
GitLab