File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -647,8 +647,19 @@ function isDateStringWithTimeZone(str: string) {
647
647
return / z $ / i. test ( str ) || / [ + - ] \d \d : \d \d $ / . test ( str ) ;
648
648
}
649
649
650
+ /**
651
+ * Trims leading and trailing spaces from a string and replaces multiple consecutive spaces with a single space.
652
+ *
653
+ * @param str - The input string to process.
654
+ * @returns The processed string with trimmed spaces and single spaces between words.
655
+ */
656
+ function trimExtraSpaces ( str : string ) {
657
+ return str . trim ( ) . replace ( / \s + / g, ' ' ) ;
658
+ }
659
+
650
660
export function parseDateFromString ( str : string , format : string , timeZone ?: string ) : DateTime {
651
- let date = parseDate ( { input : str , format, timeZone} ) ;
661
+ const input = typeof str === 'string' ? trimExtraSpaces ( str ) : str ;
662
+ let date = parseDate ( { input, format, timeZone} ) ;
652
663
if ( date . isValid ( ) ) {
653
664
if ( timeZone && ! isDateStringWithTimeZone ( str ) ) {
654
665
const time = parseDate ( { input : str , format} ) ;
Original file line number Diff line number Diff line change @@ -224,8 +224,8 @@ export function useRangeDateFieldState(props: RangeDateFieldStateOptions): Range
224
224
225
225
function setValueFromString ( str : string ) {
226
226
const list = str . split ( delimiter ) ;
227
- const start = parseDateFromString ( list ?. [ 0 ] ?. trim ( ) , format , timeZone ) ;
228
- const end = parseDateFromString ( list ?. [ 1 ] ?. trim ( ) , format , timeZone ) ;
227
+ const start = parseDateFromString ( list ?. [ 0 ] , format , timeZone ) ;
228
+ const end = parseDateFromString ( list ?. [ 1 ] , format , timeZone ) ;
229
229
const range = { start, end} ;
230
230
if ( range . start . isValid ( ) && range . end . isValid ( ) ) {
231
231
handleUpdateRange ( range ) ;
You can’t perform that action at this time.
0 commit comments