From ca660238df82a8a59835db1584f37cc324eff016 Mon Sep 17 00:00:00 2001 From: Romy Kusuma Date: Tue, 6 Apr 2021 00:27:35 +0700 Subject: [PATCH] fix(datepicker): avoid mutating value in daterangepicker (#6035) fixes #6034 Co-authored-by: Dmitriy Danilov --- src/datepicker/bs-daterangepicker-input.directive.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/datepicker/bs-daterangepicker-input.directive.ts b/src/datepicker/bs-daterangepicker-input.directive.ts index 4ccee3110c..016cdcc989 100644 --- a/src/datepicker/bs-daterangepicker-input.directive.ts +++ b/src/datepicker/bs-daterangepicker-input.directive.ts @@ -139,14 +139,14 @@ export class BsDaterangepickerInputDirective } validate(c: AbstractControl): ValidationErrors | null { - const _value: [Date, Date] = c.value; + let _value: [Date, Date] = c.value; const errors: Record[] = []; if (_value === null || _value === undefined || !isArray(_value)) { return null; } - _value.sort((a, b) => a.getTime() - b.getTime()); + _value = _value.slice().sort((a, b) => a.getTime() - b.getTime()) as [Date, Date]; const _isFirstDateValid = isDateValid(_value[0]); const _isSecondDateValid = isDateValid(_value[1]);