Forum Discussion

MZELEWSKI's avatar
MZELEWSKI
New Contributor
13 years ago

DataGen - haow to generate non working date

I want to generate a date in following format ("yyy-MM-dd") in a request.
So far I have in DataGen:

${=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())}

My question is, how to generate a date which is not working day?

Anyone know how to do this?
Thanks!

2 Replies

  • SiKing's avatar
    SiKing
    Community Hero
    Are you asking for a weekend date, or are you asking for an invalid date?

    For an invalid date just place another digit at the end, so something like
    ${=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())}1


    For a weekend date this is not going to be a one-liner! You will probably have to use GregorianCalendar(); see http://groovy.codehaus.org/JN0545-Dates for hints.
  • Here's some Groovy code which will store the next Saturday or Sunday in the variable nonWorkingDay:

    def calendar = Calendar.getInstance()
    def dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)
    def offset = Calendar.SATURDAY - dayOfWeek
    if (offset > 0) calendar.add(Calendar.DAY_OF_WEEK, offset )
    def nonWorkingDay = calendar.time