@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapdragonsnursery/react-components",
3
- "version": "1.19.3",
3
+ "version": "1.19.4",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -379,12 +379,56 @@ const ChildSearchModal = ({
379
379
  let displayYears = numericYears;
380
380
  let displayMonths = numericMonths;
381
381
 
382
- if (displayMonths !== null && displayMonths >= 12) {
383
- const additionalYears = Math.floor(displayMonths / 12);
384
- if (additionalYears > 0) {
385
- displayYears = (displayYears ?? 0) + additionalYears;
386
- displayMonths = displayMonths % 12;
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 = [];