@openmrs/esm-form-engine-lib 3.0.0-pre.1607 → 3.0.0-pre.1614

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-form-engine-lib",
3
- "version": "3.0.0-pre.1607",
3
+ "version": "3.0.0-pre.1614",
4
4
  "description": "React Form Engine for O3",
5
5
  "browser": "dist/openmrs-esm-form-engine-lib.js",
6
6
  "main": "src/index.ts",
@@ -171,7 +171,7 @@ describe('CommonExpressionHelpers', () => {
171
171
  it('should return the correct number of months on ART', () => {
172
172
  const artStartDate = new Date('2020-01-01');
173
173
  const today = new Date();
174
- const monthsOnART = Math.floor((today.getTime() - artStartDate.getTime()) / (1000 * 60 * 60 * 24 * 30));
174
+ const monthsOnART = dayjs(today).diff(dayjs(artStartDate), 'months');
175
175
  expect(helpers.calcMonthsOnART(artStartDate)).toBe(monthsOnART);
176
176
  });
177
177
 
@@ -118,19 +118,22 @@ export class CommonExpressionHelpers {
118
118
  };
119
119
 
120
120
  calcMonthsOnART = (artStartDate: Date) => {
121
- if (artStartDate == null) return null;
121
+ if (artStartDate == null) {
122
+ return null;
123
+ }
122
124
 
123
125
  if (!(artStartDate instanceof Date)) {
124
126
  throw new Error('DateFormatException: value passed is not a valid date');
125
127
  }
126
128
 
127
- let today = new Date();
128
- let resultMonthsOnART: number;
129
- let artInDays = Math.round((today.getTime() - artStartDate.getTime?.()) / 86400000);
130
- if (artStartDate && artInDays >= 30) {
131
- resultMonthsOnART = Math.floor(artInDays / 30);
129
+ const today = new Date();
130
+ const artInDays = Math.round((today.getTime() - artStartDate.getTime()) / 86400000);
131
+
132
+ if (artInDays < 30) {
133
+ return 0;
132
134
  }
133
- return artStartDate ? resultMonthsOnART : null;
135
+
136
+ return dayjs(today).diff(artStartDate, 'month');
134
137
  };
135
138
 
136
139
  calcViralLoadStatus = (viralLoadCount: number) => {