mirror of
https://github.com/jakejarvis/rdapper.git
synced 2025-10-18 20:14:27 -04:00
Refactor date parsing function and improve test coverage
Renamed the `parseWithRegex` function to `parseDateWithRegex` for clarity and consistency. Added a blank line in the `toISO` test to enhance readability. These changes aim to improve code maintainability and ensure better test organization.
This commit is contained in:
@@ -18,6 +18,7 @@ test("toISO parses ISO and common whois formats", () => {
|
||||
|
||||
const mdy = toISO("Jan 02 2023");
|
||||
expect(mdy).toBe("2023-01-02T00:00:00Z");
|
||||
|
||||
// Registrar style timezone offsets
|
||||
const plus0000 = toISO("2025-03-23T10:53:03+0000");
|
||||
expect(plus0000).toBe("2025-03-23T10:53:03Z");
|
||||
|
@@ -22,7 +22,7 @@ export function toISO(
|
||||
for (const re of tryFormats) {
|
||||
const m = raw.match(re);
|
||||
if (!m) continue;
|
||||
const d = parseWithRegex(m, re);
|
||||
const d = parseDateWithRegex(m, re);
|
||||
if (d) return toIsoFromDate(d);
|
||||
}
|
||||
// Fallback to native Date parsing (handles ISO and RFC2822 with TZ)
|
||||
@@ -51,7 +51,10 @@ function toIsoFromDate(d: Date): string | undefined {
|
||||
}
|
||||
}
|
||||
|
||||
function parseWithRegex(m: RegExpMatchArray, _re: RegExp): Date | undefined {
|
||||
function parseDateWithRegex(
|
||||
m: RegExpMatchArray,
|
||||
_re: RegExp,
|
||||
): Date | undefined {
|
||||
const monthMap: Record<string, number> = {
|
||||
jan: 0,
|
||||
feb: 1,
|
||||
|
Reference in New Issue
Block a user