@openmrs/esm-utils 6.2.1-pre.2760 → 6.2.1-pre.2762
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/.turbo/turbo-build.log +4 -4
- package/dist/openmrs-esm-utils.js +1 -1
- package/dist/openmrs-esm-utils.js.map +1 -1
- package/package.json +2 -2
- package/src/age-helpers.ts +1 -2
- package/src/{omrs-dates.test.ts → dates/date-util.test.ts} +8 -2
- package/src/{omrs-dates.ts → dates/date-util.ts} +1 -55
- package/src/dates/index.ts +1 -0
- package/src/get-locale.ts +14 -0
- package/src/index.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-utils",
|
|
3
|
-
"version": "6.2.1-pre.
|
|
3
|
+
"version": "6.2.1-pre.2762",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Helper utilities for OpenMRS",
|
|
6
6
|
"browser": "dist/openmrs-esm-utils.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@openmrs/esm-globals": "6.2.1-pre.
|
|
42
|
+
"@openmrs/esm-globals": "6.2.1-pre.2762",
|
|
43
43
|
"@types/semver": "^7.3.4",
|
|
44
44
|
"dayjs": "^1.10.4",
|
|
45
45
|
"rxjs": "^6.5.3"
|
package/src/age-helpers.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/** @module @category Utility */
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import { getLocale } from './omrs-dates';
|
|
4
3
|
import { DurationFormat } from '@formatjs/intl-durationformat';
|
|
5
4
|
import { type DurationFormatOptions, type DurationInput } from '@formatjs/intl-durationformat/src/types';
|
|
6
|
-
|
|
5
|
+
import { getLocale } from './get-locale';
|
|
7
6
|
/**
|
|
8
7
|
* Gets a human readable and locale supported representation of a person's age, given their birthDate,
|
|
9
8
|
* The representation logic follows the guideline here:
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
toOmrsIsoString,
|
|
3
|
+
toDateObjectStrict,
|
|
4
|
+
isOmrsDateStrict,
|
|
5
|
+
formatDate,
|
|
6
|
+
formatDatetime,
|
|
7
|
+
formatTime,
|
|
8
|
+
} from './date-util';
|
|
2
9
|
import dayjs from 'dayjs';
|
|
3
10
|
import timezoneMock from 'timezone-mock';
|
|
4
|
-
import { formatDate, formatDatetime, formatTime } from '.';
|
|
5
11
|
import type { i18n } from 'i18next';
|
|
6
12
|
|
|
7
13
|
window.i18next = { language: 'en' } as i18n;
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import dayjs from 'dayjs';
|
|
14
14
|
import utc from 'dayjs/plugin/utc';
|
|
15
15
|
import isToday from 'dayjs/plugin/isToday';
|
|
16
|
+
import { getLocale } from '@openmrs/esm-utils';
|
|
16
17
|
|
|
17
18
|
dayjs.extend(utc);
|
|
18
19
|
dayjs.extend(isToday);
|
|
@@ -89,46 +90,6 @@ export function toOmrsIsoString(date: DateInput, toUTC = false): string {
|
|
|
89
90
|
return d.format(isoFormat);
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
/**
|
|
93
|
-
* @deprecated use `formatTime`
|
|
94
|
-
* Formats the input as a time string using the format "HH:mm".
|
|
95
|
-
*/
|
|
96
|
-
export function toOmrsTimeString24(date: DateInput) {
|
|
97
|
-
return dayjs(date).format('HH:mm');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @deprecated use `formatTime`
|
|
102
|
-
* Formats the input as a time string using the format "HH:mm A".
|
|
103
|
-
*/
|
|
104
|
-
export function toOmrsTimeString(date: DateInput) {
|
|
105
|
-
return dayjs.utc(date).format('HH:mm A');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* @deprecated use `formatDate(date, "wide")`
|
|
110
|
-
* Formats the input as a date string using the format "DD - MMM - YYYY".
|
|
111
|
-
*/
|
|
112
|
-
export function toOmrsDayDateFormat(date: DateInput) {
|
|
113
|
-
return toOmrsDateFormat(date, 'DD - MMM - YYYY');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @deprecated use `formatDate(date, "no year")`
|
|
118
|
-
* Formats the input as a date string using the format "DD-MMM".
|
|
119
|
-
*/
|
|
120
|
-
export function toOmrsYearlessDateFormat(date: DateInput) {
|
|
121
|
-
return toOmrsDateFormat(date, 'DD-MMM');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @deprecated use `formatDate(date)`
|
|
126
|
-
* Formats the input as a date string. By default the format "YYYY-MMM-DD" is used.
|
|
127
|
-
*/
|
|
128
|
-
export function toOmrsDateFormat(date: DateInput, format = 'YYYY-MMM-DD') {
|
|
129
|
-
return dayjs(date).format(format);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
93
|
/**
|
|
133
94
|
* Utility function to parse an arbitrary string into a date.
|
|
134
95
|
* Uses `dayjs(dateString)`.
|
|
@@ -382,21 +343,6 @@ export function formatDatetime(date: Date, options?: Partial<Omit<FormatDateOpti
|
|
|
382
343
|
return formatDate(date, { ...options, time: true });
|
|
383
344
|
}
|
|
384
345
|
|
|
385
|
-
/**
|
|
386
|
-
* Returns the current locale of the application.
|
|
387
|
-
* @returns string
|
|
388
|
-
*/
|
|
389
|
-
export function getLocale() {
|
|
390
|
-
let language = window.i18next.language;
|
|
391
|
-
language = language.replace('_', '-'); // just in case
|
|
392
|
-
// hack for `ht` until https://unicode-org.atlassian.net/browse/CLDR-14956 is fixed
|
|
393
|
-
if (language === 'ht') {
|
|
394
|
-
language = 'fr-HT';
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
return language;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
346
|
/**
|
|
401
347
|
* Converts a calendar date to the equivalent locale calendar date.
|
|
402
348
|
* @returns CalendarDate
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './date-util';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current locale of the application.
|
|
3
|
+
* @returns string
|
|
4
|
+
*/
|
|
5
|
+
export function getLocale() {
|
|
6
|
+
let language = window.i18next.language;
|
|
7
|
+
language = language.replace('_', '-'); // just in case
|
|
8
|
+
// Hack for `ht` until all browsers update their unicode support with ht to fr mapping.
|
|
9
|
+
// See https://unicode-org.atlassian.net/browse/CLDR-14956
|
|
10
|
+
if (language === 'ht') {
|
|
11
|
+
language = 'fr-HT';
|
|
12
|
+
}
|
|
13
|
+
return language;
|
|
14
|
+
}
|
package/src/index.ts
CHANGED