const URL_DATE_RE = /\/(\d{4})\/(\d{2})(?:\/(\d{2}))?(?:\/|$|[?#])/;
function pad2(n) {
  return n < 10 ? `0${n}` : String(n);
}
function inferFromUrl(url) {
  try {
    const u = new URL(url);
    const m = u.pathname.match(URL_DATE_RE);
    if (!m) return void 0;
    const year = Number(m[1]);
    const month = Number(m[2]);
    const day = m[3] !== void 0 ? Number(m[3]) : 1;
    if (!Number.isFinite(year) || !Number.isFinite(month)) return void 0;
    if (year < 1990 || year > 2099 || month < 1 || month > 12) return void 0;
    if (day < 1 || day > 31) return void 0;
    return `${year}-${pad2(month)}-${pad2(day)}`;
  } catch {
    return void 0;
  }
}
function computeFreshnessSignal(url, publishedDate) {
  if (publishedDate) {
    return {
      published_date: publishedDate,
      inferred: false,
      confidence: "extracted"
    };
  }
  const urlDate = inferFromUrl(url);
  if (urlDate) {
    return {
      published_date: urlDate,
      inferred: true,
      confidence: "inferred-url"
    };
  }
  return void 0;
}
export {
  computeFreshnessSignal
};
//# sourceMappingURL=freshness.js.map