JavaLikeCalc.JavaScript
//Document generation one in hour
curMin = curHour = curDay = curMonth = curYear = 0;
SYS.localtime(SYS.time(), 0, curMin, curHour, curDay, curMonth, curYear);
if(!doc_bTime) {
	doc_bTime = SYS.strptime(""+curYear+"-"+(curMonth+1)+"-"+curDay+" "+repHour+":0:0","%Y-%m-%d %H:%M:%S");
	if(curHour < repHour)	doc_bTime -= 24*60*60;
}
if(lastHour < 0 || lastDay < 0 || lastMin < 0) SYS.localtime(doc_bTime, 0, lastMin, lastHour, lastDay);

//Archive last not closed document
if(closeDoc == true) { if(!doc_process) doc_aCur = -1, closeDoc = false; }
else if(doc_time && doc_time < doc_bTime) {
	closeDoc = true;  
	SYS.localtime(doc_time, 0, 0, curHour, curDay, curMonth, curYear);
	doc_time = doc_bTime = SYS.strptime(""+curYear+"-"+(curMonth+1)+"-"+curDay+" "+repHour+":0:0","%Y-%m-%d %H:%M:%S");
	if(curHour >= repHour) doc_time += 24*60*60; else doc_bTime -= 24*60*60;
}
//Archive the document
else if(curDay != lastDay && curHour == repHour && curMin >= 3) {
	closeDoc = true;
	doc_time = SYS.strptime(""+curYear+"-"+(curMonth+1)+"-"+curDay+" "+repHour+":0:0","%Y-%m-%d %H:%M:%S");
	lastDay = curDay;
}
//Periodic notfull update
else if(curMin != lastMin && !(curMin%5)) {
	lastMin = curMin;
	doc_time = SYS.time() - 5*60;
	SYS.localtime(doc_time, 0, 0, curHour, curDay, curMonth, curYear);
	doc_bTime = SYS.strptime(""+curYear+"-"+(curMonth+1)+"-"+curDay+" "+repHour+":0:0","%Y-%m-%d %H:%M:%S");
	if(curHour < repHour) doc_bTime -= 24*60*60;
}