@@ -14,7 +14,7 @@ import { endOfDay } from "date-fns/endOfDay";
1414import { endOfMonth } from "date-fns/endOfMonth" ;
1515import { endOfWeek } from "date-fns/endOfWeek" ;
1616import { endOfYear } from "date-fns/endOfYear" ;
17- import { format , longFormatters } from "date-fns/format" ;
17+ import { format } from "date-fns/format" ;
1818import { getDate } from "date-fns/getDate" ;
1919import { getDay } from "date-fns/getDay" ;
2020import { getHours } from "date-fns/getHours" ;
@@ -100,10 +100,6 @@ function getLocaleScope() {
100100
101101export const DEFAULT_YEAR_ITEM_NUMBER = 12 ;
102102
103- // This RegExp catches symbols escaped by quotes, and also
104- // sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
105- const longFormattingTokensRegExp = / P + p + | P + | p + | ' ' | ' ( ' ' | [ ^ ' ] ) + ( ' | $ ) | ./ g;
106-
107103// ** Date Constructors **
108104
109105export function newDate ( value ?: string | Date | number | null ) : Date {
@@ -166,30 +162,7 @@ export function parseDate(
166162 isValid ( parsedDate ) &&
167163 value === formatDate ( parsedDate , dateFormat , locale ) ;
168164 } else if ( ! isValid ( parsedDate ) ) {
169- const format = ( dateFormat . match ( longFormattingTokensRegExp ) ?? [ ] )
170- . map ( function ( substring ) {
171- const firstCharacter = substring [ 0 ] ;
172- if ( firstCharacter === "p" || firstCharacter === "P" ) {
173- // The type in date-fns is `Record<string, LongFormatter>` so we can do our firstCharacter a bit loos but I don't think that this is a good idea
174- const longFormatter = longFormatters [ firstCharacter ] ! ;
175- return localeObject
176- ? longFormatter ( substring , localeObject . formatLong )
177- : firstCharacter ;
178- }
179- return substring ;
180- } )
181- . join ( "" ) ;
182-
183- if ( value . length > 0 ) {
184- parsedDate = parse ( value , format . slice ( 0 , value . length ) , new Date ( ) , {
185- useAdditionalWeekYearTokens : true ,
186- useAdditionalDayOfYearTokens : true ,
187- } ) ;
188- }
189-
190- if ( ! isValid ( parsedDate ) ) {
191- parsedDate = new Date ( value ) ;
192- }
165+ parsedDate = new Date ( value ) ;
193166 }
194167
195168 return isValid ( parsedDate ) && strictParsingValueMatch ? parsedDate : null ;
0 commit comments