From 7947eac5f49c47d05491b290fd51cb39c0a9ea56 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 10 Oct 2017 01:41:11 +1100 Subject: [PATCH] CRM-20397 Allow for up to 4 hours tollarence in setting the date as valid or not so that end user timezone issues aren't a factor --- ang/crmMailing/RadioDate.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ang/crmMailing/RadioDate.js b/ang/crmMailing/RadioDate.js index 5ed5b204d0..037b6e22ba 100644 --- a/ang/crmMailing/RadioDate.js +++ b/ang/crmMailing/RadioDate.js @@ -1,4 +1,17 @@ (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:
...
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(); -- 2.25.1