cancel
Showing results for 
Search instead for 
Did you mean: 

Ready API 3.3.1 - messed date up

SOLVED
Highlighted
Community Hero

Re: Ready API 3.3.1 - messed date up

Right.


Regards,
Rao.
Highlighted
Occasional Contributor

Re: Ready API 3.3.1 - messed date up

@nmrao - Thanks for your time and patience in this date thing.  

 

I also wanted to note, that if anyone is just using the date and doesn't need anything to do with time you can use the following code:

XML:

${java.time.LocalDate.now()}  This will default to the format YYYY-MM-dd

 

Groovy: 

if you use the "Import java.time.*" then you just need LocalDate.now(), otherwise java.time.LocalDate.now() will give the same format as above XML.

 

To use a different format you will need to setup a format variable or put it all together as @nmrao has shown previously.

 

This link helped me play around and get it working:  https://www.java67.com/2016/10/how-to-parse-string-to-localdate-in-Java8-DateTimeFormatter-Example.h...

 

Hope this helps. Good luck!  😉

Highlighted
Occasional Contributor

Re: Ready API 3.3.1 - messed date up

a piece of code in groovy which was working fine up to ReadyAPI version 3.2.5

Once I have updated the version, the format () function stopped working.

Can anyone suggest how I can manipulate the date? Like, I want a random date after 6 months from today.

 

Upto ReadyAPI 3.2.5 I have used - 

use(TimeCategory) {
def date = (today + (new Random().nextInt(12)).months).format(yyyy-MM-DD).toString());

}

But the format () function not working in ReadyAPi 3.3.1. Any leads would be appreciated.

 

Thanks in advance!

Highlighted
Contributor

Re: Ready API 3.3.1 - messed date up

Hi @API_Guy 

 

Can you please try below snippet

 

import groovy.time.TimeCategory
import java.text.SimpleDateFormat

 

use(TimeCategory) {
date = ((new Date() + (new Random().nextInt(12)).months))
sdf = new SimpleDateFormat("yyyy-MM-dd")
newDate = sdf.format(date)
}

 

Thanks!

 

Occasional Contributor

Re: Ready API 3.3.1 - messed date up

Thanks much, @Redde.

It worked for me and it was a great help! thanks again.

@khanchett this is how you can manipulate the date by adding or subtracting a day/month as well

date = ((new Date() +  3.months). you can give a try. It worked for me.

Highlighted
Visitor

Re: Ready API 3.3.1 - messed date up

Hi Smart Bear Team ,

 

 

 

 Thanks for this Solution but this solution works only when we change the Script and it is very difficult to change every script in each and every Automation Pack let say suppose  60 Automation pack  around 30 Script in Generate Test Data and Grooy script 

 

That would be very very difficult to change the script to fix this issue 

So we want proper solution like in change in Jar file or some classes change so it should be one time change / one time activity  to fix this issue

 

we are using Pro Version and need it to fix other wise we wont be able to continue to next level of version 

 

 

Tags (1)
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors