Skip to content

Commit 0f968df

Browse files
committed
address feedback
1 parent 34bc1be commit 0f968df

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

src/lib/core/datetime/date-adapter.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ export abstract class DateAdapter<D> {
170170
*/
171171
abstract isValid(date: D): boolean;
172172

173-
/**
174-
* @param {obj} The object to check.
175-
* @returns The given object if it is both a date instance and valid, otherwise null.
176-
*/
177-
getValidDateOrNull(obj: any): D | null {
178-
return (this.isDateInstance(obj) && this.isValid(obj)) ? obj : null;
179-
}
180-
181173
/**
182174
* Sets the locale used for all dates.
183175
* @param locale The new locale.

src/lib/core/datetime/native-date-adapter.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,20 +312,17 @@ describe('NativeDateAdapter', () => {
312312
let d = new Date();
313313
expect(adapter.isValid(d)).toBe(true);
314314
expect(adapter.isDateInstance(d)).toBe(true);
315-
expect(adapter.getValidDateOrNull(d)).toBe(d);
316315
});
317316

318317
it('should count an invalid date as an invalid date instance', () => {
319318
let d = new Date(NaN);
320319
expect(adapter.isValid(d)).toBe(false);
321320
expect(adapter.isDateInstance(d)).toBe(true);
322-
expect(adapter.getValidDateOrNull(d)).toBeNull();
323321
});
324322

325323
it('should count a string as not a date instance', () => {
326324
let d = '1/1/2017';
327325
expect(adapter.isDateInstance(d)).toBe(false);
328-
expect(adapter.getValidDateOrNull(d)).toBeNull();
329326
});
330327
});
331328

src/lib/datepicker/datepicker-input.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,14 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
112112
/** The value of the input. */
113113
@Input()
114114
get value(): D | null {
115-
return this._dateAdapter.getValidDateOrNull(
116-
this._dateAdapter.parse(
117-
this._elementRef.nativeElement.value, this._dateFormats.parse.dateInput));
115+
return this._getValidDateOrNull(this._dateAdapter.parse(
116+
this._elementRef.nativeElement.value, this._dateFormats.parse.dateInput));
118117
}
119118
set value(value: D | null) {
120119
if (value != null && !this._dateAdapter.isDateInstance(value)) {
121120
throw Error('Datepicker: value not recognized as a date object by DateAdapter.');
122121
}
123-
value = this._dateAdapter.getValidDateOrNull(value);
122+
value = this._getValidDateOrNull(value);
124123

125124
let oldDate = this.value;
126125
this._renderer.setProperty(this._elementRef.nativeElement, 'value',
@@ -134,7 +133,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
134133
@Input()
135134
get min(): D | null { return this._min; }
136135
set min(value: D | null) {
137-
this._min = this._dateAdapter.getValidDateOrNull(value);
136+
this._min = this._getValidDateOrNull(value);
138137
this._validatorOnChange();
139138
}
140139
private _min: D | null;
@@ -143,7 +142,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
143142
@Input()
144143
get max(): D | null { return this._max; }
145144
set max(value: D | null) {
146-
this._max = this._dateAdapter.getValidDateOrNull(value);
145+
this._max = this._getValidDateOrNull(value);
147146
this._validatorOnChange();
148147
}
149148
private _max: D | null;
@@ -289,4 +288,12 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
289288
_onChange() {
290289
this.dateChange.emit(new MdDatepickerInputEvent(this, this._elementRef.nativeElement));
291290
}
291+
292+
/**
293+
* @param obj The object to check.
294+
* @returns The given object if it is both a date instance and valid, otherwise null.
295+
*/
296+
private _getValidDateOrNull(obj: any): D | null {
297+
return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
298+
}
292299
}

src/lib/datepicker/datepicker.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class MdDatepicker<D> implements OnDestroy {
129129
// selected value is.
130130
return this._startAt || (this._datepickerInput ? this._datepickerInput.value : null);
131131
}
132-
set startAt(date: D | null) { this._startAt = this._dateAdapter.getValidDateOrNull(date); }
132+
set startAt(date: D | null) { this._startAt = this._getValidDateOrNull(date); }
133133
private _startAt: D | null;
134134

135135
/** The view that the calendar should start in. */
@@ -343,4 +343,12 @@ export class MdDatepicker<D> implements OnDestroy {
343343
{ overlayX: 'end', overlayY: 'bottom' }
344344
);
345345
}
346+
347+
/**
348+
* @param obj The object to check.
349+
* @returns The given object if it is both a date instance and valid, otherwise null.
350+
*/
351+
private _getValidDateOrNull(obj: any): D | null {
352+
return (this._dateAdapter.isDateInstance(obj) && this._dateAdapter.isValid(obj)) ? obj : null;
353+
}
346354
}

0 commit comments

Comments
 (0)