@@ -95,8 +95,8 @@ describe("gateway usage helpers", () => {
9595 endDate : string ,
9696 ) {
9797 const range = expectDateRange ( result ) ;
98- expect ( range . startMs ) . toBe ( testApi . parseDateToMs ( startDate ) ) ;
99- expect ( range . endMs ) . toBe ( testApi . parseDateToMs ( endDate ) ! + dayMs - 1 ) ;
98+ expect ( range . startMs ) . toBe ( Date . parse ( ` ${ startDate } T00:00:00.000Z` ) ) ;
99+ expect ( range . endMs ) . toBe ( Date . parse ( ` ${ endDate } T00:00:00.000Z` ) + dayMs - 1 ) ;
100100 }
101101
102102 function expectDateRange ( result : ReturnType < typeof testApi . resolveDateRange > ) {
@@ -128,26 +128,6 @@ describe("gateway usage helpers", () => {
128128 vi . clearAllMocks ( ) ;
129129 } ) ;
130130
131- it ( "parseDateToMs accepts YYYY-MM-DD and rejects invalid input" , ( ) => {
132- expect ( testApi . parseDateToMs ( "2026-02-05" ) ) . toBe ( Date . UTC ( 2026 , 1 , 5 ) ) ;
133- expect ( testApi . parseDateToMs ( " 2026-02-05 " ) ) . toBe ( Date . UTC ( 2026 , 1 , 5 ) ) ;
134- expect ( testApi . parseDateToMs ( "2026-2-5" ) ) . toBeUndefined ( ) ;
135- expect ( testApi . parseDateToMs ( "nope" ) ) . toBeUndefined ( ) ;
136- expect ( testApi . parseDateToMs ( undefined ) ) . toBeUndefined ( ) ;
137- } ) ;
138-
139- it ( "parseDateToMs rejects out-of-range calendar dates instead of rolling them over" , ( ) => {
140- // Impossible dates that still match the YYYY-MM-DD shape must not silently shift to a real day.
141- expect ( testApi . parseDateToMs ( "2026-02-30" ) ) . toBeUndefined ( ) ; // would roll to Mar 2
142- expect ( testApi . parseDateToMs ( "2026-04-31" ) ) . toBeUndefined ( ) ; // would roll to May 1
143- expect ( testApi . parseDateToMs ( "2025-02-29" ) ) . toBeUndefined ( ) ; // non-leap Feb 29
144- expect ( testApi . parseDateToMs ( "2026-13-01" ) ) . toBeUndefined ( ) ; // month too large
145- expect ( testApi . parseDateToMs ( "2026-00-10" ) ) . toBeUndefined ( ) ; // month zero
146- expect ( testApi . parseDateToMs ( "2026-01-00" ) ) . toBeUndefined ( ) ; // day zero
147- // Real leap day must stay valid (guard against over-rejection).
148- expect ( testApi . parseDateToMs ( "2024-02-29" ) ) . toBe ( Date . UTC ( 2024 , 1 , 29 ) ) ;
149- } ) ;
150-
151131 it . each ( [
152132 [ { startDate : "2026-02-30" } , "invalid startDate" ] ,
153133 [ { endDate : "2026-2-5" } , "invalid endDate" ] ,
@@ -275,34 +255,6 @@ describe("gateway usage helpers", () => {
275255 expect ( vi . mocked ( discoverAllSessions ) ) . not . toHaveBeenCalled ( ) ;
276256 } ) ;
277257
278- it ( "parseUtcOffsetToMinutes supports whole-hour and half-hour offsets" , ( ) => {
279- expect ( testApi . parseUtcOffsetToMinutes ( "UTC-4" ) ) . toBe ( - 240 ) ;
280- expect ( testApi . parseUtcOffsetToMinutes ( "UTC+5:30" ) ) . toBe ( 330 ) ;
281- expect ( testApi . parseUtcOffsetToMinutes ( " UTC+14 " ) ) . toBe ( 14 * 60 ) ;
282- } ) ;
283-
284- it ( "parseUtcOffsetToMinutes rejects invalid offsets" , ( ) => {
285- expect ( testApi . parseUtcOffsetToMinutes ( "UTC+14:30" ) ) . toBeUndefined ( ) ;
286- expect ( testApi . parseUtcOffsetToMinutes ( "UTC+5:99" ) ) . toBeUndefined ( ) ;
287- expect ( testApi . parseUtcOffsetToMinutes ( "UTC+25" ) ) . toBeUndefined ( ) ;
288- expect ( testApi . parseUtcOffsetToMinutes ( "GMT+5" ) ) . toBeUndefined ( ) ;
289- expect ( testApi . parseUtcOffsetToMinutes ( undefined ) ) . toBeUndefined ( ) ;
290- } ) ;
291-
292- it ( "parseDays coerces strings/numbers to integers" , ( ) => {
293- expect ( testApi . parseDays ( 7.9 ) ) . toBe ( 7 ) ;
294- expect ( testApi . parseDays ( "30" ) ) . toBe ( 30 ) ;
295- expect ( testApi . parseDays ( "" ) ) . toBeUndefined ( ) ;
296- expect ( testApi . parseDays ( "nope" ) ) . toBeUndefined ( ) ;
297- } ) ;
298-
299- it ( "parseDays caps day counts before Date arithmetic can overflow" , ( ) => {
300- expect ( testApi . parseDays ( 1e300 ) ) . toBe ( 36600 ) ;
301- expect ( testApi . parseDays ( "1e300" ) ) . toBe ( 36600 ) ;
302- expect ( testApi . parseDays ( Number . MAX_SAFE_INTEGER ) ) . toBe ( 36600 ) ;
303- expect ( testApi . parseDays ( 366 * 100 ) ) . toBe ( 36600 ) ;
304- } ) ;
305-
306258 it ( "resolveDateRange uses explicit start/end as UTC when mode is missing (backward compatible)" , ( ) => {
307259 const result = testApi . resolveDateRange ( {
308260 startDate : "2026-02-01" ,
@@ -311,13 +263,13 @@ describe("gateway usage helpers", () => {
311263 expectUtcDateRange ( result , "2026-02-01" , "2026-02-02" ) ;
312264 } ) ;
313265
314- it ( "resolveDateRange uses explicit UTC mode" , ( ) => {
266+ it ( "resolveDateRange accepts a leap day in explicit UTC mode" , ( ) => {
315267 const result = testApi . resolveDateRange ( {
316- startDate : "2026 -02-01 " ,
317- endDate : "2026-02-02 " ,
268+ startDate : "2024 -02-29 " ,
269+ endDate : "2024-03-01 " ,
318270 mode : "utc" ,
319271 } ) ;
320- expectUtcDateRange ( result , "2026 -02-01 " , "2026-02-02 " ) ;
272+ expectUtcDateRange ( result , "2024 -02-29 " , "2024-03-01 " ) ;
321273 } ) ;
322274
323275 it ( "resolveDateRange uses specific UTC offset for explicit dates" , ( ) => {
@@ -389,7 +341,7 @@ describe("gateway usage helpers", () => {
389341 startDate : "2026-02-01" ,
390342 endDate : "2026-02-02" ,
391343 mode : "specific" ,
392- utcOffset : "bad-value " ,
344+ utcOffset : "UTC+14:30 " ,
393345 } ) ,
394346 ) ;
395347 expect ( missingOffset . startMs ) . toBe ( Date . UTC ( 2026 , 1 , 1 ) ) ;
0 commit comments