@@ -32,9 +32,9 @@ describe('findClosestEnabledDate', () => {
3232 disableFuture : false ,
3333 disablePast : false ,
3434 timezone : 'default' ,
35- } ) ! ;
35+ } ) ;
3636
37- expect ( adapterToUse . isSameDay ( result , adapterToUse . date ( '2000-01-01' ) ) ) . to . equal ( true ) ;
37+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2000-01-01' ) ) ;
3838 } ) ;
3939
4040 it ( 'should return next 18th going from 10th' , ( ) => {
@@ -47,9 +47,9 @@ describe('findClosestEnabledDate', () => {
4747 disableFuture : false ,
4848 disablePast : false ,
4949 timezone : 'default' ,
50- } ) ! ;
50+ } ) ;
5151
52- expect ( adapterToUse . isSameDay ( result , adapterToUse . date ( '2018-08-18' ) ) ) . to . equal ( true ) ;
52+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2018-08-18' ) ) ;
5353 } ) ;
5454
5555 it ( 'should return previous 18th going from 1st' , ( ) => {
@@ -62,9 +62,9 @@ describe('findClosestEnabledDate', () => {
6262 disableFuture : false ,
6363 disablePast : false ,
6464 timezone : 'default' ,
65- } ) ! ;
65+ } ) ;
6666
67- expect ( adapterToUse . isSameDay ( result , adapterToUse . date ( '2018-07-18' ) ) ) . to . equal ( true ) ;
67+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2018-07-18' ) ) ;
6868 } ) ;
6969
7070 it ( 'should return future 18th if disablePast' , ( ) => {
@@ -78,7 +78,7 @@ describe('findClosestEnabledDate', () => {
7878 disableFuture : false ,
7979 disablePast : true ,
8080 timezone : 'default' ,
81- } ) ! ;
81+ } ) ;
8282
8383 expect ( adapterToUse . isBefore ( result , today ) ) . to . equal ( false ) ;
8484 expect ( adapterToUse . isBefore ( result , adapterToUse . addDays ( today , 31 ) ) ) . to . equal ( true ) ;
@@ -95,9 +95,9 @@ describe('findClosestEnabledDate', () => {
9595 disableFuture : true ,
9696 disablePast : true ,
9797 timezone : 'default' ,
98- } ) ! ;
98+ } ) ;
9999
100- expect ( adapterToUse . isSameDay ( result , today ) ) . to . equal ( true ) ;
100+ expect ( result ) . toEqualDateTime ( today ) ;
101101 } ) ;
102102
103103 it ( 'should return now with given time part if disablePast and now is valid' , ( ) => {
@@ -113,13 +113,13 @@ describe('findClosestEnabledDate', () => {
113113 disableFuture : false ,
114114 disablePast : true ,
115115 timezone : 'default' ,
116- } ) ! ;
116+ } ) ;
117117
118118 expect ( result ) . toEqualDateTime ( adapterToUse . addDays ( tryDate , 1 ) ) ;
119119 clock . reset ( ) ;
120120 } ) ;
121121
122- it ( 'should fallback to today if disablePast+disableFuture and now is invalid' , ( ) => {
122+ it ( 'should return `null` when disablePast+disableFuture and now is invalid' , ( ) => {
123123 const today = adapterToUse . date ( ) ;
124124 const result = findClosestEnabledDate ( {
125125 date : adapterToUse . date ( '2000-01-01' ) ,
@@ -132,7 +132,7 @@ describe('findClosestEnabledDate', () => {
132132 timezone : 'default' ,
133133 } ) ;
134134
135- expect ( adapterToUse . isEqual ( result , adapterToUse . date ( ) ) ) ;
135+ expect ( result ) . to . equal ( null ) ;
136136 } ) ;
137137
138138 it ( 'should return minDate if it is after the date and valid' , ( ) => {
@@ -145,9 +145,9 @@ describe('findClosestEnabledDate', () => {
145145 disableFuture : false ,
146146 disablePast : false ,
147147 timezone : 'default' ,
148- } ) ! ;
148+ } ) ;
149149
150- expect ( adapterToUse . isSameDay ( result , adapterToUse . date ( '2018-08-18' ) ) ) . to . equal ( true ) ;
150+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2018-08-18' ) ) ;
151151 } ) ;
152152
153153 it ( 'should return next 18th after minDate' , ( ) => {
@@ -160,9 +160,27 @@ describe('findClosestEnabledDate', () => {
160160 disableFuture : false ,
161161 disablePast : false ,
162162 timezone : 'default' ,
163- } ) ! ;
163+ } ) ;
164+
165+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2018-08-18' ) ) ;
166+ } ) ;
167+
168+ it ( 'should keep the time of the `date` when `disablePast`' , ( ) => {
169+ const clock = useFakeTimers ( { now : new Date ( '2000-01-02T11:12:13.123Z' ) } ) ;
170+
171+ const result = findClosestEnabledDate ( {
172+ date : adapterToUse . date ( '2000-01-01T11:12:13.550Z' ) ,
173+ minDate : adapterToUse . date ( '1900-01-01' ) ,
174+ maxDate : adapterToUse . date ( '2100-01-01' ) ,
175+ utils : adapterToUse ,
176+ isDateDisabled : ( ) => false ,
177+ disableFuture : false ,
178+ disablePast : true ,
179+ timezone : 'default' ,
180+ } ) ;
164181
165- expect ( adapterToUse . isSameDay ( result , adapterToUse . date ( '2018-08-18' ) ) ) . to . equal ( true ) ;
182+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2000-01-02T11:12:13.550Z' ) ) ;
183+ clock . reset ( ) ;
166184 } ) ;
167185
168186 it ( 'should return maxDate if it is before the date and valid' , ( ) => {
@@ -175,9 +193,9 @@ describe('findClosestEnabledDate', () => {
175193 disableFuture : false ,
176194 disablePast : false ,
177195 timezone : 'default' ,
178- } ) ! ;
196+ } ) ;
179197
180- expect ( adapterToUse . isSameDay ( result , adapterToUse . date ( '2018-07-18' ) ) ) . to . equal ( true ) ;
198+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2018-07-18' ) ) ;
181199 } ) ;
182200
183201 it ( 'should return previous 18th before maxDate' , ( ) => {
@@ -190,9 +208,9 @@ describe('findClosestEnabledDate', () => {
190208 disableFuture : false ,
191209 disablePast : false ,
192210 timezone : 'default' ,
193- } ) ! ;
211+ } ) ;
194212
195- expect ( adapterToUse . isSameDay ( result , adapterToUse . date ( '2018-07-18' ) ) ) . to . equal ( true ) ;
213+ expect ( result ) . toEqualDateTime ( adapterToUse . date ( '2018-07-18' ) ) ;
196214 } ) ;
197215
198216 it ( 'should return null if minDate is after maxDate' , ( ) => {
@@ -205,7 +223,7 @@ describe('findClosestEnabledDate', () => {
205223 disableFuture : false ,
206224 disablePast : false ,
207225 timezone : 'default' ,
208- } ) ! ;
226+ } ) ;
209227
210228 expect ( result ) . to . equal ( null ) ;
211229 } ) ;
0 commit comments