remove need for hardcoded 12am test

This commit is contained in:
2024-05-23 20:29:05 -05:00
parent 98418014d3
commit 834aafe06d
+7 -6
View File
@@ -85,8 +85,13 @@ function inferSeparators(value: string, isAM: boolean, isPM: boolean) {
} }
} else if (length === 2) { } else if (length === 2) {
if (isPM || isAM) { if (isPM || isAM) {
inferredMillis = parse(value) * MILLIS_PER_HOUR; if (value === '12' && isAM) {
if (isAM || (isPM && value === '12')) { inferredMillis = 0;
} else {
inferredMillis = parse(value) * MILLIS_PER_HOUR;
}
if (isAM || value === '12') {
// this ensures we dont add 12 hours in the end // this ensures we dont add 12 hours in the end
addAM = 12; addAM = 12;
} }
@@ -114,10 +119,6 @@ function inferSeparators(value: string, isAM: boolean, isPM: boolean) {
export const forgivingStringToMillis = (value: string): number => { export const forgivingStringToMillis = (value: string): number => {
value = value.toLowerCase(); value = value.toLowerCase();
if (value === '12am' || value === '12a') {
return 0;
}
const { isAM, isPM, value: parsingValue } = checkAmPm(value); const { isAM, isPM, value: parsingValue } = checkAmPm(value);
const maybeMillisFromMatchers = checkMatchers(parsingValue); const maybeMillisFromMatchers = checkMatchers(parsingValue);
if (maybeMillisFromMatchers !== null) { if (maybeMillisFromMatchers !== null) {