cancel
Showing results for 
Search instead for 
Did you mean: 

Assert a date in format (e.g. MM-DD-CCYY) = date in a format (e.g. CCYY-MM-DDTHH24:MI:SSZ)

SOLVED
Community Hero

Assert a date in format (e.g. MM-DD-CCYY) = date in a format (e.g. CCYY-MM-DDTHH24:MI:SSZ)

Hi,

 

I have a PATCH REST request (json type payload) which contains a requiredByDate attribute with a date value with format MM-DD-CCYY

 

The follow up GET REST json response contains the requiredByDate attribute, but the value is transformed from MM-DD-CCYY to CCYY-MM-DDTHH24:MISmiley FrustratedS format.

 

I need to verify the date is correct with the new date format, but  I've no idea how to do this - I'm guessing a small script assertion might do the job - but I really have no idea how to proceed - although i did have a go....

 

e.g. my example PATCH's payload is as follows:

{
"requiredByDate" : "07-29-2019",
"certifierId" : "123456"
}

my example GET's response payload is as follows:

{
"certifierdecision" : 814250000,
"certifierfullname" : "Robert Smith",
"certifierid" : "123456",
"reasonforrejecting" : null,
"statuscode" : 814250005,
"reasonnotes" : null,
"requiredByDate" : "2019-07-29T00:00:00Z",
"dateofinspection" : "2019-10-15T00:00:00Z",
"certificateitemid" : "65f73d0f-fdef-e911-a813-000d3a4aa8a9"
}


I tried putting a script assertion together against the GET request (after saving the PATCH request's date in a Properties step) knowing I wouldnt get absolutely right - but I wanted to give it a go anyway and this is what I got:

def USdate = context.expand('${Properties#requiredByDate}')
log.info(USdate)
def date = Date.parse("MM-dd-yyyy",USdate)
def UKdate = date.format("yyyy-MM-dd'T'HH:mm:ss'Z'")
log.info(UKdate)

assert USdate == UKdate

Obviously the assertion fails - because I'm saying 07-29-2019 is the same as '2019-07-29T00:00:00'

the results of the logging in the snippet is as follows:

Tue Oct 22 20:01:58 BST 2019: INFO: 07-29-2019
Tue Oct 22 20:01:58 BST 2019: INFO: 2019-07-29T00:00:00Z

Would anyone know how I can assert a date in one format (e.g. MM-DD-CCYY) is equivalent to the date in a different format (e.g. CCYY-MM-DDTHH24:MISmiley FrustratedSZ)?

 

I hope I've been clear in my request

 

Thanks to all!

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Assert a date in format (e.g. MM-DD-CCYY) = date in a format (e.g. CCYY-MM-DDTHH24:MI:SSZ)

Here is the sample that you are looking for.
https://mrhaki.blogspot.com/2009/08/groovy-goodness-working-with-dates.html

Basically, compare year, month, date.
In java 8, it is possible to compare only dates without time as well.


Regards,
Rao.

View solution in original post

2 REPLIES 2
Highlighted
Community Hero

Re: Assert a date in format (e.g. MM-DD-CCYY) = date in a format (e.g. CCYY-MM-DDTHH24:MI:SSZ)

Here is the sample that you are looking for.
https://mrhaki.blogspot.com/2009/08/groovy-goodness-working-with-dates.html

Basically, compare year, month, date.
In java 8, it is possible to compare only dates without time as well.


Regards,
Rao.

View solution in original post

Community Manager

Re: Assert a date in format (e.g. MM-DD-CCYY) = date in a format (e.g. CCYY-MM-DDTHH24:MI:SSZ)

Hi @richie, it looks like nmrao has a suggestion for you!Smiley Happy

Does it solve your issue? 



Sonya Mihaljova
Community and Education Specialist
Enroll at the SmartBear Academy today and learn our products via exclusive video courses.
New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors