@@ -60,19 +60,31 @@ export class MdCalendar<D> implements AfterContentInit, OnDestroy {
60
60
private _intlChanges : Subscription ;
61
61
62
62
/** A date representing the period (month or year) to start the calendar in. */
63
- @Input ( ) startAt : D ;
63
+ @Input ( )
64
+ get startAt ( ) : D { return this . _startAt ; }
65
+ set startAt ( value : D ) { this . _startAt = this . _coerceDateProperty ( value ) ; }
66
+ private _startAt : D ;
64
67
65
68
/** Whether the calendar should be started in month or year view. */
66
69
@Input ( ) startView : 'month' | 'year' = 'month' ;
67
70
68
71
/** The currently selected date. */
69
- @Input ( ) selected : D | null ;
72
+ @Input ( )
73
+ get selected ( ) : D | null { return this . _selected ; }
74
+ set selected ( value : D | null ) { this . _selected = this . _coerceDateProperty ( value ) ; }
75
+ private _selected : D | null ;
70
76
71
77
/** The minimum selectable date. */
72
- @Input ( ) minDate : D | null ;
78
+ @Input ( )
79
+ get minDate ( ) : D | null { return this . _minDate ; }
80
+ set minDate ( value : D | null ) { this . _minDate = this . _coerceDateProperty ( value ) ; }
81
+ private _minDate : D | null ;
73
82
74
83
/** The maximum selectable date. */
75
- @Input ( ) maxDate : D | null ;
84
+ @Input ( )
85
+ get maxDate ( ) : D | null { return this . _maxDate ; }
86
+ set maxDate ( value : D | null ) { this . _maxDate = this . _coerceDateProperty ( value ) ; }
87
+ private _maxDate : D | null ;
76
88
77
89
/** A function used to filter which dates are selectable. */
78
90
@Input ( ) dateFilter : ( date : D ) => boolean ;
@@ -351,4 +363,16 @@ export class MdCalendar<D> implements AfterContentInit, OnDestroy {
351
363
( this . _dateAdapter . getMonth ( date ) >= 7 ? 5 : 12 ) ;
352
364
return this . _dateAdapter . addCalendarMonths ( date , increment ) ;
353
365
}
366
+
367
+ /**
368
+ * Attempts to coerce a property to a date by parsing it as a ISO 8601 string. If not a valid
369
+ * ISO 8601 string, returns the original vlaue.
370
+ */
371
+ private _coerceDateProperty ( value : any ) : any {
372
+ if ( typeof value === 'string' ) {
373
+ const d = this . _dateAdapter . fromISODateString ( value ) ;
374
+ return d || value ;
375
+ }
376
+ return value ;
377
+ }
354
378
}
0 commit comments