@ukhomeoffice/cop-react-form-renderer 4.18.0 → 4.19.0
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.
|
@@ -17,19 +17,21 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
// Local imports
|
|
18
18
|
_dayjs.default.extend(_customParseFormat.default);
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* Checks that a date is after either:
|
|
21
|
+
* - A specified, fixed date.
|
|
22
|
+
* Or
|
|
23
|
+
* - An offset to the current date in days/months/years.
|
|
24
|
+
*
|
|
24
25
|
* @param {string} date - date string in a valid date format e.g. DD-MM-YYYY
|
|
26
|
+
* @param {string} config.date - fixed date string that date must be after, in the format DD-MM-YYYY
|
|
25
27
|
* @param {string} config.unit - day, month or year
|
|
26
28
|
* @param {number} config.value - number of the unit to be after
|
|
27
|
-
* @returns false if date is
|
|
29
|
+
* @returns false if date is not after the given date/offset or true if it is.
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
var mustBeAfter = function mustBeAfter(date, config) {
|
|
32
|
-
var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
|
|
34
|
+
var dateToCompare = config.date ? (0, _dayjs.default)((0, _utils.formatString)(config.date), _utils.DATE_FORMAT) : (0, _dayjs.default)().add(config.value, config.unit);
|
|
33
35
|
return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isAfter(dateToCompare);
|
|
34
36
|
};
|
|
35
37
|
|
|
@@ -84,7 +84,7 @@ describe('utils', function () {
|
|
|
84
84
|
});
|
|
85
85
|
expect(result).toEqual(true);
|
|
86
86
|
});
|
|
87
|
-
test('should return
|
|
87
|
+
test('should return false given a date before the given number of days in the future', function () {
|
|
88
88
|
var date = (0, _dayjs.default)().add(250, 'day').format(_utils.DATE_FORMAT);
|
|
89
89
|
var result = (0, _mustBeAfter.default)(date, {
|
|
90
90
|
value: 275,
|
|
@@ -92,6 +92,20 @@ describe('utils', function () {
|
|
|
92
92
|
});
|
|
93
93
|
expect(result).toEqual(false);
|
|
94
94
|
});
|
|
95
|
+
test('should return false given a date before the specified fixed date', function () {
|
|
96
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
97
|
+
var result = (0, _mustBeAfter.default)(date, {
|
|
98
|
+
date: '01-01-5000'
|
|
99
|
+
});
|
|
100
|
+
expect(result).toEqual(false);
|
|
101
|
+
});
|
|
102
|
+
test('should return true given a date after the specified fixed date', function () {
|
|
103
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
104
|
+
var result = (0, _mustBeAfter.default)(date, {
|
|
105
|
+
date: '01-01-2000'
|
|
106
|
+
});
|
|
107
|
+
expect(result).toEqual(true);
|
|
108
|
+
});
|
|
95
109
|
});
|
|
96
110
|
});
|
|
97
111
|
});
|
|
@@ -17,17 +17,21 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
17
|
// Local imports
|
|
18
18
|
_dayjs.default.extend(_customParseFormat.default);
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Checks that a date is before either:
|
|
21
|
+
* - A specified, fixed date.
|
|
22
|
+
* Or
|
|
23
|
+
* - An offset to the current date in days/months/years.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} date - date string in a valid date format e.g. DD-MM-YYYY
|
|
26
|
+
* @param {string} config.date - fixed date string that date must be before, in the format DD-MM-YYYY
|
|
23
27
|
* @param {string} config.unit - day, month or year
|
|
24
28
|
* @param {number} config.value - number of the unit to be before
|
|
25
|
-
* @returns
|
|
29
|
+
* @returns false if date is not before the given date/offset or true if it is.
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
var mustBeBefore = function mustBeBefore(date, config) {
|
|
30
|
-
var dateToCompare = (0, _dayjs.default)().add(config.value, config.unit);
|
|
34
|
+
var dateToCompare = config.date ? (0, _dayjs.default)((0, _utils.formatString)(config.date), _utils.DATE_FORMAT) : (0, _dayjs.default)().add(config.value, config.unit);
|
|
31
35
|
return (0, _dayjs.default)((0, _utils.formatString)(date), _utils.DATE_FORMAT).isBefore(dateToCompare);
|
|
32
36
|
};
|
|
33
37
|
|
|
@@ -60,6 +60,20 @@ describe('utils', function () {
|
|
|
60
60
|
});
|
|
61
61
|
expect(result).toEqual(false);
|
|
62
62
|
});
|
|
63
|
+
test('should return false given a date after the specified fixed date', function () {
|
|
64
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
65
|
+
var result = (0, _mustBeBefore.default)(date, {
|
|
66
|
+
date: '01-01-2000'
|
|
67
|
+
});
|
|
68
|
+
expect(result).toEqual(false);
|
|
69
|
+
});
|
|
70
|
+
test('should return true given a date before the specified fixed date', function () {
|
|
71
|
+
var date = (0, _dayjs.default)().format(_utils.DATE_FORMAT);
|
|
72
|
+
var result = (0, _mustBeBefore.default)(date, {
|
|
73
|
+
date: '01-01-5000'
|
|
74
|
+
});
|
|
75
|
+
expect(result).toEqual(true);
|
|
76
|
+
});
|
|
63
77
|
});
|
|
64
78
|
});
|
|
65
79
|
});
|