@@ -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}
0 commit comments