Skip to content

Commit 16b9c94

Browse files
maranomynetlaug
authored andcommitted
fix: Remove weird, redundant code, fix bug illustrated in #45ce1fa3
1 parent 883353c commit 16b9c94

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

src/date_utils.ts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { endOfDay } from "date-fns/endOfDay";
1414
import { endOfMonth } from "date-fns/endOfMonth";
1515
import { endOfWeek } from "date-fns/endOfWeek";
1616
import { endOfYear } from "date-fns/endOfYear";
17-
import { format, longFormatters } from "date-fns/format";
17+
import { format } from "date-fns/format";
1818
import { getDate } from "date-fns/getDate";
1919
import { getDay } from "date-fns/getDay";
2020
import { getHours } from "date-fns/getHours";
@@ -100,10 +100,6 @@ function getLocaleScope() {
100100

101101
export 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

109105
export 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

Comments
 (0)