@@ -97,6 +97,24 @@ export interface LocaleSettings {
97
97
<span class="fa fa-angle-down"></span>
98
98
</a>
99
99
</div>
100
+ <div class="ui-separator" *ngIf="showSeconds">
101
+ <a href="#">
102
+ <span class="fa fa-angle-up"></span>
103
+ </a>
104
+ <span>:</span>
105
+ <a href="#">
106
+ <span class="fa fa-angle-down"></span>
107
+ </a>
108
+ </div>
109
+ <div class="ui-second-picker" *ngIf="showSeconds">
110
+ <a href="#" (click)="incrementSecond($event)">
111
+ <span class="fa fa-angle-up"></span>
112
+ </a>
113
+ <span [ngStyle]="{'display': currentSecond < 10 ? 'inline': 'none'}">0</span><span>{{currentSecond}}</span>
114
+ <a href="#" (click)="incrementSecond($event)">
115
+ <span class="fa fa-angle-down"></span>
116
+ </a>
117
+ </div>
100
118
<div class="ui-ampm-picker" *ngIf="hourFormat=='12'">
101
119
<a href="#" (click)="toggleAMPM($event)">
102
120
<span class="fa fa-angle-up"></span>
@@ -177,6 +195,10 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
177
195
@Input ( ) stepHour : number = 1 ;
178
196
179
197
@Input ( ) stepMinute : number = 1 ;
198
+
199
+ @Input ( ) stepSecond : number = 1 ;
200
+
201
+ @Input ( ) showSeconds : number = 1 ;
180
202
181
203
@Input ( ) required : boolean ;
182
204
@@ -217,6 +239,8 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
217
239
218
240
currentMinute : number ;
219
241
242
+ currentSecond : number ;
243
+
220
244
pm : boolean ;
221
245
222
246
overlay : HTMLDivElement ;
@@ -282,6 +306,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
282
306
this . currentYear = date . getFullYear ( ) ;
283
307
if ( this . showTime ) {
284
308
this . currentMinute = date . getMinutes ( ) ;
309
+ this . currentSecond = date . getSeconds ( ) ;
285
310
this . pm = date . getHours ( ) > 11 ;
286
311
287
312
if ( this . hourFormat == '12' )
@@ -292,6 +317,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
292
317
else if ( this . timeOnly ) {
293
318
this . currentMinute = 0 ;
294
319
this . currentHour = 0 ;
320
+ this . currentSecond = 0 ;
295
321
}
296
322
297
323
this . createMonth ( this . currentMonth , this . currentYear ) ;
@@ -454,6 +480,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
454
480
this . value . setHours ( this . currentHour ) ;
455
481
456
482
this . value . setMinutes ( this . currentMinute ) ;
483
+ this . value . setSeconds ( this . currentSecond ) ;
457
484
}
458
485
this . updateModel ( ) ;
459
486
this . onSelect . emit ( this . value ) ;
@@ -652,6 +679,24 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
652
679
event . preventDefault ( ) ;
653
680
}
654
681
682
+ incrementSecond ( event ) {
683
+ let newSecond = this . currentSecond + this . stepSecond ;
684
+ this . currentSecond = ( newSecond > 59 ) ? newSecond - 60 : newSecond ;
685
+
686
+ this . updateTime ( ) ;
687
+
688
+ event . preventDefault ( ) ;
689
+ }
690
+
691
+ decrementSecond ( event ) {
692
+ let newSecond = this . currentSecond - this . stepSecond ;
693
+ this . currentSecond = ( newSecond < 0 ) ? 60 + newSecond : newSecond ;
694
+
695
+ this . updateTime ( ) ;
696
+
697
+ event . preventDefault ( ) ;
698
+ }
699
+
655
700
updateTime ( ) {
656
701
this . value = this . value || new Date ( ) ;
657
702
if ( this . hourFormat === '12' && this . pm && this . currentHour != 12 )
@@ -660,6 +705,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
660
705
this . value . setHours ( this . currentHour ) ;
661
706
662
707
this . value . setMinutes ( this . currentMinute ) ;
708
+ this . value . setSeconds ( this . currentSecond ) ;
663
709
this . updateModel ( ) ;
664
710
this . onSelect . emit ( this . value ) ;
665
711
this . updateInputfield ( ) ;
@@ -720,6 +766,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
720
766
}
721
767
722
768
value . setMinutes ( time . minute ) ;
769
+ value . setSeconds ( time . second ) ;
723
770
}
724
771
725
772
updateUI ( ) {
@@ -744,6 +791,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
744
791
}
745
792
746
793
this . currentMinute = val . getMinutes ( ) ;
794
+ this . currentSecond = val . getSeconds ( ) ;
747
795
}
748
796
}
749
797
@@ -874,6 +922,7 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
874
922
let output = '' ;
875
923
let hours = date . getHours ( ) ;
876
924
let minutes = date . getMinutes ( ) ;
925
+ let seconds = date . getSeconds ( ) ;
877
926
878
927
if ( this . hourFormat == '12' && this . pm && hours != 12 ) {
879
928
hours -= 12 ;
@@ -883,6 +932,11 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
883
932
output += ':' ;
884
933
output += ( minutes < 10 ) ? '0' + minutes : minutes ;
885
934
935
+ if ( this . showSeconds ) {
936
+ output += ':' ;
937
+ output += ( seconds < 10 ) ? '0' + seconds : seconds ;
938
+ }
939
+
886
940
if ( this . hourFormat == '12' ) {
887
941
output += this . pm ? ' PM' : ' AM' ;
888
942
}
@@ -892,21 +946,25 @@ export class Calendar implements AfterViewInit,OnInit,OnDestroy,ControlValueAcce
892
946
893
947
parseTime ( value ) {
894
948
let tokens : string [ ] = value . split ( ':' ) ;
895
- if ( tokens . length !== 2 ) {
949
+ let validTokentLength = this . showSeconds ? 3 : 2 ;
950
+
951
+ if ( tokens . length !== validTokentLength ) {
896
952
throw "Invalid time" ;
897
953
}
898
954
899
955
let h = parseInt ( tokens [ 0 ] ) ;
900
956
let m = parseInt ( tokens [ 1 ] ) ;
901
- if ( isNaN ( h ) || isNaN ( m ) || h > 23 || m > 59 || ( this . hourFormat == '12' && h > 12 ) ) {
957
+ let s = this . showSeconds ? parseInt ( tokens [ 2 ] ) : null ;
958
+
959
+ if ( isNaN ( h ) || isNaN ( m ) || h > 23 || m > 59 || ( this . hourFormat == '12' && h > 12 ) || ( this . showSeconds && ( isNaN ( s ) || s > 59 ) ) ) {
902
960
throw "Invalid time" ;
903
961
}
904
962
else {
905
963
if ( this . hourFormat == '12' && h !== 12 ) {
906
964
h += 12 ;
907
965
}
908
-
909
- return { hour : parseInt ( tokens [ 0 ] ) , minute : parseInt ( tokens [ 1 ] ) } ;
966
+
967
+ return { hour : h , minute : m , second : s } ;
910
968
}
911
969
}
912
970
0 commit comments