@ibragim-dev-org/ui-forge-library 1.3.3 → 1.3.5
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.
|
@@ -3401,8 +3401,8 @@ class UIInputDateDirective extends UiInputDirective {
|
|
|
3401
3401
|
$isRangeSelection = input(false, ...(ngDevMode ? [{ debugName: "$isRangeSelection" }] : []));
|
|
3402
3402
|
$dateFormat = input(undefined, ...(ngDevMode ? [{ debugName: "$dateFormat" }] : []));
|
|
3403
3403
|
$dividePattern = input('/', ...(ngDevMode ? [{ debugName: "$dividePattern" }] : []));
|
|
3404
|
-
$minDate = input(
|
|
3405
|
-
$maxDate = input(
|
|
3404
|
+
$minDate = input(new Date(new Date().getFullYear() - 100, 0, 1), ...(ngDevMode ? [{ debugName: "$minDate" }] : []));
|
|
3405
|
+
$maxDate = input(new Date(new Date().getFullYear() + 20, 11, 31), ...(ngDevMode ? [{ debugName: "$maxDate" }] : []));
|
|
3406
3406
|
$inputElement = viewChild('input', ...(ngDevMode ? [{ debugName: "$inputElement" }] : []));
|
|
3407
3407
|
setDate(date) {
|
|
3408
3408
|
const newDate = this.formatDate(date);
|
|
@@ -3443,9 +3443,12 @@ class UIInputDateDirective extends UiInputDirective {
|
|
|
3443
3443
|
const oldPatternCount = (oldValue.match(patternRegex) || []).length;
|
|
3444
3444
|
const newPatternCount = (newValue.match(patternRegex) || []).length;
|
|
3445
3445
|
const patternAdded = newPatternCount > oldPatternCount;
|
|
3446
|
+
const oldHasRangeSep = oldValue.includes(' - ');
|
|
3447
|
+
const newHasRangeSep = newValue.includes(' - ');
|
|
3448
|
+
const rangeSepAdded = !oldHasRangeSep && newHasRangeSep;
|
|
3446
3449
|
super.onInput(newValue);
|
|
3447
3450
|
inputElement.value = newValue;
|
|
3448
|
-
if (patternAdded) {
|
|
3451
|
+
if (patternAdded || rangeSepAdded) {
|
|
3449
3452
|
inputElement.setSelectionRange(newValue.length, newValue.length);
|
|
3450
3453
|
}
|
|
3451
3454
|
else {
|
|
@@ -3471,14 +3474,65 @@ class UIInputDateDirective extends UiInputDirective {
|
|
|
3471
3474
|
}
|
|
3472
3475
|
return res;
|
|
3473
3476
|
};
|
|
3477
|
+
const correctDateString = (str) => {
|
|
3478
|
+
if (str.length < 8)
|
|
3479
|
+
return formatSingle(str);
|
|
3480
|
+
let dayStr = str.substring(0, 2);
|
|
3481
|
+
let monthStr = str.substring(2, 4);
|
|
3482
|
+
let yearStr = str.substring(4, 8);
|
|
3483
|
+
let day = parseInt(dayStr, 10) || 0;
|
|
3484
|
+
let month = parseInt(monthStr, 10) || 0;
|
|
3485
|
+
let year = parseInt(yearStr, 10) || 0;
|
|
3486
|
+
const minDate = this.$minDate() || new Date(new Date().getFullYear() - 100, 0, 1);
|
|
3487
|
+
const maxDate = this.$maxDate() || new Date(new Date().getFullYear() + 20, 11, 31);
|
|
3488
|
+
const minYear = minDate.getFullYear();
|
|
3489
|
+
const maxYear = maxDate.getFullYear();
|
|
3490
|
+
if (year < 1000) {
|
|
3491
|
+
year = maxYear;
|
|
3492
|
+
}
|
|
3493
|
+
else if (year < minYear) {
|
|
3494
|
+
year = minYear;
|
|
3495
|
+
}
|
|
3496
|
+
else if (year > maxYear) {
|
|
3497
|
+
year = maxYear;
|
|
3498
|
+
}
|
|
3499
|
+
if (month < 1 || month > 12) {
|
|
3500
|
+
month = 12;
|
|
3501
|
+
}
|
|
3502
|
+
if (day < 1) {
|
|
3503
|
+
day = 31;
|
|
3504
|
+
}
|
|
3505
|
+
else {
|
|
3506
|
+
const lastDay = new Date(year, month, 0).getDate();
|
|
3507
|
+
if (day > lastDay) {
|
|
3508
|
+
day = lastDay;
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
const parsedDate = new Date(year, month - 1, day);
|
|
3512
|
+
if (parsedDate < minDate) {
|
|
3513
|
+
day = minDate.getDate();
|
|
3514
|
+
month = minDate.getMonth() + 1;
|
|
3515
|
+
year = minDate.getFullYear();
|
|
3516
|
+
}
|
|
3517
|
+
else if (parsedDate > maxDate) {
|
|
3518
|
+
day = maxDate.getDate();
|
|
3519
|
+
month = maxDate.getMonth() + 1;
|
|
3520
|
+
year = maxDate.getFullYear();
|
|
3521
|
+
}
|
|
3522
|
+
const correctedDay = String(day).padStart(2, '0');
|
|
3523
|
+
const correctedMonth = String(month).padStart(2, '0');
|
|
3524
|
+
const correctedYear = String(year).padStart(4, '0');
|
|
3525
|
+
const correctedStr = correctedDay + correctedMonth + correctedYear;
|
|
3526
|
+
return formatSingle(correctedStr);
|
|
3527
|
+
};
|
|
3474
3528
|
if (this.$isRangeSelection()) {
|
|
3475
3529
|
const first = limited.substring(0, 8);
|
|
3476
3530
|
const second = limited.substring(8, 16);
|
|
3477
|
-
const firstDate =
|
|
3478
|
-
const secondDate =
|
|
3531
|
+
const firstDate = correctDateString(first);
|
|
3532
|
+
const secondDate = correctDateString(second);
|
|
3479
3533
|
return secondDate ? `${firstDate} - ${secondDate}` : firstDate;
|
|
3480
3534
|
}
|
|
3481
|
-
return
|
|
3535
|
+
return correctDateString(limited);
|
|
3482
3536
|
}
|
|
3483
3537
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: UIInputDateDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
3484
3538
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.2.0", version: "21.1.1", type: UIInputDateDirective, isStandalone: true, selector: "app-ui-input-date", inputs: { $isRangeSelection: { classPropertyName: "$isRangeSelection", publicName: "$isRangeSelection", isSignal: true, isRequired: false, transformFunction: null }, $dateFormat: { classPropertyName: "$dateFormat", publicName: "$dateFormat", isSignal: true, isRequired: false, transformFunction: null }, $dividePattern: { classPropertyName: "$dividePattern", publicName: "$dividePattern", isSignal: true, isRequired: false, transformFunction: null }, $minDate: { classPropertyName: "$minDate", publicName: "$minDate", isSignal: true, isRequired: false, transformFunction: null }, $maxDate: { classPropertyName: "$maxDate", publicName: "$maxDate", isSignal: true, isRequired: false, transformFunction: null } }, viewQueries: [{ propertyName: "$inputElement", first: true, predicate: ["input"], descendants: true, isSignal: true }], usesInheritance: true, ngImport: i0 });
|