purplemanchris
3/27/2019 - 2:37 PM

Date Time Stuff

//Set a timer in workflow based on a Date variable
//Convert Date Variable to DateTime
var dateToRemoveAccess =  current.variables.u_date_to_remove_access;
var dateTimeToRemoveAccess = new GlideDateTime(dateToRemoveAccess);

var dateNow = new GlideDateTime();

var secondsToDelay = gs.dateDiff(dateNow.getDisplayValue(),dateTimeToRemoveAccess.getDisplayValue(), true);
gs.addInfoMessage("Seconds delay: " + secondsToDelay);

//Set 'answer' to the number of seconds this timer should wait
answer = secondsToDelay;


(function executeRule(current, previous /*null when async*/) {
	//Board Slot start = Date of Board Date Assigned (DateTime) + time slot (Time)
	// Board Date End = Board slot start + Board Item Duration
	var boardAssignedDate = current.u_board_assigned.start.getDisplayValue().split(' ')[0];
//	gs.addInfoMessage("CJT Date: " + boardAssignedDate);
	
	//Get Time slot value
	var gdtTime = new GlideDateTime(current.u_time_slot);
	var gdtsplit = gdtTime.getDisplayValue().split(' ')[1].split(':');
	var hour = gdtsplit[0];
	var minute = gdtsplit[1];
	var second = gdtsplit[2];
	var displayValue = boardAssignedDate + " "+ hour + ":" + minute + ":" + second;

//	var imsTime = gdtTime.getNumericValue();
//	var imsInHour = 3600000;
//	var imsInMinute = 60000;
//	var iLocalHours = Math.floor(imsTime / imsInHour).toFixed(0);
//	var iLocalMinutes = Math.floor((imsTime - (iLocalHours * imsInHour)) / imsInMinute).toFixed(0);
//  var displayValue = boardAssignedDate + " "+ iLocalHours + ":" + iLocalMinutes + ":00";
//	gs.addInfoMessage("CJT timeslot: " + iLocalHours + " Mins: " + iLocalMinutes);
	
//	gs.addInfoMessage("CJT Start time slot: " + displayValue);

	var startDT = new GlideDateTime();
	startDT.setDisplayValue(displayValue, "dd/MM/yyyy HH:mm:ss");
	current.u_slot_start = startDT;
	
	var endDT = new GlideDateTime();
	endDT.setDisplayValue(displayValue, "dd/MM/yyyy HH:mm:ss");
	endDT.add(60000 * current.u_board_item_duration);
	current.u_slot_end = endDT;
	
	current.update();
	
	
})(current, previous);