Commit 69e9a259 authored by Monish Deb's avatar Monish Deb Committed by GitHub

Merge pull request #11093 from seamuslee001/CRM-20397-tollerance

CRM-20397 Allow for up to 4 hours tollarence in setting the date as v…
parents 30ce03ec 7947eac5
(function(angular, $, _) {
// "YYYY-MM-DD hh:mm:ss" => Date()
function parseYmdHms(d) {
var parts = d.split(/[\-: ]/);
return new Date(parts[0], parts[1]-1, parts[2], parts[3], parts[4], parts[5]);
}
function isDateBefore(tgt, cutoff, tolerance) {
var ad = parseYmdHms(tgt), bd = parseYmdHms(cutoff);
// We'll allow a little leeway, where tgt is considered before cutoff
// even if technically misses the cutoff by a little.
return ad < bd-tolerance;
}
// Represent a datetime field as if it were a radio ('schedule.mode') and a datetime ('schedule.datetime').
// example: <div crm-mailing-radio-date="mySchedule" ng-model="mailing.scheduled_date">...</div>
angular.module('crmMailing').directive('crmMailingRadioDate', function(crmUiAlert) {
......@@ -64,7 +77,7 @@
date = [year, month, day].join('-');
time = [hours, minutes, "00"].join(':');
currentDate = date + ' ' + time;
var isInPast = ($(this).val().length && submittedDate < currentDate);
var isInPast = (submittedDate.length && submittedDate.match(/^[0-9\-]+ [0-9\:]+$/) && isDateBefore(submittedDate, currentDate, 4*60*60*1000));
ngModel.$setValidity('dateTimeInThePast', !isInPast);
if (lastAlert && lastAlert.isOpen) {
lastAlert.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment