@@ -101,35 +101,31 @@ export function isDateTimeCol(col: QueryColumn): boolean {
101101}
102102
103103function _toAmPm ( rawTimeFormat : string , toAMPM : boolean ) {
104- if ( ! toAMPM )
105- return rawTimeFormat ;
104+ if ( ! toAMPM ) return rawTimeFormat ;
106105
107- if ( rawTimeFormat . indexOf ( ' a' ) > - 1 )
108- return rawTimeFormat ;
106+ if ( rawTimeFormat . indexOf ( ' a' ) > - 1 ) return rawTimeFormat ;
109107
110108 return rawTimeFormat . replace ( 'HH' , 'hh' ) + ' a' ;
111-
112109}
113110
114- export function getPickerTimeFormatWithPrecision ( timeFormat : string , showMinute : boolean , showSeconds : boolean , showMilliSeconds : boolean ) {
111+ export function getPickerTimeFormatWithPrecision (
112+ timeFormat : string ,
113+ showMinute : boolean ,
114+ showSeconds : boolean ,
115+ showMilliSeconds : boolean
116+ ) {
115117 const useAmPm = timeFormat . indexOf ( ' a' ) > - 1 ;
116- if ( timeFormat . indexOf ( '.SSS' ) > - 1 )
117- return timeFormat ;
118+ if ( timeFormat . indexOf ( '.SSS' ) > - 1 ) return timeFormat ;
118119
119- if ( showMilliSeconds )
120- return _toAmPm ( ISO_LONG_TIME_FORMAT_STRING , useAmPm ) ;
120+ if ( showMilliSeconds ) return _toAmPm ( ISO_LONG_TIME_FORMAT_STRING , useAmPm ) ;
121121
122- if ( timeFormat . indexOf ( ':ss' ) > - 1 )
123- return timeFormat ;
122+ if ( timeFormat . indexOf ( ':ss' ) > - 1 ) return timeFormat ;
124123
125- if ( showSeconds )
126- return _toAmPm ( ISO_TIME_FORMAT_STRING , useAmPm ) ;
124+ if ( showSeconds ) return _toAmPm ( ISO_TIME_FORMAT_STRING , useAmPm ) ;
127125
128- if ( timeFormat . indexOf ( ':mm' ) > - 1 )
129- return timeFormat ;
126+ if ( timeFormat . indexOf ( ':mm' ) > - 1 ) return timeFormat ;
130127
131- if ( showMinute )
132- return _toAmPm ( ISO_SHORT_TIME_FORMAT_STRING , useAmPm ) ;
128+ if ( showMinute ) return _toAmPm ( ISO_SHORT_TIME_FORMAT_STRING , useAmPm ) ;
133129
134130 return timeFormat ;
135131}
@@ -138,11 +134,19 @@ export function getPickerTimeFormatWithPrecision(timeFormat: string, showMinute:
138134// for example:
139135// 'yyyy-MM-dd HH:mm' -> 'yyyy-MM-dd HH:mm:ss' if showSeconds is true and showMilliSeconds is false
140136// 'yyyy-MM-dd hh:mm a' -> 'yyyy-MM-dd hh:mm:ss.SSS a' if showSeconds is true and showMilliSeconds is true
141- export function getPickerFormatWithPrecision ( rawDateTimeFormat : string , showMinute : boolean , showSeconds : boolean , showMilliSeconds : boolean ) {
137+ export function getPickerFormatWithPrecision (
138+ rawDateTimeFormat : string ,
139+ showMinute : boolean ,
140+ showSeconds : boolean ,
141+ showMilliSeconds : boolean
142+ ) {
142143 const parts = splitDateTimeFormat ( rawDateTimeFormat ) ;
143- if ( parts . length === 1 )
144- return parts [ 0 ] ;
145- return ( parts [ 0 ] + ' ' + getPickerTimeFormatWithPrecision ( parts [ 1 ] , showMinute , showSeconds , showMilliSeconds ) ) . trim ( ) ;
144+ if ( parts . length === 1 ) return parts [ 0 ] ;
145+ return (
146+ parts [ 0 ] +
147+ ' ' +
148+ getPickerTimeFormatWithPrecision ( parts [ 1 ] , showMinute , showSeconds , showMilliSeconds )
149+ ) . trim ( ) ;
146150}
147151
148152export function getPickerDateAndTimeFormat (
@@ -152,25 +156,38 @@ export function getPickerDateAndTimeFormat(
152156) : { dateFormat : string ; timeFormat : string } {
153157 const hasMsPrecision = initDate ?. getMilliseconds ( ) > 0 ;
154158 const hasSecondsPrecision = hasMsPrecision || initDate ?. getSeconds ( ) > 0 ;
155- const hasMinutePrecision = hasSecondsPrecision || initDate ?. getMinutes ( ) > 0 || initDate ?. getHours ( ) > 0 ;
159+ const hasMinutePrecision = hasSecondsPrecision || initDate ?. getMinutes ( ) > 0 || initDate ?. getHours ( ) > 0 ;
156160
157161 const dateFormat_ = getColDateFormat ( column , hideTime ? DateFormatType . Date : undefined , column . isDateOnlyColumn ) ;
158- let dateFormat = column . isTimeColumn || column . isDateOnlyColumn ? dateFormat_ : getPickerFormatWithPrecision ( dateFormat_ , hasMinutePrecision , hasSecondsPrecision , hasMsPrecision ) ;
162+ let dateFormat =
163+ column . isTimeColumn || column . isDateOnlyColumn
164+ ? dateFormat_
165+ : getPickerFormatWithPrecision ( dateFormat_ , hasMinutePrecision , hasSecondsPrecision , hasMsPrecision ) ;
159166 let timeFormat : string ;
160167 if ( ! hideTime ) {
161168 if ( column . isTimeColumn ) {
162169 timeFormat = parseFNSTimeFormat ( getColDateFormat ( column , column ?. format ?? DateFormatType . Time ) ) ;
163- timeFormat = getPickerTimeFormatWithPrecision ( timeFormat , hasMinutePrecision , hasSecondsPrecision , hasMsPrecision ) ;
170+ timeFormat = getPickerTimeFormatWithPrecision (
171+ timeFormat ,
172+ hasMinutePrecision ,
173+ hasSecondsPrecision ,
174+ hasMsPrecision
175+ ) ;
164176 dateFormat = timeFormat ;
165177 } else {
166178 timeFormat = parseDateFNSTimeFormat ( dateFormat ) ;
167179 }
168180 }
169181
170- return { dateFormat, timeFormat } ;
182+ return { dateFormat, timeFormat } ;
171183}
172184
173- export function getDateFromISO ( value : string , queryColumn : QueryColumn , allowRelativeInput ?: boolean , minDate ?: Date ) : Date {
185+ export function getDateFromISO (
186+ value : string ,
187+ queryColumn : QueryColumn ,
188+ allowRelativeInput ?: boolean ,
189+ minDate ?: Date
190+ ) : Date {
174191 if ( ! value || ( allowRelativeInput && isRelativeDateFilterValue ( value ) ) ) return undefined ;
175192
176193 if ( queryColumn . isTimeColumn ) {
@@ -182,12 +199,10 @@ export function getDateFromISO(value: string, queryColumn: QueryColumn, allowRel
182199
183200export function formatDateTimeDisplayValueForUpdate ( vd : ValueDescriptor , queryColumn : QueryColumn ) : string {
184201 const isoValue = vd ?. raw ;
185- if ( ! isoValue )
186- return null ;
202+ if ( ! isoValue ) return null ;
187203 const date = getDateFromISO ( isoValue , queryColumn ) ;
188- const { dateFormat, timeFormat} = getPickerDateAndTimeFormat ( queryColumn , false , date ) ;
189- if ( queryColumn . isTimeColumn )
190- return formatTime ( isoValue , timeFormat ) ;
204+ const { dateFormat, timeFormat } = getPickerDateAndTimeFormat ( queryColumn , false , date ) ;
205+ if ( queryColumn . isTimeColumn ) return formatTime ( isoValue , timeFormat ) ;
191206 return formatDate ( date , null , dateFormat ) ;
192207}
193208
@@ -469,12 +484,9 @@ export function parseTime(time: string | Date): Date {
469484 if ( ! time ) return null ;
470485
471486 if ( time instanceof Date ) {
472- if ( isValid ( time ) )
473- return time ;
474- return null ;
475- }
476- else if ( typeof time !== 'string' )
487+ if ( isValid ( time ) ) return time ;
477488 return null ;
489+ } else if ( typeof time !== 'string' ) return null ;
478490
479491 // Regular expressions for different time formats
480492 const timeFormats = [
0 commit comments