i have response like { Data: {a: [{ date1: "2018-12-23", date2: "23-11-2018" },{ date1: "2018-12-20",date2: "23-11-2018" }] } }
and want to test if each date1 field is less than today's date and each date2 is less than input date field (i have a date field in input payload) How can i perform that.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
In many ways, here is one. Refactoring this code to be cleaner is homework for you :P
* def toTime1 =
"""
function(s) {
var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
var sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.parse(s).time
}
"""
* def toTime2 =
"""
function(s) {
var SimpleDateFormat = Java.type('java.text.SimpleDateFormat');
var sdf = new SimpleDateFormat("dd-MM-yyyy");
return sdf.parse(s).time
}
"""
* def input = toTime2("24-11-2018")
* def today = new java.util.Date().time
* def isValid1 = function(x){ return toTime1(x) < today }
* def isValid2 = function(x){ return toTime2(x) < input }
* def response = [{ date1: "2018-12-23", date2: "23-11-2018" }, { date1: "2018-12-20", date2: "23-11-2018" }]
* match each response == { date1: '#? isValid1(_)', date2: '#? isValid2(_)' }