{
  "schemaVersion": 1,
  "slug": "planting-date-calculator",
  "category": "gardening",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "7c73c6d1c7fdfd10b98c7b522068e064eff339667d31fd4ef55a897b0f3f9cdb",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/planting-date-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "D_sow = D_frost + 7w; D_ripe = D_sow + m; spare = (D_autumn − D_ripe) ÷ 86400000",
    "vars": [
      [
        "D_sow",
        "Safe sowing date"
      ],
      [
        "D_frost",
        "Last frost date"
      ],
      [
        "w",
        "Crop offset (weeks)"
      ],
      [
        "m",
        "Days to maturity"
      ],
      [
        "spare",
        "Margin (days)"
      ]
    ],
    "note": "w = −6/−4/−2/+1/+2 by hardiness; indoor start 4/6/8 weeks earlier; harvest end = min(first frost, ripe + 21 d)."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const ms=86400000; const parse=s=>{const m=/^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(String(s));if(!m)return null;const d=new Date(0);d.setUTCHours(0,0,0,0);d.setUTCFullYear(+m[1],+m[2]-1,+m[3]);return d.getUTCFullYear()===+m[1]&&d.getUTCMonth()===+m[2]-1&&d.getUTCDate()===+m[3]?d:null;}; const frost=parse(lastFrostDate),autumn=parse(firstFrostDate); if(!frost||!autumn||autumn<=frost)return {__error:'inputError',safeSowingDate:null,indoorStartDate:null,transplantDate:null,harvestWindowStart:null,harvestWindowEnd:null,growingDays:null,spareDays:null,note:null}; const weeksOff={'very-hardy':-6,hardy:-4,'semi-hardy':-2,tender:1,'very-tender':2}[crop]||0,indoorWeeks={'very-hardy':4,hardy:6,'semi-hardy':6,tender:8,'very-tender':8}[crop]||6,sow=new Date(frost.getTime()+weeksOff*7*ms),indoor=method==='transplant'?new Date(sow.getTime()-indoorWeeks*7*ms):sow,ripe=new Date(sow.getTime()+maturityDays*ms),windowEnd=new Date(ripe.getTime()+21*ms),spare=Math.round((autumn-ripe)/ms),iso=d=>d.toISOString().slice(0,10); if(spare<0)return {safeSowingDate:iso(sow),indoorStartDate:iso(indoor),transplantDate:iso(sow),harvestWindowStart:'No frost-free harvest window',harvestWindowEnd:'—',growingDays:maturityDays,spareDays:spare,note:'Predicted maturity falls after the first frost; choose an earlier variety or change the planting plan.'}; const lastGood=autumn<windowEnd?autumn:windowEnd,note=spare<14?'Only '+spare+' days of margin; a late frost or cool summer could affect harvest.':'Comfortable margin of '+spare+' days for a slow start.'; return {safeSowingDate:iso(sow),indoorStartDate:iso(indoor),transplantDate:iso(sow),harvestWindowStart:iso(ripe),harvestWindowEnd:iso(lastGood),growingDays:maturityDays,spareDays:spare,note};",
    "inputs": [
      {
        "name": "lastFrostDate",
        "type": "date",
        "default": "@today+7m",
        "step": 1
      },
      {
        "name": "firstFrostDate",
        "type": "date",
        "default": "@today+12m",
        "step": 1
      },
      {
        "name": "crop",
        "type": "select",
        "default": "tender",
        "options": [
          {
            "value": "very-hardy"
          },
          {
            "value": "hardy"
          },
          {
            "value": "semi-hardy"
          },
          {
            "value": "tender"
          },
          {
            "value": "very-tender"
          }
        ]
      },
      {
        "name": "method",
        "type": "select",
        "default": "transplant",
        "options": [
          {
            "value": "direct"
          },
          {
            "value": "transplant"
          }
        ]
      },
      {
        "name": "maturityDays",
        "type": "number",
        "default": 70,
        "min": 20,
        "max": 200,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "safeSowingDate",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "indoorStartDate",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "transplantDate",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "harvestWindowStart",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "harvestWindowEnd",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "growingDays",
        "precision": 0,
        "unit": "days"
      },
      {
        "name": "spareDays",
        "precision": 0,
        "unit": "days"
      },
      {
        "name": "note",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
