@@ -926,6 +926,41 @@ describe("date_utils", () => {
926926 } ) ;
927927 } ) ;
928928
929+ describe ( "isTimeInDisabledRange edge cases" , ( ) => {
930+ it ( "throws when either minTime or maxTime is missing" , ( ) => {
931+ expect ( ( ) =>
932+ isTimeInDisabledRange ( newDate ( ) , { minTime : newDate ( ) } ) ,
933+ ) . toThrow ( "Both minTime and maxTime props required" ) ;
934+ } ) ;
935+
936+ it ( "returns false when isWithinInterval throws" , async ( ) => {
937+ jest . doMock ( "date-fns" , ( ) => {
938+ const actual = jest . requireActual ( "date-fns" ) ;
939+ return {
940+ ...actual ,
941+ isWithinInterval : ( ) => {
942+ throw new Error ( "boom" ) ;
943+ } ,
944+ } ;
945+ } ) ;
946+
947+ try {
948+ const { isTimeInDisabledRange : mockedIsTimeInDisabledRange } =
949+ await import ( "../date_utils" ) ;
950+
951+ expect (
952+ mockedIsTimeInDisabledRange ( new Date ( ) , {
953+ minTime : new Date ( ) ,
954+ maxTime : new Date ( ) ,
955+ } ) ,
956+ ) . toBe ( false ) ;
957+ } finally {
958+ jest . resetModules ( ) ;
959+ jest . dontMock ( "date-fns" ) ;
960+ }
961+ } ) ;
962+ } ) ;
963+
929964 describe ( "isDayInRange" , ( ) => {
930965 it ( "should tell if day is in range" , ( ) => {
931966 const day = newDate ( "2016-02-15 09:40" ) ;
@@ -1105,6 +1140,14 @@ describe("date_utils", () => {
11051140
11061141 expect ( isMonthInRange ( startDate , endDate , 5 , day ) ) . toBe ( true ) ;
11071142 } ) ;
1143+
1144+ it ( "should return false when the start date is after the end date" , ( ) => {
1145+ const day = newDate ( "2024-01-01" ) ;
1146+ const startDate = newDate ( "2024-02-01" ) ;
1147+ const endDate = newDate ( "2024-01-01" ) ;
1148+
1149+ expect ( isMonthInRange ( startDate , endDate , 1 , day ) ) . toBe ( false ) ;
1150+ } ) ;
11081151 } ) ;
11091152
11101153 describe ( "getStartOfYear" , ( ) => {
@@ -1139,6 +1182,14 @@ describe("date_utils", () => {
11391182
11401183 expect ( isQuarterInRange ( startDate , endDate , 5 , day ) ) . toBe ( true ) ;
11411184 } ) ;
1185+
1186+ it ( "should return false when the start quarter is after the end quarter" , ( ) => {
1187+ const day = newDate ( "2024-01-01" ) ;
1188+ const startDate = newDate ( "2024-10-01" ) ;
1189+ const endDate = newDate ( "2024-04-01" ) ;
1190+
1191+ expect ( isQuarterInRange ( startDate , endDate , 1 , day ) ) . toBe ( false ) ;
1192+ } ) ;
11421193 } ) ;
11431194
11441195 describe ( "isYearInRange" , ( ) => {
@@ -1580,14 +1631,33 @@ describe("date_utils", () => {
15801631 } ) ;
15811632
15821633 describe ( "isDayInRange error handling" , ( ) => {
1583- it ( "returns false when isWithinInterval throws" , ( ) => {
1584- const testDate = new Date ( "2024-01-15" ) ;
1585- const invalidStartDate = new Date ( "invalid" ) ;
1586- const invalidEndDate = new Date ( "also-invalid" ) ;
1587-
1588- const result = isDayInRange ( testDate , invalidStartDate , invalidEndDate ) ;
1634+ it ( "returns false when isWithinInterval throws" , async ( ) => {
1635+ jest . doMock ( "date-fns" , ( ) => {
1636+ const actual = jest . requireActual ( "date-fns" ) ;
1637+ return {
1638+ ...actual ,
1639+ isWithinInterval : ( ) => {
1640+ throw new Error ( "boom" ) ;
1641+ } ,
1642+ } ;
1643+ } ) ;
15891644
1590- expect ( result ) . toBe ( false ) ;
1645+ try {
1646+ const { isDayInRange : mockedIsDayInRange } = await import (
1647+ "../date_utils"
1648+ ) ;
1649+
1650+ expect (
1651+ mockedIsDayInRange (
1652+ new Date ( "2024-01-15" ) ,
1653+ new Date ( "2024-01-10" ) ,
1654+ new Date ( "2024-01-20" ) ,
1655+ ) ,
1656+ ) . toBe ( false ) ;
1657+ } finally {
1658+ jest . resetModules ( ) ;
1659+ jest . dontMock ( "date-fns" ) ;
1660+ }
15911661 } ) ;
15921662
15931663 it ( "returns true for dates inside a valid range" , ( ) => {
0 commit comments