{
  "schemaVersion": 1,
  "slug": "baby-age-calculator",
  "category": "date-time",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "e4beb1187f39f07221441d8cf79fe93c82a6c9517d5769b46be39534bb2f8d0a",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/baby-age-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 = max(round((t − t₀) ÷ 86,400,000), 0); W = ⌊D ÷ 7⌋",
    "vars": [
      [
        "t₀",
        "Birth date"
      ],
      [
        "t",
        "Current date, UTC midnight"
      ],
      [
        "D",
        "Age in days"
      ],
      [
        "W",
        "Completed weeks"
      ]
    ],
    "note": "Months are counted by calendar-month difference; corrected age subtracts prematurity days: (D − early days) ÷ 7."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-12",
    "sources": [
      {
        "name": "American Academy of Pediatrics — Corrected age for preemies",
        "url": "https://www.healthychildren.org/English/ages-stages/baby/preemie/Pages/Corrected-Age-For-Preemies.aspx"
      }
    ],
    "referenceRole": "context",
    "implementationHash": "e4beb1187f39f07221441d8cf79fe93c82a6c9517d5769b46be39534bb2f8d0a",
    "basis": "D = max(round((t − t₀) ÷ 86,400,000), 0); W = ⌊D ÷ 7⌋",
    "limitations": "The references provide context and limitations. They do not validate this page’s illustrative multipliers, lookup values or predictions."
  },
  "contract": {
    "compute": "const validDate = (s) => { const m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(String(s)); if (!m) return false; const d = new Date(String(s) + 'T00:00:00Z'); return Number.isFinite(d.getTime()) && d.getUTCFullYear() === +m[1] && d.getUTCMonth()+1 === +m[2] && d.getUTCDate() === +m[3]; };\nif (!validDate(birthDate) || !validDate(dueDate || birthDate)) return { totalDays: null, weeksOld: null, monthsOld: null, ageText: null, correctedWeeks: null, __error: 'inputError' };\nconst DAY=86400000; const b=new Date(birthDate+'T00:00:00Z'); const due=new Date((dueDate||birthDate)+'T00:00:00Z'); const now=new Date(); now.setUTCHours(0,0,0,0); if (b > now || due < b) return { totalDays: null, weeksOld: null, monthsOld: null, ageText: null, correctedWeeks: null, __error: 'invalidBabyDates' }; const days = Math.round((now-b)/DAY); const weeks = Math.floor(days/7); const rem = days % 7; const months = (now.getUTCFullYear()-b.getUTCFullYear())*12 + (now.getUTCMonth()-b.getUTCMonth()) - (now.getUTCDate() < b.getUTCDate() ? 1 : 0); const prematurity = Math.round((due-b)/DAY); const corrected = Math.max((days - prematurity)/7, 0); return { totalDays: days, weeksOld: weeks, monthsOld: Math.max(months,0), ageText: weeks + ' weeks ' + rem + ' days', correctedWeeks: corrected };",
    "inputs": [
      {
        "name": "birthDate",
        "type": "date",
        "default": "@today-6m",
        "step": 1
      },
      {
        "name": "dueDate",
        "type": "date",
        "default": "@today-6m",
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "totalDays",
        "precision": 0,
        "unit": "days"
      },
      {
        "name": "weeksOld",
        "precision": 1,
        "unit": "weeks"
      },
      {
        "name": "monthsOld",
        "precision": 2,
        "unit": "months"
      },
      {
        "name": "ageText",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "correctedWeeks",
        "precision": 1,
        "unit": "weeks"
      }
    ],
    "interpret": null
  }
}
