@openmrs/esm-framework 9.0.3-pre.4321 → 9.0.3-pre.4342

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 3 files with swc (106.28ms)
1
+ [0] Successfully compiled: 3 files with swc (120.81ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
package/docs/API.md CHANGED
@@ -179,6 +179,7 @@
179
179
  - [useAbortController](functions/useAbortController.md)
180
180
  - [useDebounce](functions/useDebounce.md)
181
181
  - [useOpenmrsSWR](functions/useOpenmrsSWR.md)
182
+ - [ageAsDuration](functions/ageAsDuration.md)
182
183
  - [age](functions/age.md)
183
184
  - [getPatientName](functions/getPatientName.md)
184
185
  - [~~displayName~~](functions/displayName.md)
@@ -284,6 +285,11 @@
284
285
  - [formatDatetime](functions/formatDatetime.md)
285
286
  - [convertToLocaleCalendar](functions/convertToLocaleCalendar.md)
286
287
  - [formatDuration](functions/formatDuration.md)
288
+ - [parseDateInput](functions/parseDateInput.md)
289
+ - [duration](functions/duration.md)
290
+ - [formatDurationBetween](functions/formatDurationBetween.md)
291
+ - [DurationOptions](interfaces/DurationOptions.md)
292
+ - [DurationOptionsWithFormat](interfaces/DurationOptionsWithFormat.md)
287
293
 
288
294
  ## Dynamic Loading
289
295
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  > **age**(`birthDate`, `currentDate`): `null` \| `string`
6
6
 
7
- Defined in: [packages/framework/esm-utils/src/age-helpers.ts:20](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/age-helpers.ts#L20)
7
+ Defined in: [packages/framework/esm-utils/src/age-helpers.ts:83](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/age-helpers.ts#L83)
8
8
 
9
9
  Gets a human readable and locale supported representation of a person's age, given their birthDate,
10
10
  The representation logic follows the guideline here:
@@ -30,3 +30,14 @@ Optional. If provided, calculates the age of the person at the provided currentD
30
30
  `null` \| `string`
31
31
 
32
32
  A human-readable string version of the age.
33
+
34
+ ## Examples
35
+
36
+ ```ts
37
+ age('2020-02-29', '2024-07-30') // => '4 yrs, 5 mths'
38
+ ```
39
+
40
+ ```ts
41
+ // String dates with partial precision are supported
42
+ age('2000', '2024-07-30') // => '24 yrs'
43
+ ```
@@ -0,0 +1,46 @@
1
+ [O3 Framework](../API.md) / ageAsDuration
2
+
3
+ # Function: ageAsDuration()
4
+
5
+ > **ageAsDuration**(`birthDate`, `currentDate`): `null` \| `DurationInput`
6
+
7
+ Defined in: [packages/framework/esm-utils/src/age-helpers.ts:22](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/age-helpers.ts#L22)
8
+
9
+ Gets the age of a person as a structured duration object, following NHS Digital guidelines
10
+ (Tables 7 and 8) for which units to include based on the person's age.
11
+
12
+ ## Parameters
13
+
14
+ ### birthDate
15
+
16
+ `ConfigType`
17
+
18
+ The birthDate. If null, returns null.
19
+
20
+ ### currentDate
21
+
22
+ `ConfigType` = `...`
23
+
24
+ Optional. If provided, calculates the age at the provided date instead of now.
25
+
26
+ ## Returns
27
+
28
+ `null` \| `DurationInput`
29
+
30
+ A DurationInput object, or null if birthDate is null or unparseable.
31
+
32
+ ## See
33
+
34
+ https://webarchive.nationalarchives.gov.uk/ukgwa/20160921162509mp_/http://systems.digital.nhs.uk/data/cui/uig/patben.pdf
35
+
36
+ ## Examples
37
+
38
+ ```ts
39
+ // For infants, returns fine-grained units
40
+ ageAsDuration('2024-07-29', '2024-07-30') // => { hours: 24 }
41
+ ```
42
+
43
+ ```ts
44
+ // For adults (>= 18), returns years only
45
+ ageAsDuration('2000-01-15', '2024-07-30') // => { years: 24 }
46
+ ```
@@ -0,0 +1,60 @@
1
+ [O3 Framework](../API.md) / duration
2
+
3
+ # Function: duration()
4
+
5
+ > **duration**(`startDate`, `endDate`, `options?`): `null` \| `DurationInput`
6
+
7
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:645](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L645)
8
+
9
+ Calculates the duration between two dates as a structured duration object.
10
+
11
+ When called with no options or a single unit string, the unit is auto-selected
12
+ using dayjs relativeTime thresholds:
13
+ - < 45 seconds → seconds
14
+ - < 45 minutes → minutes
15
+ - < 22 hours → hours
16
+ - < 26 days → days
17
+ - < 11 months → months
18
+ - otherwise → years
19
+
20
+ With a [DurationOptions](../interfaces/DurationOptions.md) object, you can override thresholds and/or request
21
+ a multi-unit decomposition via largestUnit/smallestUnit.
22
+
23
+ ## Parameters
24
+
25
+ ### startDate
26
+
27
+ `ConfigType`
28
+
29
+ The start date. If null, returns null.
30
+
31
+ ### endDate
32
+
33
+ `ConfigType` = `...`
34
+
35
+ Optional. Defaults to now.
36
+
37
+ ### options?
38
+
39
+ A unit string for single-unit output, or a DurationOptions object.
40
+
41
+ [`DurationUnit`](../type-aliases/DurationUnit.md) | [`DurationOptions`](../interfaces/DurationOptions.md)
42
+
43
+ ## Returns
44
+
45
+ `null` \| `DurationInput`
46
+
47
+ A DurationInput object, or null if either date is null or unparseable.
48
+
49
+ ## Examples
50
+
51
+ ```ts
52
+ // Auto-selects the appropriate unit
53
+ duration('2022-01-01', '2024-07-30') // => { years: 2 }
54
+ ```
55
+
56
+ ```ts
57
+ // Multi-unit decomposition
58
+ duration('2022-01-01', '2024-07-30', { largestUnit: 'year', smallestUnit: 'day' })
59
+ // => { years: 2, months: 6, days: 29 }
60
+ ```
@@ -0,0 +1,53 @@
1
+ [O3 Framework](../API.md) / formatDurationBetween
2
+
3
+ # Function: formatDurationBetween()
4
+
5
+ > **formatDurationBetween**(`startDate`, `endDate`, `options?`): `null` \| `string`
6
+
7
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:707](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L707)
8
+
9
+ Calculates the duration between two dates and formats it as a locale-aware string.
10
+ Uses the same unit-selection logic as [duration](duration.md) and delegates formatting
11
+ to [formatDuration](formatDuration.md).
12
+
13
+ ## Parameters
14
+
15
+ ### startDate
16
+
17
+ `ConfigType`
18
+
19
+ The start date. If null, returns null.
20
+
21
+ ### endDate
22
+
23
+ `ConfigType` = `...`
24
+
25
+ Optional. Defaults to now.
26
+
27
+ ### options?
28
+
29
+ A unit string for single-unit output, or a [DurationOptionsWithFormat](../interfaces/DurationOptionsWithFormat.md) object.
30
+ The `formatOptions` field is passed to Intl.DurationFormat (defaults to short style).
31
+
32
+ [`DurationUnit`](../type-aliases/DurationUnit.md) | [`DurationOptionsWithFormat`](../interfaces/DurationOptionsWithFormat.md)
33
+
34
+ ## Returns
35
+
36
+ `null` \| `string`
37
+
38
+ A formatted duration string, or null if either date is null or unparseable.
39
+
40
+ ## Examples
41
+
42
+ ```ts
43
+ formatDurationBetween('2022-01-01', '2024-07-30') // => '2 yrs'
44
+ ```
45
+
46
+ ```ts
47
+ // Multi-unit with long-form formatting
48
+ formatDurationBetween('2022-01-01', '2024-07-30', {
49
+ largestUnit: 'year',
50
+ smallestUnit: 'day',
51
+ formatOptions: { style: 'long' },
52
+ }) // => '2 years, 6 months, 29 days'
53
+ ```
@@ -0,0 +1,31 @@
1
+ [O3 Framework](../API.md) / parseDateInput
2
+
3
+ # Function: parseDateInput()
4
+
5
+ > **parseDateInput**(`dateInput`, `referenceDate`): `null` \| `Dayjs`
6
+
7
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:455](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L455)
8
+
9
+ Parses a date input into a dayjs object. String inputs are interpreted using
10
+ any-date-parser with corrections for its month/day representation differences
11
+ with dayjs. Non-string inputs are passed directly to dayjs.
12
+
13
+ ## Parameters
14
+
15
+ ### dateInput
16
+
17
+ `ConfigType`
18
+
19
+ The date to parse.
20
+
21
+ ### referenceDate
22
+
23
+ `Dayjs`
24
+
25
+ Used as the base when resolving partial string dates (e.g., '2000' resolves missing fields from this date).
26
+
27
+ ## Returns
28
+
29
+ `null` \| `Dayjs`
30
+
31
+ A dayjs object, or null if the string could not be parsed.
@@ -0,0 +1,41 @@
1
+ [O3 Framework](../API.md) / DurationOptions
2
+
3
+ # Interface: DurationOptions
4
+
5
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:495](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L495)
6
+
7
+ ## Extended by
8
+
9
+ - [`DurationOptionsWithFormat`](DurationOptionsWithFormat.md)
10
+
11
+ ## Properties
12
+
13
+ ### largestUnit?
14
+
15
+ > `optional` **largestUnit**: `"auto"` \| [`DurationUnit`](../type-aliases/DurationUnit.md)
16
+
17
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:503](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L503)
18
+
19
+ Coarsest unit to include. Accepts 'auto' (default when smallestUnit is set),
20
+ which resolves to the largest non-zero unit or smallestUnit, whichever is greater.
21
+ Mirrors Temporal.Duration.round() behavior.
22
+
23
+ ***
24
+
25
+ ### smallestUnit?
26
+
27
+ > `optional` **smallestUnit**: [`DurationUnit`](../type-aliases/DurationUnit.md)
28
+
29
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:505](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L505)
30
+
31
+ Finest unit to include. Defaults to largestUnit when largestUnit is an explicit unit, giving a single-unit result.
32
+
33
+ ***
34
+
35
+ ### thresholds?
36
+
37
+ > `optional` **thresholds**: `Partial`\<`Record`\<[`DurationUnit`](../type-aliases/DurationUnit.md), `number`\>\>
38
+
39
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:497](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L497)
40
+
41
+ Override auto-selection thresholds. Each value is in the unit's own terms (e.g., seconds: 30 means "use seconds if < 30 seconds").
@@ -0,0 +1,63 @@
1
+ [O3 Framework](../API.md) / DurationOptionsWithFormat
2
+
3
+ # Interface: DurationOptionsWithFormat
4
+
5
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:508](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L508)
6
+
7
+ ## Extends
8
+
9
+ - [`DurationOptions`](DurationOptions.md)
10
+
11
+ ## Properties
12
+
13
+ ### formatOptions?
14
+
15
+ > `optional` **formatOptions**: `Partial`\<`ResolvedDurationFormatOptions`\>
16
+
17
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:510](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L510)
18
+
19
+ Options passed to Intl.DurationFormat. Defaults to { style: 'short', localeMatcher: 'lookup' }.
20
+
21
+ ***
22
+
23
+ ### largestUnit?
24
+
25
+ > `optional` **largestUnit**: `"auto"` \| [`DurationUnit`](../type-aliases/DurationUnit.md)
26
+
27
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:503](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L503)
28
+
29
+ Coarsest unit to include. Accepts 'auto' (default when smallestUnit is set),
30
+ which resolves to the largest non-zero unit or smallestUnit, whichever is greater.
31
+ Mirrors Temporal.Duration.round() behavior.
32
+
33
+ #### Inherited from
34
+
35
+ [`DurationOptions`](DurationOptions.md).[`largestUnit`](DurationOptions.md#largestunit)
36
+
37
+ ***
38
+
39
+ ### smallestUnit?
40
+
41
+ > `optional` **smallestUnit**: [`DurationUnit`](../type-aliases/DurationUnit.md)
42
+
43
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:505](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L505)
44
+
45
+ Finest unit to include. Defaults to largestUnit when largestUnit is an explicit unit, giving a single-unit result.
46
+
47
+ #### Inherited from
48
+
49
+ [`DurationOptions`](DurationOptions.md).[`smallestUnit`](DurationOptions.md#smallestunit)
50
+
51
+ ***
52
+
53
+ ### thresholds?
54
+
55
+ > `optional` **thresholds**: `Partial`\<`Record`\<[`DurationUnit`](../type-aliases/DurationUnit.md), `number`\>\>
56
+
57
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:497](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L497)
58
+
59
+ Override auto-selection thresholds. Each value is in the unit's own terms (e.g., seconds: 30 means "use seconds if < 30 seconds").
60
+
61
+ #### Inherited from
62
+
63
+ [`DurationOptions`](DurationOptions.md).[`thresholds`](DurationOptions.md#thresholds)
@@ -238,7 +238,7 @@ aria-owns.
238
238
 
239
239
  ### aria-current?
240
240
 
241
- > `optional` **aria-current**: `boolean` \| `"date"` \| `"false"` \| `"time"` \| `"true"` \| `"location"` \| `"page"` \| `"step"`
241
+ > `optional` **aria-current**: `boolean` \| `"false"` \| `"time"` \| `"date"` \| `"true"` \| `"location"` \| `"page"` \| `"step"`
242
242
 
243
243
  Defined in: node\_modules/@types/react/index.d.ts:2661
244
244
 
@@ -1187,7 +1187,7 @@ Defined in: node\_modules/@types/react/index.d.ts:2942
1187
1187
 
1188
1188
  ### inputMode?
1189
1189
 
1190
- > `optional` **inputMode**: `"search"` \| `"numeric"` \| `"text"` \| `"none"` \| `"url"` \| `"tel"` \| `"email"` \| `"decimal"`
1190
+ > `optional` **inputMode**: `"numeric"` \| `"search"` \| `"text"` \| `"none"` \| `"url"` \| `"tel"` \| `"email"` \| `"decimal"`
1191
1191
 
1192
1192
  Defined in: node\_modules/@types/react/index.d.ts:2969
1193
1193
 
@@ -0,0 +1,9 @@
1
+ [O3 Framework](../API.md) / DurationUnit
2
+
3
+ # Type Alias: DurationUnit
4
+
5
+ > **DurationUnit** = `DurationUnitPlural` \| `DurationUnitSingular`
6
+
7
+ Defined in: [packages/framework/esm-utils/src/dates/date-util.ts:493](https://github.com/openmrs/openmrs-esm-core/blob/main/packages/framework/esm-utils/src/dates/date-util.ts#L493)
8
+
9
+ Accepts both singular ('year') and plural ('years') forms, mirroring Temporal.Duration.round().
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-framework",
3
- "version": "9.0.3-pre.4321",
3
+ "version": "9.0.3-pre.4342",
4
4
  "license": "MPL-2.0",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
@@ -59,24 +59,24 @@
59
59
  "access": "public"
60
60
  },
61
61
  "dependencies": {
62
- "@openmrs/esm-api": "9.0.3-pre.4321",
63
- "@openmrs/esm-config": "9.0.3-pre.4321",
64
- "@openmrs/esm-context": "9.0.3-pre.4321",
65
- "@openmrs/esm-dynamic-loading": "9.0.3-pre.4321",
66
- "@openmrs/esm-emr-api": "9.0.3-pre.4321",
67
- "@openmrs/esm-error-handling": "9.0.3-pre.4321",
68
- "@openmrs/esm-expression-evaluator": "9.0.3-pre.4321",
69
- "@openmrs/esm-extensions": "9.0.3-pre.4321",
70
- "@openmrs/esm-feature-flags": "9.0.3-pre.4321",
71
- "@openmrs/esm-globals": "9.0.3-pre.4321",
72
- "@openmrs/esm-navigation": "9.0.3-pre.4321",
73
- "@openmrs/esm-offline": "9.0.3-pre.4321",
74
- "@openmrs/esm-react-utils": "9.0.3-pre.4321",
75
- "@openmrs/esm-routes": "9.0.3-pre.4321",
76
- "@openmrs/esm-state": "9.0.3-pre.4321",
77
- "@openmrs/esm-styleguide": "9.0.3-pre.4321",
78
- "@openmrs/esm-translations": "9.0.3-pre.4321",
79
- "@openmrs/esm-utils": "9.0.3-pre.4321"
62
+ "@openmrs/esm-api": "9.0.3-pre.4342",
63
+ "@openmrs/esm-config": "9.0.3-pre.4342",
64
+ "@openmrs/esm-context": "9.0.3-pre.4342",
65
+ "@openmrs/esm-dynamic-loading": "9.0.3-pre.4342",
66
+ "@openmrs/esm-emr-api": "9.0.3-pre.4342",
67
+ "@openmrs/esm-error-handling": "9.0.3-pre.4342",
68
+ "@openmrs/esm-expression-evaluator": "9.0.3-pre.4342",
69
+ "@openmrs/esm-extensions": "9.0.3-pre.4342",
70
+ "@openmrs/esm-feature-flags": "9.0.3-pre.4342",
71
+ "@openmrs/esm-globals": "9.0.3-pre.4342",
72
+ "@openmrs/esm-navigation": "9.0.3-pre.4342",
73
+ "@openmrs/esm-offline": "9.0.3-pre.4342",
74
+ "@openmrs/esm-react-utils": "9.0.3-pre.4342",
75
+ "@openmrs/esm-routes": "9.0.3-pre.4342",
76
+ "@openmrs/esm-state": "9.0.3-pre.4342",
77
+ "@openmrs/esm-styleguide": "9.0.3-pre.4342",
78
+ "@openmrs/esm-translations": "9.0.3-pre.4342",
79
+ "@openmrs/esm-utils": "9.0.3-pre.4342"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "dayjs": "1.x",
@@ -89,7 +89,7 @@
89
89
  "swr": "2.x"
90
90
  },
91
91
  "devDependencies": {
92
- "@openmrs/typedoc-plugin-file-categories": "9.0.3-pre.4321",
92
+ "@openmrs/typedoc-plugin-file-categories": "9.0.3-pre.4342",
93
93
  "@swc/cli": "0.8.0",
94
94
  "@swc/core": "1.15.18",
95
95
  "@vitest/coverage-v8": "^4.0.18",