@@ -2,131 +2,64 @@ import { UtcDateFromStringSchema, UtcDateTimeFromStringSchema } from "@src/utils
22
33describe ( "utils-date" , ( ) => {
44 describe ( "UtcDateFromStringSchema" , ( ) => {
5- it ( "should parse winter date" , ( ) => {
6- const actual = UtcDateFromStringSchema . parse ( "2026-01-01" ) ;
7-
8- expect ( actual ) . toEqual ( new Date ( "2026-01-01" ) ) ;
9- } ) ;
10-
11- it ( "should parse summer date" , ( ) => {
12- const actual = UtcDateFromStringSchema . parse ( "2026-06-01" ) ;
13-
14- expect ( actual ) . toEqual ( new Date ( "2026-06-01" ) ) ;
15- } ) ;
16-
17- it ( "should throw on invalid date" , ( ) => {
18- const given = "2026-13-01" ;
19-
20- expect ( ( ) => {
21- UtcDateFromStringSchema . parse ( given ) ;
22- } ) . toThrow ( ) ;
23- } ) ;
24-
25- it ( "should throw on date without dashes" , ( ) => {
26- const given = "20261301" ;
27-
28- expect ( ( ) => {
29- UtcDateFromStringSchema . parse ( given ) ;
30- } ) . toThrow ( ) ;
31- } ) ;
32-
33- it ( "should throw on badly formed date" , ( ) => {
34- const given = "Sausages" ;
35-
36- expect ( ( ) => {
37- UtcDateFromStringSchema . parse ( given ) ;
38- } ) . toThrow ( ) ;
39- } ) ;
40- } ) ;
41-
42- describe ( "UtcDateTimeFromStringSchema with Zulu time" , ( ) => {
43- it ( "should parse winter date" , ( ) => {
44- const actual = UtcDateTimeFromStringSchema . parse ( "2026-01-01T13:16:02Z" ) ;
45-
46- expect ( actual ) . toEqual ( new Date ( "2026-01-01T13:16:02.000Z" ) ) ;
47- } ) ;
48-
49- it ( "should parse summer date" , ( ) => {
50- const actual = UtcDateTimeFromStringSchema . parse ( "2026-06-01T13:16:02Z" ) ;
51-
52- expect ( actual ) . toEqual ( new Date ( "2026-06-01T13:16:02.000Z" ) ) ;
53- } ) ;
54-
55- it ( "should throw on invalid date" , ( ) => {
56- const given = "2026-13-01T13:16:02Z" ;
57-
58- expect ( ( ) => {
59- UtcDateTimeFromStringSchema . parse ( given ) ;
60- } ) . toThrow ( ) ;
61- } ) ;
62-
63- it ( "should throw on invalid time" , ( ) => {
64- const given = "2026-12-01T25:16:02Z" ;
65-
5+ it . each ( [
6+ { description : "winter date" , input : "2026-01-01" } ,
7+ { description : "summer date" , input : "2026-06-01" } ,
8+ ] ) ( "should parse $description" , ( { input } ) => {
9+ const actual = UtcDateFromStringSchema . parse ( input ) ;
10+ expect ( actual ) . toEqual ( new Date ( input ) ) ;
11+ } ) ;
12+
13+ it . each ( [
14+ { description : "invalid date" , input : "2026-13-01" } ,
15+ { description : "date without dashes" , input : "20261301" } ,
16+ { description : "badly formed date" , input : "Sausages" } ,
17+ ] ) ( "should throw on $description" , ( { input } ) => {
6618 expect ( ( ) => {
67- UtcDateTimeFromStringSchema . parse ( given ) ;
68- } ) . toThrow ( ) ;
69- } ) ;
70-
71- it ( "should throw on date without dashes" , ( ) => {
72- const given = "20261301T13:16:02Z" ;
73-
74- expect ( ( ) => {
75- UtcDateTimeFromStringSchema . parse ( given ) ;
76- } ) . toThrow ( ) ;
77- } ) ;
78-
79- it ( "should throw on badly formed date" , ( ) => {
80- const given = "SausagesT13:16:02Z" ;
81-
82- expect ( ( ) => {
83- UtcDateTimeFromStringSchema . parse ( given ) ;
19+ UtcDateFromStringSchema . parse ( input ) ;
8420 } ) . toThrow ( ) ;
8521 } ) ;
8622 } ) ;
8723
88- describe ( "UtcDateTimeFromStringSchema with offset time" , ( ) => {
89- it ( "should parse winter date" , ( ) => {
90- const actual = UtcDateTimeFromStringSchema . parse ( "2026-01-01T13:16:02+02:00" ) ;
91-
92- expect ( actual ) . toEqual ( new Date ( "2026-01-01T11:16:02.000Z" ) ) ;
93- } ) ;
94-
95- it ( "should parse summer date" , ( ) => {
96- const actual = UtcDateTimeFromStringSchema . parse ( "2026-06-01T13:16:02+02:00" ) ;
97-
98- expect ( actual ) . toEqual ( new Date ( "2026-06-01T11:16:02.000Z" ) ) ;
99- } ) ;
100-
101- it ( "should throw on invalid date" , ( ) => {
102- const given = "2026-13-01T13:16:02+02:00" ;
103-
104- expect ( ( ) => {
105- UtcDateTimeFromStringSchema . parse ( given ) ;
106- } ) . toThrow ( ) ;
107- } ) ;
108-
109- it ( "should throw on invalid time" , ( ) => {
110- const given = "2026-12-01T25:16:02+02:00" ;
111-
112- expect ( ( ) => {
113- UtcDateTimeFromStringSchema . parse ( given ) ;
114- } ) . toThrow ( ) ;
115- } ) ;
116-
117- it ( "should throw on date without dashes" , ( ) => {
118- const given = "20261301T13:16:02+02:00" ;
119-
120- expect ( ( ) => {
121- UtcDateTimeFromStringSchema . parse ( given ) ;
122- } ) . toThrow ( ) ;
123- } ) ;
124-
125- it ( "should throw on badly formed date" , ( ) => {
126- const given = "SausagesT13:16:02+02:00" ;
127-
24+ describe ( "UtcDateTimeFromStringSchema" , ( ) => {
25+ it . each ( [
26+ {
27+ description : "winter date (Zulu)" ,
28+ input : "2026-01-01T13:16:02Z" ,
29+ expected : "2026-01-01T13:16:02.000Z" ,
30+ } ,
31+ {
32+ description : "summer date (Zulu)" ,
33+ input : "2026-06-01T13:16:02Z" ,
34+ expected : "2026-06-01T13:16:02.000Z" ,
35+ } ,
36+ {
37+ description : "winter date (Offset)" ,
38+ input : "2026-01-01T13:16:02+02:00" ,
39+ expected : "2026-01-01T11:16:02.000Z" ,
40+ } ,
41+ {
42+ description : "summer date (Offset)" ,
43+ input : "2026-06-01T13:16:02+02:00" ,
44+ expected : "2026-06-01T11:16:02.000Z" ,
45+ } ,
46+ ] ) ( "should parse $description" , ( { input, expected } ) => {
47+ const actual = UtcDateTimeFromStringSchema . parse ( input ) ;
48+ expect ( actual ) . toEqual ( new Date ( expected ) ) ;
49+ } ) ;
50+
51+ it . each ( [
52+ { description : "invalid date (Zulu)" , input : "2026-13-01T13:16:02Z" } ,
53+ { description : "invalid time (Zulu)" , input : "2026-12-01T25:16:02Z" } ,
54+ { description : "date without dashes (Zulu)" , input : "20261301T13:16:02Z" } ,
55+ { description : "badly formed string (Zulu)" , input : "SausagesT13:16:02Z" } ,
56+ { description : "invalid date (Offset)" , input : "2026-13-01T13:16:02+02:00" } ,
57+ { description : "invalid time (Offset)" , input : "2026-12-01T25:16:02+02:00" } ,
58+ { description : "date without dashes (Offset)" , input : "20261301T13:16:02+02:00" } ,
59+ { description : "badly formed string (Offset)" , input : "SausagesT13:16:02+02:00" } ,
60+ ] ) ( "should throw on $description" , ( { input } ) => {
12861 expect ( ( ) => {
129- UtcDateTimeFromStringSchema . parse ( given ) ;
62+ UtcDateTimeFromStringSchema . parse ( input ) ;
13063 } ) . toThrow ( ) ;
13164 } ) ;
13265 } ) ;
0 commit comments