birth_dates
birth_dates
¶
Shared parsing and rendering for structured and free-text birth dates.
Functions:
| Name | Description |
|---|---|
birth_date_is_supported |
Return whether |
shift_birth_date |
Shift a parseable birth date by a small nonzero number of days, or return |
random_birth_date |
Return a random birth date between 1930 and 2010, written with |
birth_date_is_supported(value)
¶
Return whether value contains one complete, deterministic date.
shift_birth_date(original, pattern, rng, *, locale)
¶
Shift a parseable birth date by a small nonzero number of days, or return None.
The shift is drawn from a normal distribution with a 30-day standard deviation and never exceeds 180 days, so the original date does not survive while ages and the column's distribution stay close to the original.
The plan's pattern only has to cover 99% of a column, so each value is tried
against the pattern first, then ISO 8601, common numeric formats, and strict
complete natural-language dates. Numeric formats are tried month first for
en_US and day first for every other locale. Relative expressions such as "yesterday"
or an age such as "30 years" are not fixed dates and are not parsed. The replacement uses the pattern when one
is configured, else the numeric format that parsed, else ISO 8601. None
means the value could not be parsed; the caller then generates a random
birth date so the original never survives.
A date within the shift range of either end of the calendar, such as the
placeholders 0001-01-01 and 9999-12-31, is returned unchanged: nobody
is born on it, so it keeps its meaning as a placeholder.
Example
With pattern "%m/%d/%Y", "02/14/1990" shifts to a date such as
"11/03/1989", "1990-02-14" also shifts and is written as
%m/%d/%Y, and "08/2010" returns None.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/birth_dates.py
random_birth_date(pattern, rng)
¶
Return a random birth date between 1930 and 2010, written with pattern or as ISO 8601.
The date is taken at midnight UTC, so a pattern with %z or %Z still renders a timezone and the
value parses with that pattern.
Example
With pattern "%Y-%m-%d %z", the result looks like "1974-06-02 +0000".