{
  "schemaVersion": 1,
  "slug": "countdown-calculator",
  "category": "date-time",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "a65f2bd44643853095a85a6cf6493c2dc9362fcf15b066bee0eb5814fb212423",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/countdown-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": "Δ = (T − S)/86400000; counted = sign(Δ) × (|Δ| + inclusive); weeks = counted/7; months ≈ counted/30.4375",
    "vars": [],
    "note": "Months are an average conversion using 30.4375 days, not calendar months. Holidays are not removed."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "try{if(false)throw new Error('inputError');const calculate=function(){const h=(function context() {\n  const DAY=86400000;\n  const own=(o,k)=>Object.prototype.hasOwnProperty.call(o,k);\n  const fail=()=>{throw new Error('inputError');};\n  const num=(v,min=-Infinity,max=Infinity,integer=false)=>{\n    if(!Number.isFinite(v)||v<min||v>max||(integer&&!Number.isInteger(v)))fail();return v;\n  };\n  const choice=(v,values)=>{if(!values.includes(v))fail();return v;};\n  const date=s=>{if(typeof s!=='string'||!/^\\d{4}-\\d{2}-\\d{2}$/.test(s)||s.startsWith('0000'))fail();const d=new Date(s+'T00:00:00Z');if(!Number.isFinite(+d)||d.toISOString().slice(0,10)!==s)fail();return d;};\n  const iso=d=>{if(!Number.isFinite(+d)||d.getUTCFullYear()<1||d.getUTCFullYear()>9999)fail();return d.toISOString().slice(0,10);};\n  const shift=(d,n)=>{const r=new Date(+d+n*DAY);iso(r);return r;};\n  const month=(d,n)=>{const r=new Date(+d);r.setUTCDate(1);r.setUTCMonth(r.getUTCMonth()+n);const end=new Date(+r);end.setUTCMonth(end.getUTCMonth()+1,0);r.setUTCDate(Math.min(d.getUTCDate(),end.getUTCDate()));iso(r);return r;};\n  const weekdays=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];\n  const work=(d,count)=>{let n=Math.floor(count/7)*5;for(let k=0;k<count%7;k++){const w=(d.getUTCDay()+k)%7;if(w!==0&&w!==6)n++;}return n;};\n  const wholeMonths=(a,b)=>{let n=(b.getUTCFullYear()-a.getUTCFullYear())*12+b.getUTCMonth()-a.getUTCMonth();if(n>=0&&+month(a,n)>+b)n--;if(n<0&&+month(a,n)<+b)n++;return n;};\n  return {DAY,own,fail,num,choice,date,iso,shift,month,weekdays,work,wholeMonths};\n})();const result=(function(v,h){\n    const {date,choice,DAY,shift,work,weekdays}=h,a=date(v.fromDate),b=date(v.targetDate);choice(v.includeEndDay,['yes','no']);\n    const delta=Math.round((b-a)/DAY),span=Math.abs(delta),count=span+(v.includeEndDay==='yes'?1:0),sign=delta<0?-1:1;\n    let first=delta<0?b:a;if(v.includeEndDay==='no'&&delta>0)first=shift(a,1);\n    const wd=work(first,count),days=sign*count;\n    return {days,weeks:days/7,months:days/30.4375,hours:days*24,includingToday:sign*(span+1),weekdays:wd,weekendDays:count-wd,targetWeekday:weekdays[b.getUTCDay()],elapsed:delta===0?'Today':delta>0?'Still to come':'Already passed'};\n  })({\"targetDate\":(targetDate),\"fromDate\":(fromDate),\"includeEndDay\":(includeEndDay)},h);return result;};const out=calculate();return Object.fromEntries([\"days\",\"weeks\",\"months\",\"hours\",\"includingToday\",\"weekdays\",\"weekendDays\",\"targetWeekday\",\"elapsed\"].map(k=>[k,out[k]??null]).concat(Object.entries(out).filter(([k])=>k.startsWith('__'))));}catch(error){return Object.assign(Object.fromEntries([\"days\",\"weeks\",\"months\",\"hours\",\"includingToday\",\"weekdays\",\"weekendDays\",\"targetWeekday\",\"elapsed\"].map(k=>[k,null])),{__error:error.message==='openingsExceedWallArea'?'openingsExceedWallArea':'inputError'});}",
    "inputs": [
      {
        "name": "targetDate",
        "type": "date",
        "default": "@today+3m",
        "step": 1,
        "preserveEmpty": true,
        "requiredValue": true
      },
      {
        "type": "date",
        "default": "@today",
        "preserveEmpty": true,
        "advanced": true,
        "name": "fromDate",
        "requiredValue": true
      },
      {
        "type": "select",
        "default": "no",
        "options": [
          {
            "value": "no"
          },
          {
            "value": "yes"
          }
        ],
        "advanced": true,
        "name": "includeEndDay"
      }
    ],
    "outputs": [
      {
        "name": "days",
        "precision": 0,
        "unit": "days",
        "notation": "auto"
      },
      {
        "name": "weeks",
        "precision": 1,
        "unit": "weeks",
        "notation": "auto"
      },
      {
        "name": "months",
        "precision": 1,
        "unit": "months",
        "notation": "auto"
      },
      {
        "name": "hours",
        "precision": 0,
        "unit": "h",
        "notation": "auto"
      },
      {
        "name": "includingToday",
        "precision": 0,
        "unit": "days",
        "notation": "auto"
      },
      {
        "name": "weekdays",
        "precision": 0,
        "unit": "days",
        "notation": "auto"
      },
      {
        "name": "weekendDays",
        "precision": 0,
        "unit": "days",
        "notation": "auto"
      },
      {
        "name": "targetWeekday",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "elapsed",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
