Docs/Skills and code/tests/

tests/temporal-normalization.test.js

Code33 lines1.7 KBtests/

import test from "node:test";
import assert from "node:assert/strict";
import { normalizePublishedAt, isRecencyEligible } from "../src/analysis/temporal.js";

test("parses absolute YouTube display dates with Premiered and Published prefixes", () => {
  const premiered = normalizePublishedAt("Premiered Sep 19, 2026", "2026-10-07T17:10:45.123Z");
  assert.equal(premiered.normalized, "2026-09-19T00:00:00.000Z");
  assert.equal(premiered.precision, "exact_day");
  assert.equal(premiered.method, "absolute_display_value");
  const published = normalizePublishedAt("Published on October 3, 2026", "2026-10-07T00:00:00Z");
  assert.equal(published.normalized, "2026-10-03T00:00:00.000Z");
  assert.equal(published.precision, "exact_day");
});

test("parses day-month-year display dates without local timezone conversion", () => {
  assert.equal(normalizePublishedAt("19 Sep 2026", "2026-10-07T00:00:00Z").normalized, "2026-09-19T00:00:00.000Z");
  assert.equal(normalizePublishedAt("2026-09-19", "2026-10-07T00:00:00Z").normalized, "2026-09-19T00:00:00.000Z");
});

test("relative display dates remain estimates and month estimates are not recency eligible", () => {
  const relative = normalizePublishedAt("Premiered 2 months ago", "2026-10-07T17:10:45.123Z");
  assert.equal(relative.precision, "estimated_month");
  assert.equal(relative.method, "relative_to_discovered_at");
  assert.equal(isRecencyEligible(relative.precision), false);
  assert.equal(isRecencyEligible("exact_day"), true);
});

test("unrecognized date text is not silently converted into a date", () => {
  const result = normalizePublishedAt("A while ago", "2026-10-07T00:00:00Z");
  assert.equal(result.normalized, null);
  assert.equal(result.precision, "unknown");
});

Shown as it is in the repository at build time (2026-11-03); the home directory appears as <home>. If this page and the file differ, the file is right. Back to the catalogue.