Skip to main content
Version: v0.0.8

Function: generalizeDate()

generalizeDate(value): GeneralizeOutcome | null

Generalize a date to its year (§164.514(b)(2)(i)(C)). Accepts common encodings - ISO YYYY-MM-DD / YYYY-MM-DDThh:mm:ss, HL7 YYYYMMDD - anything beginning with a plausible four-digit year. Fails closed (null) when no year can be extracted; the retained year is a residual.

Parameters

value

string

The date value to generalize.

Returns

GeneralizeOutcome | null

The { value: year, residual: true } outcome, or null if no year is present.

Example

import { generalizeDate } from "@cosyte/deid";

generalizeDate("2019-03-14")?.value; // => "2019"
generalizeDate("not-a-date"); // => null