Forum Discussion

KPP's avatar
KPP
New Contributor
4 years ago
Solved

Script assertion to check date time between min and max

I'll appreciate your time and expertise since I'm not sure what is wrong. Following groovy script works if def expectedMinDateTime is exact as the epoch conversion. However, I was thinking it should...
  • PrathapR's avatar
    4 years ago

    KPP 

    Why can't you get Min(CST&/ Current Time) and Max(PST(adding 2 hrs)) times in Epoch and compare your response time(as per my understand it's in Epoch).

     

    If this scenarios works for you and I understood your requirement correctly, hope below code helps you.

     

    Code::

    import java.util.concurrent.TimeUnit
    
    long epoch = System.currentTimeMillis() //Gives current time in Epoch in milliseconds
    long epochin2hr = epoch + TimeUnit.MINUTES.toMillis(120) //Adds 120 mins to current time in milliseconds
    
    long responsetime = 1234567890 //get this from your response as like above you did and convert to Millis
    
    assert (responsetime <= epoch && responsetime < epochin2hr) // You can modify first condition(<=) depends on your requirement, like response time should be less than equal or greater than equal to current time.