Forum Discussion
WaveyDavey
13 years agoOccasional Contributor
Ok, I did this. Probably much nicer ways to do it, but ...
so, for smartTest's problem above, use the Calendar object to do the manipulation, and then convert to date object with Calendar.getTime()
Hope this helps.
David
//Parse table row returned
def dbNewDbu = context.expand( '${check DBU really changed#ResponseAsXml#//root[1]/data[1]/reset[1]}' )
dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dbValAsDate = dateFormat.parse(dbNewDbu);
// Set up a pair of calendar object for date manipulation
def a = Calendar.getInstance();
def b = Calendar.getInstance();
// set them now + 30 days +/- 5 minutes in case of time sync differences
a.add(Calendar.DATE,30);
b.add(Calendar.DATE,30);
a.add(Calendar.MINUTE,-5);
b.add(Calendar.MINUTE,5);
// get 2 date objects from Calendar objects, so we can do assertion with before and after methods
Date aDate = a.getTime();
Date bDate = b.getTime();
s1= dateFormat.format(aDate);
s2= dateFormat.format(dbValAsDate);
s3= dateFormat.format(bDate);
assert (dbValAsDate.after(aDate) && dbValAsDate.before(bDate));
so, for smartTest's problem above, use the Calendar object to do the manipulation, and then convert to date object with Calendar.getTime()
Hope this helps.
David
Related Content
Recent Discussions
- 7 days agoemoya