@snapdragonsnursery/react-components 1.19.3 → 1.19.4
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 +1 -1
- package/src/ChildSearchModal.jsx +49 -5
package/package.json
CHANGED
package/src/ChildSearchModal.jsx
CHANGED
|
@@ -379,12 +379,56 @@ const ChildSearchModal = ({
|
|
|
379
379
|
let displayYears = numericYears;
|
|
380
380
|
let displayMonths = numericMonths;
|
|
381
381
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
|
|
382
|
+
const normaliseMonths = (yearsValue, monthsValue) => {
|
|
383
|
+
if (monthsValue === null || Number.isNaN(monthsValue)) return null;
|
|
384
|
+
if (yearsValue === null || Number.isNaN(yearsValue)) {
|
|
385
|
+
return {
|
|
386
|
+
years: Math.floor(monthsValue / 12),
|
|
387
|
+
months: monthsValue % 12,
|
|
388
|
+
};
|
|
387
389
|
}
|
|
390
|
+
|
|
391
|
+
const expectedMonthsTotal = yearsValue * 12;
|
|
392
|
+
let remainder = monthsValue;
|
|
393
|
+
|
|
394
|
+
if (remainder >= expectedMonthsTotal) {
|
|
395
|
+
remainder = remainder - expectedMonthsTotal;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (remainder >= 12) {
|
|
399
|
+
remainder = remainder % 12;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (remainder < 0) {
|
|
403
|
+
remainder = 0;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return {
|
|
407
|
+
years: yearsValue,
|
|
408
|
+
months: remainder,
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
if (displayMonths !== null && !Number.isNaN(displayMonths)) {
|
|
413
|
+
const normalised = normaliseMonths(
|
|
414
|
+
displayYears ?? null,
|
|
415
|
+
displayMonths ?? null
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
if (normalised) {
|
|
419
|
+
displayYears =
|
|
420
|
+
normalised.years !== undefined ? normalised.years : displayYears;
|
|
421
|
+
displayMonths = normalised.months ?? null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (
|
|
426
|
+
(displayYears === null || Number.isNaN(displayYears)) &&
|
|
427
|
+
displayMonths !== null &&
|
|
428
|
+
displayMonths >= 12
|
|
429
|
+
) {
|
|
430
|
+
displayYears = Math.floor(displayMonths / 12);
|
|
431
|
+
displayMonths = displayMonths % 12;
|
|
388
432
|
}
|
|
389
433
|
|
|
390
434
|
const parts = [];
|