@openmrs/esm-utils 6.2.1-pre.2807 → 6.2.1-pre.2812

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-utils",
3
- "version": "6.2.1-pre.2807",
3
+ "version": "6.2.1-pre.2812",
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.2807",
42
+ "@openmrs/esm-globals": "6.2.1-pre.2812",
43
43
  "@types/lodash-es": "^4.17.12",
44
44
  "@types/semver": "^7.3.4",
45
45
  "dayjs": "^1.10.4",
@@ -6,6 +6,7 @@ import {
6
6
  formatDatetime,
7
7
  formatTime,
8
8
  registerDefaultCalendar,
9
+ formatPartialDate,
9
10
  } from './date-util';
10
11
  import dayjs from 'dayjs';
11
12
  import timezoneMock from 'timezone-mock';
@@ -79,6 +80,16 @@ describe('Openmrs Dates', () => {
79
80
  expect(formatDate(testDate, { mode: 'wide' })).toMatch(/09\s—\sдек\.\s—\s2021\sг\./);
80
81
  });
81
82
 
83
+ it('formats partial dates', () => {
84
+ timezoneMock.register('UTC');
85
+ window.i18next.language = 'en';
86
+ expect(formatPartialDate('2021')).toEqual('2021');
87
+ expect(formatPartialDate('2021-04')).toEqual('Apr 2021');
88
+ expect(formatPartialDate('2021-04-09')).toEqual('09-Apr-2021');
89
+ expect(formatPartialDate('2021-01-01')).toEqual('01-Jan-2021');
90
+ expect(formatPartialDate('2021-12')).toEqual('Dec 2021');
91
+ });
92
+
82
93
  it('formats dates with respect to the active calendar', () => {
83
94
  registerDefaultCalendar('am', 'ethiopic');
84
95
 
@@ -15,8 +15,7 @@ import dayjs from 'dayjs';
15
15
  import isToday from 'dayjs/plugin/isToday';
16
16
  import objectSupport from 'dayjs/plugin/objectSupport';
17
17
  import utc from 'dayjs/plugin/utc';
18
- import type { i18n } from 'i18next';
19
- import { omit } from 'lodash-es';
18
+ import { isNil, omit } from 'lodash-es';
20
19
 
21
20
  dayjs.extend(isToday);
22
21
  dayjs.extend(utc);
@@ -242,7 +241,7 @@ export function formatPartialDate(dateString: string, options: Partial<FormatDat
242
241
  }
243
242
 
244
243
  // hack here but any date interprets 2000-01, etc. as yyyy-dd rather than yyyy-mm
245
- if (parsed.day && !parsed.month) {
244
+ if (!isNil(parsed.day) && isNil(parsed.month)) {
246
245
  parsed = Object.assign({}, omit(parsed, 'day'), { month: parsed.day });
247
246
  }
248
247
 
@@ -258,15 +257,15 @@ export function formatPartialDate(dateString: string, options: Partial<FormatDat
258
257
 
259
258
  const date = dayjs().set(parsed).toDate();
260
259
 
261
- if (!parsed.year) {
260
+ if (isNil(parsed.year)) {
262
261
  options.year = false;
263
262
  }
264
263
 
265
- if (!parsed.month) {
264
+ if (isNil(parsed.month)) {
266
265
  options.month = false;
267
266
  }
268
267
 
269
- if (!parsed.date) {
268
+ if (isNil(parsed.date)) {
270
269
  options.day = false;
271
270
  }
272
271