I set a variable in another transformation...it is read in as a date. In the transformation with the error I do this:
I'm getting this error:
2019/04/29 16:53:27 - js get req body.0 - org.mozilla.javascript.EvaluatorException: Cannot convert 2019-04-29 16:53:27 to java.util.Date (script#41) (script#41)
Why does the dateDiff function need to convert the date if it is already a date?
Code:
var now_time = new Date();
var sixty_second_count = getVariable("SIXTY_SECOND_COUNT", 0);
var sixty_second_count_plus_one = sixty_second_count + 1;
var sixty_second_start = getVariable("SIXTY_SECOND_START", now_time);
if (sixty_second_count == 19)
{
writeToLog("m", "We hit 19 requests");
setVariable("SIXTY_SECOND_COUNT", 0, "r");
java.lang.Thread.sleep(60 - dateDiff(sixty_second_start, now_time, "ss"));
writeToLog("m", "Done waiting for 60 seconds to end");
setVariable("SIXTY_SECOND_START", new Date(), "r");
}
else
{
setVariable("SIXTY_SECOND_COUNT", sixty_second_count + 1 , "r");
writeToLog("m", "60 second count now at: " + sixty_second_count_plus_one);
writeToLog("m", "Time into 60 second interval: " + dateDiff(sixty_second_start, now_time, "ss"));
}
if (dateDiff(sixty_second_start, now_time, "ss") >= 60)
{
setVariable("SIXTY_SECOND_START", new Date(), "r");
setVariable("SIXTY_SECOND_COUNT", 0, "r");
writeToLog("m", "We reached 60 seconds and reset start time and 60 second interval count");
}
Quote:
2019/04/29 16:53:27 - js get req body.0 - org.mozilla.javascript.EvaluatorException: Cannot convert 2019-04-29 16:53:27 to java.util.Date (script#41) (script#41)