@@ -44,7 +44,7 @@ import { IgxDateTimeEditorModule, IgxDateTimeEditorDirective } from '../directiv
44
44
import { IgxToggleModule , IgxToggleDirective } from '../directives/toggle/toggle.directive' ;
45
45
import { ITimePickerResourceStrings } from '../core/i18n/time-picker-resources' ;
46
46
import { CurrentResourceStrings } from '../core/i18n/resources' ;
47
- import { KEYS , IBaseEventArgs , isEqual } from '../core/utils' ;
47
+ import { KEYS , IBaseEventArgs , isEqual , isDate } from '../core/utils' ;
48
48
import { PickerInteractionMode } from '../date-common/types' ;
49
49
import { IgxTextSelectionModule } from '../directives/text-selection/text-selection.directive' ;
50
50
import { IgxLabelDirective } from '../directives/label/label.directive' ;
@@ -54,6 +54,7 @@ import { DatePart, DatePartDeltas } from '../directives/date-time-editor/public_
54
54
import { PickerHeaderOrientation } from '../date-common/types' ;
55
55
import { IgxPickerToggleComponent } from '../date-common/picker-icons.common' ;
56
56
import { TimeFormatPipe } from './time-picker.pipes' ;
57
+ import { defaultCipherList } from 'constants' ;
57
58
58
59
59
60
let NEXT_ID = 0 ;
@@ -144,7 +145,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
144
145
* ```
145
146
*/
146
147
@Input ( )
147
- public inputFormat : string = DateTimeUtil . DEFAULT_TIME_INPUT_FORMAT ;
148
+ public inputFormat : string = DateTimeUtil . DEFAULT_TIME_INPUT_FORMAT ;
148
149
149
150
/**
150
151
* Gets/Sets the interaction mode - dialog or drop down.
@@ -222,18 +223,6 @@ export class IgxTimePickerComponent extends PickerBaseDirective
222
223
@Input ( )
223
224
public headerOrientation : PickerHeaderOrientation = PickerHeaderOrientation . Horizontal ;
224
225
225
- /**
226
- * Delta values used to increment or decrement each editor time part on spin actions.
227
- * All values default to `1`.
228
- *
229
- * @example
230
- * ```html
231
- * <igx-time-picker [spinDelta]="{ hour: 2, minute: 20 }"></igx-time-picker>
232
- * ```
233
- */
234
- @Input ( )
235
- public spinDelta : Pick < DatePartDeltas , 'hour' | 'minute' | 'second' > ;
236
-
237
226
/**
238
227
* Emitted after a selection has been done.
239
228
*
@@ -257,7 +246,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
257
246
* ```
258
247
*/
259
248
@Output ( )
260
- public valueChange = new EventEmitter < Date > ( ) ;
249
+ public valueChange = new EventEmitter < Date | string > ( ) ;
261
250
262
251
/**
263
252
* Emitted when the user types/spins invalid time in the time-picker editor.
@@ -515,14 +504,14 @@ export class IgxTimePickerComponent extends PickerBaseDirective
515
504
*/
516
505
@Input ( )
517
506
public set value ( value : Date | string ) {
518
- const oldValue = this . _dateValue ;
507
+ const oldValue = this . _value ;
519
508
this . _value = value ;
520
509
this . _dateValue = this . parseToDate ( value ) ;
521
- if ( this . dateTimeEditor . value !== value ) {
522
- this . dateTimeEditor . value = value ;
510
+ if ( this . dateTimeEditor . value !== this . _dateValue ) {
511
+ this . dateTimeEditor . value = this . _dateValue ;
523
512
}
524
- this . emitValueChange ( oldValue , this . _dateValue ) ;
525
- this . _onChangeCallback ( this . _dateValue ) ;
513
+ this . emitValueChange ( oldValue , this . _value ) ;
514
+ this . _onChangeCallback ( this . _value ) ;
526
515
}
527
516
528
517
/**
@@ -691,9 +680,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
691
680
this . dateTimeEditor . displayFormat = this . displayFormat ;
692
681
}
693
682
if ( changes [ 'inputFormat' ] && this . dateTimeEditor ) {
694
- if ( this . validateFormat ( this . inputFormat ) ) {
695
- this . inputFormat = DateTimeUtil . DEFAULT_TIME_INPUT_FORMAT ;
696
- }
683
+ this . inputFormat = this . hasDateParts ( ) ? DateTimeUtil . DEFAULT_TIME_INPUT_FORMAT : this . inputFormat ;
697
684
this . dateTimeEditor . inputFormat = this . inputFormat ;
698
685
}
699
686
}
@@ -774,11 +761,13 @@ export class IgxTimePickerComponent extends PickerBaseDirective
774
761
this . close ( ) ;
775
762
}
776
763
777
- const value = this . _dateValue ;
778
- value . setHours ( 0 , 0 , 0 ) ;
779
- this . value = value ;
780
- this . dateTimeEditor . value = new Date ( this . value ) ;
781
- this . setSelectedValue ( ) ;
764
+ if ( isDate ( this . value ) ) {
765
+ this . value . setHours ( 0 , 0 , 0 ) ;
766
+ this . dateTimeEditor . value = new Date ( this . value ) ;
767
+ this . setSelectedValue ( ) ;
768
+ } else {
769
+ this . value = null ;
770
+ }
782
771
}
783
772
784
773
/**
@@ -868,7 +857,6 @@ export class IgxTimePickerComponent extends PickerBaseDirective
868
857
this . updateSelectedAmpm ( previousDate ) ;
869
858
this . updateSelectedMinutes ( ) ;
870
859
this . updateSelectedSeconds ( ) ;
871
- this . value = this . _selectedDate ;
872
860
}
873
861
break ;
874
862
case 'minuteList' : {
@@ -878,7 +866,6 @@ export class IgxTimePickerComponent extends PickerBaseDirective
878
866
this . _minuteView = this . scrollListItem ( minutes , this . _minuteItems , DatePart . Minutes ) ;
879
867
this . _selectedDate = date ;
880
868
this . updateSelectedSeconds ( ) ;
881
- this . value = this . _selectedDate ;
882
869
break ;
883
870
}
884
871
case 'secondsList' : {
@@ -887,7 +874,6 @@ export class IgxTimePickerComponent extends PickerBaseDirective
887
874
if ( this . valueInRange ( date , this . _minDropdownValue , this . _maxDropdownValue ) ) {
888
875
this . _secondsView = this . scrollListItem ( seconds , this . _secondsItems , DatePart . Seconds ) ;
889
876
this . _selectedDate = date ;
890
- this . value = this . _selectedDate ;
891
877
}
892
878
break ;
893
879
}
@@ -902,10 +888,10 @@ export class IgxTimePickerComponent extends PickerBaseDirective
902
888
this . _selectedDate = date ;
903
889
this . updateSelectedMinutes ( ) ;
904
890
this . updateSelectedSeconds ( ) ;
905
- this . value = this . _selectedDate ;
906
891
break ;
907
892
}
908
893
}
894
+ this . value = isDate ( this . value ) ? this . _selectedDate : this . toISOString ( this . _selectedDate ) ;
909
895
}
910
896
911
897
/** @hidden @internal */
@@ -934,7 +920,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
934
920
this . updateSelectedAmpm ( previousDate ) ;
935
921
936
922
this . _selectedDate = new Date ( this . _selectedDate ) ;
937
- this . value = this . _selectedDate ;
923
+ this . value = isDate ( this . value ) ? this . _selectedDate : this . toISOString ( this . _selectedDate ) ;
938
924
}
939
925
940
926
/** @hidden @internal */
@@ -957,7 +943,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
957
943
958
944
this . _minuteView = this . scrollListItem ( minutes , this . _minuteItems , DatePart . Minutes ) ;
959
945
this . _selectedDate = new Date ( this . _selectedDate ) ;
960
- this . value = this . _selectedDate ;
946
+ this . value = isDate ( this . value ) ? this . _selectedDate : this . toISOString ( this . _selectedDate ) ;
961
947
}
962
948
963
949
/** @hidden @internal */
@@ -978,7 +964,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
978
964
979
965
this . _secondsView = this . scrollListItem ( seconds , this . _secondsItems , DatePart . Seconds ) ;
980
966
this . _selectedDate = new Date ( this . _selectedDate ) ;
981
- this . value = this . _selectedDate ;
967
+ this . value = isDate ( this . value ) ? this . _selectedDate : this . toISOString ( this . _selectedDate ) ;
982
968
}
983
969
984
970
/** @hidden @internal */
@@ -1002,7 +988,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
1002
988
this . _ampmView = this . scrollListItem ( ampm , this . _ampmItems , DatePart . AmPm ) ;
1003
989
1004
990
this . _selectedDate = new Date ( this . _selectedDate ) ;
1005
- this . value = this . _selectedDate ;
991
+ this . value = isDate ( this . value ) ? this . _selectedDate : this . toISOString ( this . _selectedDate ) ;
1006
992
}
1007
993
}
1008
994
@@ -1207,7 +1193,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
1207
1193
}
1208
1194
1209
1195
private initializeContainer ( ) {
1210
- this . value = this . _selectedDate ;
1196
+ this . value = isDate ( this . value ) ? this . _selectedDate : this . toISOString ( this . _selectedDate ) ;
1211
1197
this . _onTouchedCallback ( ) ;
1212
1198
1213
1199
if ( this . showHoursList ) {
@@ -1309,7 +1295,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
1309
1295
return spinDelta ;
1310
1296
}
1311
1297
1312
- private emitValueChange ( oldValue : Date , newValue : Date ) {
1298
+ private emitValueChange ( oldValue : Date | string , newValue : Date | string ) {
1313
1299
if ( ! isEqual ( oldValue , newValue ) ) {
1314
1300
this . valueChange . emit ( newValue ) ;
1315
1301
}
@@ -1383,6 +1369,14 @@ export class IgxTimePickerComponent extends PickerBaseDirective
1383
1369
return DateTimeUtil . isValidDate ( value ) ? value : DateTimeUtil . parseIsoDate ( value ) ;
1384
1370
}
1385
1371
1372
+ private toISOString ( value : Date ) : string {
1373
+ return value . toLocaleTimeString ( "en-GB" , {
1374
+ hour : "2-digit" ,
1375
+ minute : "2-digit" ,
1376
+ second : "2-digit" ,
1377
+ } ) ;
1378
+ }
1379
+
1386
1380
private isTimePart ( datePart : DatePart ) : boolean {
1387
1381
return ( datePart === DatePart . Hours || datePart === DatePart . Minutes || datePart === DatePart . Seconds || datePart === DatePart . AmPm ) ;
1388
1382
}
@@ -1407,11 +1401,12 @@ export class IgxTimePickerComponent extends PickerBaseDirective
1407
1401
return hour ;
1408
1402
}
1409
1403
1410
- private validateFormat ( format : string ) : boolean {
1411
- return ( format . indexOf ( 'd' ) < 0 && format . indexOf ( 'M' ) < 0 &&
1412
- format . indexOf ( 'Y' ) < 0 && format . indexOf ( 'y' ) < 0 &&
1413
- format . indexOf ( 'L' ) < 0 && format . indexOf ( 'E' ) < 0 &&
1414
- format . indexOf ( 'W' ) < 0 && format . indexOf ( 'w' ) < 0 ) ;
1404
+ private hasDateParts ( ) : boolean {
1405
+ const inputDateParts = DateTimeUtil . parseDateTimeFormat ( this . inputFormat ) ;
1406
+ return inputDateParts . some (
1407
+ p => p . type === DatePart . Date
1408
+ || p . type === DatePart . Month
1409
+ || p . type === DatePart . Year ) ;
1415
1410
}
1416
1411
1417
1412
private attachOnKeydown ( ) : void {
@@ -1442,9 +1437,7 @@ export class IgxTimePickerComponent extends PickerBaseDirective
1442
1437
1443
1438
this . dateTimeEditor . valueChange . pipe (
1444
1439
takeUntil ( this . _destroy$ ) ) . subscribe ( date => {
1445
- if ( ! isEqual ( date , this . _dateValue ) ) {
1446
- this . value = date ;
1447
- }
1440
+ this . value = isDate ( this . value ) ? this . parseToDate ( date ) : isDate ( date ) ? this . toISOString ( date ) : date ;
1448
1441
this . setSelectedValue ( ) ;
1449
1442
} ) ;
1450
1443
0 commit comments