File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -624,7 +624,9 @@ protected function getSeconds($ttl)
624624        $ duration$ this parseDateInterval ($ ttl
625625
626626        if  ($ durationinstanceof  DateTimeInterface) {
627-             $ durationnow ()->diffInSeconds ($ durationfalse );
627+             $ durationint ) ceil (
628+                 Carbon::now ()->diffInMilliseconds ($ durationfalse ) / 1000 
629+             );
628630        }
629631
630632        return  (int ) ($ duration0  ? $ duration0 );
Original file line number Diff line number Diff line change 22
33namespace  Illuminate \Tests \Integration \Cache ;
44
5+ use  Illuminate \Cache \Events \KeyWritten ;
56use  Illuminate \Foundation \Testing \LazilyRefreshDatabase ;
67use  Illuminate \Support \Carbon ;
78use  Illuminate \Support \Facades \Cache ;
9+ use  Illuminate \Support \Facades \Event ;
810use  Orchestra \Testbench \Attributes \WithMigration ;
911use  Orchestra \Testbench \TestCase ;
1012
@@ -235,4 +237,21 @@ public function testItImplicitlyClearsTtlKeysFromFileDriver()
235237        $ this assertFalse ($ cachegetFilesystem ()->exists ($ cachepath ('illuminate:cache:flexible:created:count ' )));
236238        $ this assertTrue ($ cachemissing ('illuminate:cache:flexible:created:count ' ));
237239    }
240+ 
241+     public  function  testItRoundsDateTimeValuesToAccountForTimePassedDuringScriptExecution ()
242+     {
243+         // do not freeze time as this test depends on time progressing duration execution. 
244+         $ cachedriver ('array ' );
245+         $ events
246+         Event::listen (function  (KeyWritten $ eventuse  (&$ events
247+             $ events$ event
248+         });
249+ 
250+         $ result$ cacheput ('foo ' , 'bar ' , now ()->addSecond ());
251+ 
252+         $ this assertTrue ($ result
253+         $ this assertCount (1 , $ events
254+         $ this assertSame ('foo ' , $ events0 ]->key );
255+         $ this assertSame (1 , $ events0 ]->seconds );
256+     }
238257}
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments