Skip to content

Commit fa2c55e

Browse files
committed
All date and times should have at least two parts matching
1 parent 16d51b1 commit fa2c55e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/formats/datetime.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ const rfc3339 = [
5858
},
5959
];
6060

61+
function matchFilter(matches: RegExpMatchArray | null): boolean {
62+
if (!matches) {
63+
return false;
64+
}
65+
66+
const truthyMatches = matches.filter((match) => !!match);
67+
68+
return truthyMatches.length > 2;
69+
}
70+
6171
function inferRFC3339(value: string): JSONDateTimeFormat | undefined {
6272
const rfc3339Matches = rfc3339
6373
.map((rfc) => {
@@ -67,7 +77,7 @@ function inferRFC3339(value: string): JSONDateTimeFormat | undefined {
6777
extensions: rfc.extensions,
6878
};
6979
})
70-
.filter((rfc) => rfc.matches !== null && rfc.matches.some((i) => i));
80+
.filter((rfc) => matchFilter(rfc.matches));
7181

7282
const rfc3339BestMatch = rfc3339Matches.sort(
7383
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

tests/stringFormats.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,12 @@ describe("credit cards", () => {
811811
},
812812
);
813813
});
814+
815+
describe("without format", () => {
816+
test.each(["46"])("%p should be inferred as having no format", (value) => {
817+
expect(inferType(value)).toEqual({
818+
name: "string",
819+
value,
820+
});
821+
});
822+
});

0 commit comments

Comments
 (0)