@openmrs/esm-utils
Version:
Helper utilities for OpenMRS
39 lines • 1.89 kB
TypeScript
/** @module @category Utility */
import dayjs from 'dayjs';
/**
* Gets the age of a person as a structured duration object, following NHS Digital guidelines
* (Tables 7 and 8) for which units to include based on the person's age.
*
* @see https://webarchive.nationalarchives.gov.uk/ukgwa/20160921162509mp_/http://systems.digital.nhs.uk/data/cui/uig/patben.pdf
* @param birthDate The birthDate. If null, returns null.
* @param currentDate Optional. If provided, calculates the age at the provided date instead of now.
* @returns A DurationInput object, or null if birthDate is null or unparseable.
*
* @example
* // For infants, returns fine-grained units
* ageAsDuration('2024-07-29', '2024-07-30') // => { hours: 24 }
*
* @example
* // For adults (>= 18), returns years only
* ageAsDuration('2000-01-15', '2024-07-30') // => { years: 24 }
*/
export declare function ageAsDuration(birthDate: dayjs.ConfigType, currentDate?: dayjs.ConfigType): Intl.DurationInput | null;
/**
* Gets a human readable and locale supported representation of a person's age, given their birthDate,
* The representation logic follows the guideline here:
* https://webarchive.nationalarchives.gov.uk/ukgwa/20160921162509mp_/http://systems.digital.nhs.uk/data/cui/uig/patben.pdf
* (See Tables 7 and 8)
*
* @param birthDate The birthDate. If birthDate is null, returns null.
* @param currentDate Optional. If provided, calculates the age of the person at the provided currentDate (instead of now).
* @returns A human-readable string version of the age.
*
* @example
* age('2020-02-29', '2024-07-30') // => '4 yrs, 5 mths'
*
* @example
* // String dates with partial precision are supported
* age('2000', '2024-07-30') // => '24 yrs'
*/
export declare function age(birthDate: dayjs.ConfigType, currentDate?: dayjs.ConfigType): string | null;
//# sourceMappingURL=age-helpers.d.ts.map