{
  "schemaVersion": 1,
  "slug": "day-of-week-calculator",
  "category": "date-time",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "5c5f5e4cdb004a91716ec466f6444006a230761a12d09edb0c25a86530e164e0",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/day-of-week-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": "n = (D − Jan 1) ÷ 86400000 + 1; r = N − n",
    "vars": [
      [
        "D",
        "Date"
      ],
      [
        "n",
        "Day of year"
      ],
      [
        "N",
        "Days in year"
      ],
      [
        "r",
        "Days remaining"
      ],
      [
        "w",
        "Weekday index (0=Sun)"
      ]
    ],
    "note": "N = 365 or 366 in a leap year; w runs 0 (Sunday) to 6 (Saturday)."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const out=(()=>{if(!/^\\d{4}-\\d{2}-\\d{2}$/.test(date)||Number.isNaN(new Date(date+'T00:00:00Z').getTime())||new Date(date+'T00:00:00Z').toISOString().slice(0,10)!==date)return {weekdayIndex:null,dayOfYear:null,daysInYear:null,daysRemaining:null};const d=new Date(date+'T00:00:00Z'),y=d.getUTCFullYear(),jan1=new Date(d.getTime()),dec31=new Date(d.getTime()),doy=(jan1.setUTCMonth(0,1),dec31.setUTCMonth(11,31),Math.round((d-jan1)/86400000)+1),diy=Math.round((dec31-jan1)/86400000)+1;return {weekdayIndex:d.getUTCDay(),dayOfYear:doy,daysInYear:diy,daysRemaining:diy-doy};})();if(out.__error)return out;return {...out,weekday:Number.isInteger(out.weekdayIndex)?['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][out.weekdayIndex]:null};",
    "inputs": [
      {
        "name": "date",
        "type": "date",
        "default": "@today",
        "step": 1,
        "preserveEmpty": true,
        "requiredValue": true
      }
    ],
    "outputs": [
      {
        "name": "weekday",
        "type": "text",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "weekdayIndex",
        "precision": 0,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "dayOfYear",
        "precision": 0,
        "unit": "days",
        "trimTrailingZeros": true
      },
      {
        "name": "daysInYear",
        "precision": 0,
        "unit": "days",
        "trimTrailingZeros": true
      },
      {
        "name": "daysRemaining",
        "precision": 0,
        "unit": "days",
        "trimTrailingZeros": true
      }
    ],
    "interpret": [
      {
        "max": 1,
        "key": "sunday"
      },
      {
        "max": 2,
        "key": "monday"
      },
      {
        "max": 3,
        "key": "tuesday"
      },
      {
        "max": 4,
        "key": "wednesday"
      },
      {
        "max": 5,
        "key": "thursday"
      },
      {
        "max": 6,
        "key": "friday"
      },
      {
        "max": 7,
        "key": "saturday"
      },
      {
        "max": 1000000000,
        "key": "sunday"
      }
    ]
  }
}
