44export function isValidHour ( value : string ) {
55 return / ^ ( 0 [ 0 - 9 ] | 1 [ 0 - 9 ] | 2 [ 0 - 3 ] ) $ / . test ( value ) ;
66}
7-
87/**
98 * regular expression to check for valid 12 hour format (01-12)
109 */
1110export function isValid12Hour ( value : string ) {
1211 return / ^ ( 0 [ 1 - 9 ] | 1 [ 0 - 2 ] ) $ / . test ( value ) ;
1312}
14-
1513/**
1614 * regular expression to check for valid minute format (00-59)
1715 */
@@ -45,17 +43,14 @@ export function getValidHour(value: string) {
4543 if ( isValidHour ( value ) ) return value ;
4644 return getValidNumber ( value , { max : 23 } ) ;
4745}
48-
4946export function getValid12Hour ( value : string ) {
5047 if ( isValid12Hour ( value ) ) return value ;
5148 return getValidNumber ( value , { min : 1 , max : 12 } ) ;
5249}
53-
5450export function getValidMinuteOrSecond ( value : string ) {
5551 if ( isValidMinuteOrSecond ( value ) ) return value ;
5652 return getValidNumber ( value , { max : 59 } ) ;
5753}
58-
5954type GetValidArrowNumberConfig = {
6055 min : number ;
6156 max : number ;
@@ -91,19 +86,16 @@ export function setMinutes(date: Date, value: string) {
9186 date . setMinutes ( parseInt ( minutes , 10 ) ) ;
9287 return date ;
9388}
94-
9589export function setSeconds ( date : Date , value : string ) {
9690 const seconds = getValidMinuteOrSecond ( value ) ;
9791 date . setSeconds ( parseInt ( seconds , 10 ) ) ;
9892 return date ;
9993}
100-
10194export function setHours ( date : Date , value : string ) {
10295 const hours = getValidHour ( value ) ;
10396 date . setHours ( parseInt ( hours , 10 ) ) ;
10497 return date ;
10598}
106-
10799export function set12Hours ( date : Date , value : string , period : Period ) {
108100 const hours = parseInt ( getValid12Hour ( value ) , 10 ) ;
109101 const convertedHours = convert12HourTo24Hour ( hours , period ) ;
@@ -135,7 +127,6 @@ export function setDateByType(
135127 return date ;
136128 }
137129}
138-
139130export function getDateByType ( date : Date , type : TimePickerType ) {
140131 switch ( type ) {
141132 case "minutes" :
@@ -170,7 +161,6 @@ export function getArrowByType(
170161 return "00" ;
171162 }
172163}
173-
174164/**
175165 * handles value change of 12-hour input
176166 * 12:00 PM is 12:00
@@ -189,7 +179,6 @@ export function convert12HourTo24Hour(hour: number, period: Period) {
189179 }
190180 return hour ;
191181}
192-
193182/**
194183 * time is stored in the 24-hour form,
195184 * but needs to be displayed to the user
0 commit comments