@@ -37,7 +37,7 @@ import {
37
37
} from './time-picker.directives' ;
38
38
import { Subject , fromEvent , interval , animationFrameScheduler , Subscription } from 'rxjs' ;
39
39
import { 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' ;
41
41
import { AbsoluteScrollStrategy } from '../services/overlay/scroll' ;
42
42
import { AutoPositionStrategy } from '../services/overlay/position' ;
43
43
import { OverlaySettings } from '../services/overlay/utilities' ;
@@ -98,6 +98,7 @@ const noop = () => { };
98
98
}`
99
99
]
100
100
} )
101
+
101
102
export class IgxTimePickerComponent implements
102
103
IgxTimePickerBase ,
103
104
ControlValueAccessor ,
@@ -152,6 +153,10 @@ export class IgxTimePickerComponent implements
152
153
this . onValidationFailed . emit ( args ) ;
153
154
}
154
155
}
156
+ /**
157
+ * @hidden @internal
158
+ */
159
+ timeParts : any = Object . assign ( { } , TimeParts ) ;
155
160
156
161
/**
157
162
* An accessor that returns the value of `igx-time-picker` component.
@@ -507,10 +512,10 @@ export class IgxTimePickerComponent implements
507
512
@ViewChild ( IgxInputDirective , { read : ElementRef } )
508
513
private _inputElementRef : ElementRef ;
509
514
510
- @ViewChild ( IgxInputDirective , { read : IgxInputDirective } )
515
+ @ViewChild ( IgxInputDirective , { read : IgxInputDirective } )
511
516
private _inputDirective : IgxInputDirective ;
512
517
513
- @ContentChild ( IgxInputDirective , { read : IgxInputDirective } )
518
+ @ContentChild ( IgxInputDirective , { read : IgxInputDirective } )
514
519
private _inputDirectiveUserTemplate : IgxInputDirective ;
515
520
516
521
@ViewChild ( IgxInputGroupComponent , { read : IgxInputGroupComponent } )
@@ -635,6 +640,46 @@ export class IgxTimePickerComponent implements
635
640
}
636
641
}
637
642
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
+
638
683
/** @hidden @internal */
639
684
public registerOnChange ( fn : ( _ : Date ) => void ) { this . _onChangeCallback = fn ; }
640
685
@@ -1267,7 +1312,11 @@ export class IgxTimePickerComponent implements
1267
1312
return date ;
1268
1313
}
1269
1314
1270
- private _convertMinMaxValue ( value : string ) : Date {
1315
+ /** @hidden @internal */
1316
+ public convertMinMaxValue ( value : string ) : Date {
1317
+ if ( ! value ) {
1318
+ return ;
1319
+ }
1271
1320
const date = this . value ? new Date ( this . value ) : this . _dateFromModel ? new Date ( this . _dateFromModel ) : new Date ( ) ;
1272
1321
const sections = value . split ( / [ \s : ] + / ) ;
1273
1322
let hour , minutes , seconds , amPM ;
@@ -1310,9 +1359,9 @@ export class IgxTimePickerComponent implements
1310
1359
}
1311
1360
1312
1361
private _isValueValid ( value : Date ) : boolean {
1313
- if ( this . maxValue && value > this . _convertMinMaxValue ( this . maxValue ) ) {
1362
+ if ( this . maxValue && value > this . convertMinMaxValue ( this . maxValue ) ) {
1314
1363
return false ;
1315
- } else if ( this . minValue && value < this . _convertMinMaxValue ( this . minValue ) ) {
1364
+ } else if ( this . minValue && value < this . convertMinMaxValue ( this . minValue ) ) {
1316
1365
return false ;
1317
1366
} else {
1318
1367
return true ;
@@ -1484,7 +1533,7 @@ export class IgxTimePickerComponent implements
1484
1533
1485
1534
private _onDropDownClosed ( ) : void {
1486
1535
const oldValue = this . value ;
1487
- const newVal = this . _convertMinMaxValue ( this . displayValue ) ;
1536
+ const newVal = this . convertMinMaxValue ( this . displayValue ) ;
1488
1537
1489
1538
if ( this . displayValue === this . parseMask ( false ) ) {
1490
1539
return ;
@@ -1922,7 +1971,7 @@ export class IgxTimePickerComponent implements
1922
1971
// timepicker own value property if it is a valid Date
1923
1972
if ( val . indexOf ( this . promptChar ) === - 1 ) {
1924
1973
if ( this . _isEntryValid ( val ) ) {
1925
- const newVal = this . _convertMinMaxValue ( val ) ;
1974
+ const newVal = this . convertMinMaxValue ( val ) ;
1926
1975
if ( oldVal . getTime ( ) !== newVal . getTime ( ) ) {
1927
1976
this . value = newVal ;
1928
1977
}
@@ -1970,7 +2019,7 @@ export class IgxTimePickerComponent implements
1970
2019
1971
2020
if ( value && value !== this . parseMask ( ) ) {
1972
2021
if ( this . _isEntryValid ( value ) ) {
1973
- const newVal = this . _convertMinMaxValue ( value ) ;
2022
+ const newVal = this . convertMinMaxValue ( value ) ;
1974
2023
if ( ! this . value || this . value . getTime ( ) !== newVal . getTime ( ) ) {
1975
2024
this . value = newVal ;
1976
2025
}
@@ -2007,8 +2056,8 @@ export class IgxTimePickerComponent implements
2007
2056
let sign : number ;
2008
2057
let displayVal : string ;
2009
2058
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' ) ;
2012
2061
2013
2062
const cursor = this . _getCursorPosition ( ) ;
2014
2063
0 commit comments