0

I am working in SoapUI , which supports GroovyScript in TestCases.
In some TestCases i supposed to use a date of now + 15 minutes, 30, or 90 minutes.
If im using this script:

import java.util.Calendar;

def tdFormat = "yyyy-MM-dd HH:mm"
def today =  Calendar.getInstance()
def today15min = today.add(today.MINUTE,15)
def todayFormated = today15min.format(tdFormat)

gets NullPointerException: Cannot invoke method format() on null object error at line: 6.
How can i fix this?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
mabuno
  • 13
  • 2
  • 9
  • Similar to http://stackoverflow.com/questions/21166927/incrementing-date-object-by-hours-minutes-in-groovy – biniam Aug 17 '16 at 10:00

2 Answers2

5

Using TimeCategory.

use( groovy.time.TimeCategory ) {
    println 15.minutes.from.now.format( 'yyyy-MM-dd HH:mm' )
}
dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • Thanks, that works great and simple! I'm modified it in script as `use( groovy.time.TimeCategory ) { def newDate = 15.minutes.from.now.format( 'yyyy-MM-dd HH:mm' ) }` and result of this script is what i wanted to! – mabuno Mar 24 '15 at 14:40
0

Calendar is a static class used to create Dates. Calendar.add() returns void, because it simply modifies the Calendar. You need to call getTime() to get a Date object which you can then format how you please.

doelleri
  • 19,232
  • 5
  • 61
  • 65