@openmrs/esm-framework 3.1.15-pre.742 → 3.1.15-pre.751

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.
package/docs/API.md CHANGED
@@ -113,6 +113,7 @@
113
113
  - [DateInput](API.md#dateinput)
114
114
  - [ExtensionSlotProps](API.md#extensionslotprops)
115
115
  - [FormatDateMode](API.md#formatdatemode)
116
+ - [FormatDateOptions](API.md#formatdateoptions)
116
117
  - [KnownOmrsServiceWorkerEvents](API.md#knownomrsserviceworkerevents)
117
118
  - [KnownOmrsServiceWorkerMessages](API.md#knownomrsserviceworkermessages)
118
119
  - [LayoutType](API.md#layouttype)
@@ -402,6 +403,22 @@ ___
402
403
 
403
404
  ___
404
405
 
406
+ ### FormatDateOptions
407
+
408
+ Ƭ **FormatDateOptions**: `Object`
409
+
410
+ #### Type declaration
411
+
412
+ | Name | Type | Description |
413
+ | :------ | :------ | :------ |
414
+ | `time` | `boolean` \| ``"for today"`` | Whether the time should be included in the output always (`true`), never (`false`), or only when the input date is today (`for today`). |
415
+
416
+ #### Defined in
417
+
418
+ [packages/framework/esm-utils/src/omrs-dates.ts:156](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-utils/src/omrs-dates.ts#L156)
419
+
420
+ ___
421
+
405
422
  ### KnownOmrsServiceWorkerEvents
406
423
 
407
424
  Ƭ **KnownOmrsServiceWorkerEvents**: [`NetworkRequestFailedEvent`](interfaces/NetworkRequestFailedEvent.md)
@@ -1706,15 +1723,23 @@ ___
1706
1723
 
1707
1724
  ### formatDate
1708
1725
 
1709
- ▸ **formatDate**(`date`, `mode?`): `string`
1726
+ ▸ **formatDate**(`date`, `mode?`, `options?`): `string`
1710
1727
 
1711
1728
  Formats the input date according to the current locale and the
1712
1729
  given format mode.
1713
1730
 
1714
- `standard`: "13 Dec 2021"
1715
- `no year`: "13 Dec"
1716
- `no day`: "Dec 2021"
1717
- `wide`: "13 — Dec — 2021"
1731
+ - `standard`: "13 Dec 2021"
1732
+ - `no year`: "13 Dec"
1733
+ - `no day`: "Dec 2021"
1734
+ - `wide`: "13 — Dec — 2021"
1735
+
1736
+ Regardless of the mode, if the date is today, then "Today" is produced
1737
+ (in the locale language).
1738
+
1739
+ Can be used to format a date with time, also, by providing `options`.
1740
+ By default, the time is included only when the input date is today.
1741
+ The time is appended with a comma and a space. This agrees with the
1742
+ output of `Date.prototype.toLocaleString` for *most* locales.
1718
1743
 
1719
1744
  #### Parameters
1720
1745
 
@@ -1722,6 +1747,7 @@ given format mode.
1722
1747
  | :------ | :------ | :------ |
1723
1748
  | `date` | `Date` | `undefined` |
1724
1749
  | `mode` | [`FormatDateMode`](API.md#formatdatemode) | `"standard"` |
1750
+ | `options` | [`FormatDateOptions`](API.md#formatdateoptions) | `undefined` |
1725
1751
 
1726
1752
  #### Returns
1727
1753
 
@@ -1729,7 +1755,7 @@ given format mode.
1729
1755
 
1730
1756
  #### Defined in
1731
1757
 
1732
- [packages/framework/esm-utils/src/omrs-dates.ts:165](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-utils/src/omrs-dates.ts#L165)
1758
+ [packages/framework/esm-utils/src/omrs-dates.ts:184](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-utils/src/omrs-dates.ts#L184)
1733
1759
 
1734
1760
  ___
1735
1761
 
@@ -1758,7 +1784,7 @@ output of `Date.prototype.toLocaleString` for *most* locales.
1758
1784
 
1759
1785
  #### Defined in
1760
1786
 
1761
- [packages/framework/esm-utils/src/omrs-dates.ts:227](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-utils/src/omrs-dates.ts#L227)
1787
+ [packages/framework/esm-utils/src/omrs-dates.ts:254](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-utils/src/omrs-dates.ts#L254)
1762
1788
 
1763
1789
  ___
1764
1790
 
@@ -1781,7 +1807,7 @@ Formats the input as a time, according to the current locale.
1781
1807
 
1782
1808
  #### Defined in
1783
1809
 
1784
- [packages/framework/esm-utils/src/omrs-dates.ts:211](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-utils/src/omrs-dates.ts#L211)
1810
+ [packages/framework/esm-utils/src/omrs-dates.ts:238](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-utils/src/omrs-dates.ts#L238)
1785
1811
 
1786
1812
  ___
1787
1813
 
package/mock.tsx CHANGED
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import type {} from "@openmrs/esm-globals";
3
3
  import createStore, { Store } from "unistore";
4
4
  import { never, of } from "rxjs";
5
+ import dayjs from "dayjs";
5
6
 
6
7
  interface StoreEntity {
7
8
  value: Store<any>;
@@ -259,3 +260,28 @@ export const usePagination = jest.fn().mockImplementation(() => ({
259
260
  }));
260
261
 
261
262
  export const useVisitTypes = jest.fn(() => []);
263
+
264
+ export const formatDate = jest.fn((date: Date, mode) => {
265
+ if (!mode || mode == "standard") {
266
+ return dayjs(date).format("DD-MMM-YYYY");
267
+ }
268
+ if (mode == "wide") {
269
+ return dayjs(date).format("DD - MMM - YYYY");
270
+ }
271
+ if (mode == "no day") {
272
+ return dayjs(date).format("MMM YYYY");
273
+ }
274
+ if (mode == "no year") {
275
+ return dayjs(date).format("DD MMM");
276
+ }
277
+ console.warn("Unknown formatDate mode: ", mode);
278
+ return dayjs(date).format("DD-MMM-YYYY");
279
+ });
280
+
281
+ export const formatTime = jest.fn((date: Date) => {
282
+ return dayjs(date).format("HH:mm");
283
+ });
284
+
285
+ export const formatDatetime = jest.fn((date: Date, mode) => {
286
+ return formatDate(date, mode) + " " + formatTime(date);
287
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-framework",
3
- "version": "3.1.15-pre.742",
3
+ "version": "3.1.15-pre.751",
4
4
  "license": "MPL-2.0",
5
5
  "browser": "dist/openmrs-esm-framework.js",
6
6
  "main": "src/index.ts",
@@ -35,17 +35,18 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@openmrs/esm-api": "^3.1.15-pre.742",
39
- "@openmrs/esm-breadcrumbs": "^3.1.15-pre.742",
40
- "@openmrs/esm-config": "^3.1.15-pre.742",
41
- "@openmrs/esm-error-handling": "^3.1.15-pre.742",
42
- "@openmrs/esm-extensions": "^3.1.15-pre.742",
43
- "@openmrs/esm-globals": "^3.1.15-pre.742",
44
- "@openmrs/esm-offline": "^3.1.15-pre.742",
45
- "@openmrs/esm-react-utils": "^3.1.15-pre.742",
46
- "@openmrs/esm-state": "^3.1.15-pre.742",
47
- "@openmrs/esm-styleguide": "^3.1.15-pre.742",
48
- "@openmrs/esm-utils": "^3.1.15-pre.742"
38
+ "@openmrs/esm-api": "^3.1.15-pre.751",
39
+ "@openmrs/esm-breadcrumbs": "^3.1.15-pre.751",
40
+ "@openmrs/esm-config": "^3.1.15-pre.751",
41
+ "@openmrs/esm-error-handling": "^3.1.15-pre.751",
42
+ "@openmrs/esm-extensions": "^3.1.15-pre.751",
43
+ "@openmrs/esm-globals": "^3.1.15-pre.751",
44
+ "@openmrs/esm-offline": "^3.1.15-pre.751",
45
+ "@openmrs/esm-react-utils": "^3.1.15-pre.751",
46
+ "@openmrs/esm-state": "^3.1.15-pre.751",
47
+ "@openmrs/esm-styleguide": "^3.1.15-pre.751",
48
+ "@openmrs/esm-utils": "^3.1.15-pre.751",
49
+ "dayjs": "^1.10.7"
49
50
  },
50
- "gitHead": "46137ce3d7fa9063058317a118324168e12cee11"
51
+ "gitHead": "de47ee691eaa1863dcd18a5b696ba785f502223e"
51
52
  }