From e102cf9234d2842d25759d8d5067b10a8f8ed011 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 25 Jan 2022 17:34:15 -0500 Subject: Add overwinterPlant property to Crop to support a Garlic crop. --- js/garden.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'js') diff --git a/js/garden.js b/js/garden.js index f9f5f06..daf014b 100644 --- a/js/garden.js +++ b/js/garden.js @@ -25,7 +25,7 @@ function seasonLengthInWeeks(lastFrostDate, firstFrostDate) { } function seasonWeeks(lastFrostDate, seasonLength) { - return range(-WEEKS_BEFORE_LAST_FROST, seasonLength + 1).map(offset => { + return range(-WEEKS_BEFORE_LAST_FROST, seasonLength + 3).map(offset => { return { date: weeksLater(lastFrostDate, offset), offset: offset @@ -44,8 +44,8 @@ class Season { class Crop { constructor(name, {fallCrop, family, headStart, interval, maturity, multisow, - pause, spacing, springPlant, resume, species, - transplant, trellis}) { + overwinterPlant, pause, spacing, springPlant, resume, + species, transplant, trellis}) { // Plant again in the fall? this.fallCrop = fallCrop; // Broad category (brassica, cucurbit, nightshade, etc.) @@ -60,6 +60,12 @@ class Crop { this.multisow = multisow || 1; // Human readable name this.name = name; + // Overwintered crops are fall crops but they are not subject to + // the same rules as plants that are harvested the same year. + // Instead of planting them relative to their time to maturity, + // they are planted relative to the first frost date so they can + // be harvested in the spring/summer of the following year. + this.overwinterPlant = overwinterPlant; // When to pause succession planting (weeks after last frost) this.pause = pause || 99; // When to resume succession planting (weeks before first frost) @@ -70,7 +76,8 @@ class Crop { // Latin names. this.species = species || []; // Earliest sowing/transplanting week (offset relative to last - // frost date.) + // frost date.) Null if the crop should not be planted in the + // spring. this.springPlant = springPlant; // Transplanted or direct sown? this.transplant = transplant || false; @@ -247,6 +254,13 @@ const CROPS = [ species: ["foeniculum vulgare"], springPlant: 0 }), + new Crop("Garlic", { + fallCrop: true, + overwinterPlant: 2, + maturity: 28, + spacing: 4, + species: ["allium sativum"] + }), new Crop("Kale", { fallCrop: true, family: "Brassica", @@ -471,7 +485,11 @@ function makeCropSchedule(crop, season) { } if(crop.fallCrop) { - if(crop.transplant && week.offset == fallStart) { + if(crop.overwinterPlant) { + if(week.offset == season.length + crop.overwinterPlant) { + actions.push("sow"); + } + } else if(crop.transplant && week.offset == fallStart) { actions.push("start"); } else if(crop.transplant && week.offset == fallPlant) { actions.push("transplant"); -- cgit v1.2.3