@@ -37,7 +37,7 @@ import {
3737} from './time-picker.directives' ;
3838import { Subject , fromEvent , interval , animationFrameScheduler , Subscription } from 'rxjs' ;
3939import { EditorProvider } from '../core/edit-provider' ;
40- import { IgxTimePickerBase , IGX_TIME_PICKER_COMPONENT } from './time-picker.common' ;
40+ import { IgxTimePickerBase , IGX_TIME_PICKER_COMPONENT , TimeParts } from './time-picker.common' ;
4141import { AbsoluteScrollStrategy } from '../services/overlay/scroll' ;
4242import { AutoPositionStrategy } from '../services/overlay/position' ;
4343import { OverlaySettings } from '../services/overlay/utilities' ;
@@ -98,6 +98,7 @@ const noop = () => { };
9898 }`
9999 ]
100100} )
101+
101102export class IgxTimePickerComponent implements
102103 IgxTimePickerBase ,
103104 ControlValueAccessor ,
@@ -152,6 +153,10 @@ export class IgxTimePickerComponent implements
152153 this . onValidationFailed . emit ( args ) ;
153154 }
154155 }
156+ /**
157+ * @hidden @internal
158+ */
159+ timeParts : any = Object . assign ( { } , TimeParts ) ;
155160
156161 /**
157162 * An accessor that returns the value of `igx-time-picker` component.
@@ -507,10 +512,10 @@ export class IgxTimePickerComponent implements
507512 @ViewChild ( IgxInputDirective , { read : ElementRef } )
508513 private _inputElementRef : ElementRef ;
509514
510- @ViewChild ( IgxInputDirective , { read : IgxInputDirective } )
515+ @ViewChild ( IgxInputDirective , { read : IgxInputDirective } )
511516 private _inputDirective : IgxInputDirective ;
512517
513- @ContentChild ( IgxInputDirective , { read : IgxInputDirective } )
518+ @ContentChild ( IgxInputDirective , { read : IgxInputDirective } )
514519 private _inputDirectiveUserTemplate : IgxInputDirective ;
515520
516521 @ViewChild ( IgxInputGroupComponent , { read : IgxInputGroupComponent } )
@@ -635,6 +640,46 @@ export class IgxTimePickerComponent implements
635640 }
636641 }
637642
643+ /** @hidden @internal */
644+ applyDisabledStyleForItem ( period : string , value : string ) {
645+ if ( ! this . minValue || ! this . maxValue ) {
646+ return false ;
647+ }
648+ const minValueDate : Date = this . convertMinMaxValue ( this . minValue ) ;
649+ const maxValueDate : Date = this . convertMinMaxValue ( this . maxValue ) ;
650+ let hour : number = parseInt ( this . selectedHour , 10 ) ;
651+ let minute : number = parseInt ( this . selectedMinute , 10 ) ;
652+ let seconds : number = parseInt ( this . selectedSeconds , 10 ) ;
653+ let amPM : string = this . selectedAmPm ;
654+ const date = new Date ( minValueDate ) ;
655+ switch ( period ) {
656+ case TimeParts . Hour :
657+ hour = parseInt ( value , 10 ) ;
658+ break ;
659+
660+ case TimeParts . Minute :
661+ minute = parseInt ( value , 10 ) ;
662+ break ;
663+
664+ case TimeParts . Seconds :
665+ seconds = parseInt ( value , 10 ) ;
666+ break ;
667+
668+ case TimeParts . amPM :
669+ amPM = value ;
670+ break ;
671+ }
672+
673+ if ( amPM === 'PM' ) {
674+ hour += 12 ;
675+ }
676+ date . setHours ( hour ) ;
677+ date . setMinutes ( minute ) ;
678+ date . setSeconds ( seconds ) ;
679+ return date < minValueDate || date > maxValueDate ;
680+
681+ }
682+
638683 /** @hidden @internal */
639684 public registerOnChange ( fn : ( _ : Date ) => void ) { this . _onChangeCallback = fn ; }
640685
@@ -1267,7 +1312,11 @@ export class IgxTimePickerComponent implements
12671312 return date ;
12681313 }
12691314
1270- private _convertMinMaxValue ( value : string ) : Date {
1315+ /** @hidden @internal */
1316+ public convertMinMaxValue ( value : string ) : Date {
1317+ if ( ! value ) {
1318+ return ;
1319+ }
12711320 const date = this . value ? new Date ( this . value ) : this . _dateFromModel ? new Date ( this . _dateFromModel ) : new Date ( ) ;
12721321 const sections = value . split ( / [ \s : ] + / ) ;
12731322 let hour , minutes , seconds , amPM ;
@@ -1310,9 +1359,9 @@ export class IgxTimePickerComponent implements
13101359 }
13111360
13121361 private _isValueValid ( value : Date ) : boolean {
1313- if ( this . maxValue && value > this . _convertMinMaxValue ( this . maxValue ) ) {
1362+ if ( this . maxValue && value > this . convertMinMaxValue ( this . maxValue ) ) {
13141363 return false ;
1315- } else if ( this . minValue && value < this . _convertMinMaxValue ( this . minValue ) ) {
1364+ } else if ( this . minValue && value < this . convertMinMaxValue ( this . minValue ) ) {
13161365 return false ;
13171366 } else {
13181367 return true ;
@@ -1484,7 +1533,7 @@ export class IgxTimePickerComponent implements
14841533
14851534 private _onDropDownClosed ( ) : void {
14861535 const oldValue = this . value ;
1487- const newVal = this . _convertMinMaxValue ( this . displayValue ) ;
1536+ const newVal = this . convertMinMaxValue ( this . displayValue ) ;
14881537
14891538 if ( this . displayValue === this . parseMask ( false ) ) {
14901539 return ;
@@ -1922,7 +1971,7 @@ export class IgxTimePickerComponent implements
19221971 // timepicker own value property if it is a valid Date
19231972 if ( val . indexOf ( this . promptChar ) === - 1 ) {
19241973 if ( this . _isEntryValid ( val ) ) {
1925- const newVal = this . _convertMinMaxValue ( val ) ;
1974+ const newVal = this . convertMinMaxValue ( val ) ;
19261975 if ( oldVal . getTime ( ) !== newVal . getTime ( ) ) {
19271976 this . value = newVal ;
19281977 }
@@ -1970,7 +2019,7 @@ export class IgxTimePickerComponent implements
19702019
19712020 if ( value && value !== this . parseMask ( ) ) {
19722021 if ( this . _isEntryValid ( value ) ) {
1973- const newVal = this . _convertMinMaxValue ( value ) ;
2022+ const newVal = this . convertMinMaxValue ( value ) ;
19742023 if ( ! this . value || this . value . getTime ( ) !== newVal . getTime ( ) ) {
19752024 this . value = newVal ;
19762025 }
@@ -2007,8 +2056,8 @@ export class IgxTimePickerComponent implements
20072056 let sign : number ;
20082057 let displayVal : string ;
20092058 const currentVal = new Date ( this . value ) ;
2010- const min = this . minValue ? this . _convertMinMaxValue ( this . minValue ) : this . _convertMinMaxValue ( '00:00' ) ;
2011- const max = this . maxValue ? this . _convertMinMaxValue ( this . maxValue ) : this . _convertMinMaxValue ( '24:00' ) ;
2059+ const min = this . minValue ? this . convertMinMaxValue ( this . minValue ) : this . convertMinMaxValue ( '00:00' ) ;
2060+ const max = this . maxValue ? this . convertMinMaxValue ( this . maxValue ) : this . convertMinMaxValue ( '24:00' ) ;
20122061
20132062 const cursor = this . _getCursorPosition ( ) ;
20142063
0 commit comments