Java code snippet no longer working to create dates in 3.3.2, worked fine in 3.3.1 and prior builds
I have been using the following custom property for years to create dates which I then pass for my insertion of transactions in my rest web service calls. The below example has always created the date of tomorrow in "effectiveEntryDate":09/14/2020 format.
${=import javax.xml.datatype.DatatypeFactory; def cal = Calendar.instance;cal.add(Calendar.DATE, 1);cal.getTime().toLocaleDateString()}
It worked fine in 3.3.1 but once I upgraded to 3.3.2, it now returns an error:
"effectiveEntryDate":"No signature of method: java.util.Date.format() is applicable for argument types: (String) values: [MM/dd/yyyy]
Possible solutions: from(java.time.Instant), toYear(), stream(), getAt(java.lang.String), parse(java.lang.String), print(java.io.PrintWriter)"
Is it possible I need to upgrade the java for ReadyAPI, etc? Any help would be greatly appreciated!
The custom property worked perfectly! Let me ask one more thing. With the old java, I could modify the dates such as:
Same Day
${=import javax.xml.datatype.DatatypeFactory; def cal = Calendar.instance;cal.getTime().format("MM/dd/yyyy")}Future Date
${=import javax.xml.datatype.DatatypeFactory; def cal = Calendar.instance;cal.add(Calendar.DATE, 1000);cal.getTime().format("MM/dd/yyyy")}Is that possible using the SimpleDate snippets?
1) Future date custom property with Local Date class:
${= import java.time.LocalDate; LocalDate.now().plusDays(1).format(java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy"))}
or
${=java.time.LocalDateTime.now().plusDays(1).format(java.time.format.DateTimeFormatter.ofPattern("MM/dd/yyyy"))}
2) Future Date in groovy with Simple Date Format:
import groovy.time.TimeCategory
import java.text.SimpleDateFormatuse(TimeCategory) {
def time = new Date()+ 1.days
date = new SimpleDateFormat ("MM/dd/yyyy").format(time)}