Issues with Time Date Fields

Good Afternoon,

I am having some issues performing some tests and calculations on Time and Date fields using JavaScript, my code is below: -

fd.field('Start_x0020_Date_x002f_Time').$on('change',validateEndDate);
fd.field('End_x0020_Date_x002f_Time').$on('change',validateEndDate);

// Function to validate End Date/Time is not before Start Date/Time
function validateEndDate () {
	debugger;
	var startDate = fd.field('Start_x0020_Date_x002f_Time').value;
	var endDate = fd.field('End_x0020_Date_x002f_Time').value;
	var plusOneHour = fd.field('Start_x0020_Date_x002f_Time').value;
	plusOneHour.setHours(plusOneHour.getHours() +1);
	if (endDate != null) {
		if (endDate < startDate) {
			fd.field('End_x0020_Date_x002f_Time').value = plusOneHour;
			alert('The End Date/Time cannot be set before the Start Date/Time');
		}
	}
}

The function should perform a simple test on the selected End Date/Time to test if it is set before the selected Start Date/Time, if it is then it should pop up an alert to the user and then increment the Start Date/Time by +1 hour and insert this into the End Date/Time field.

The issue is that increment just seems to keep growing if this function is examined in the debugger, the plusOneHour variable seems to affect the Start Date/Time field and and some how the data in this field is updated with the incremented time even though the field itself does not change on the form…

Thanks

Any help on this one?

Dear @Tony_Duke,

I’m sorry for a late reply, we are researching your issue. I’ll give you an answer soon.

Dear @Tony_Duke,

It’s a bug, thank you for your request. I’ll keep you up to date.

Dear @Tony_Duke,

The bug was fixed, please clean the browser cache completely.

I’ve slightly changed your code:

function validateEndDate () {
    debugger;
    var startDate = fd.field('StartDate').value;
    var endDate = fd.field('EndDate').value;
    var plusOneHour = fd.field('StartDate').value;
    if (endDate != null) {
        if (endDate < startDate) {
            plusOneHour.setHours(plusOneHour.getHours() +1);
            fd.field('EndDate').value = plusOneHour;
            alert('The End Date/Time cannot be set before the Start Date/Time');
        }
    }
}

Hi Alex,

The bug still seems to be there, I completely cleared my cache and no real difference, please see images below when: -

  1. End Date selected as tomorrow, code runs and works exactly as expected and required, except that as you can see the operation of the plusOneHour has also incremented the startDate var...

  2. The next time it runs if the user attempts to change the End Date/Time to before the Start Date/Time the startDate var starts at 10:00:00 rather than at 09:00:00 so the resultant plusOneHour time ends up being 11:00:00

Every time the user attempts to change the End Date/Time to before the Start Date/Time the time is incremented by 1 hour, and if I try to retrieve the Start Date/Time field for any other use or even within a completely different function while ever that form is open the time returned will be the incremented time, not the time entered in the actual field. I would expect every time I run the var startDate = fd.field('Start_x0020_Date_x002f_Time').value; it should return startDate = Thu Feb 28 2019 09:00:00 GMT+0000 (Greenwich Mean Time) {}.

Dear Tony,

I’ve reproduced your issue, please try this code:

function validateEndDate () {
    var startDate = fd.field('StartDate').value;
    var endDate = fd.field('EndDate').value;
    var plusOneHour = new Date(fd.field('StartDate').value.getTime());
    if (endDate != null) {
        if (endDate < startDate) {
            plusOneHour.setHours(plusOneHour.getHours() +1);
            fd.field('EndDate').value = plusOneHour;
            alert('The End Date/Time cannot be set before the Start Date/Time');
        }
    }
}