From 8ce6946a2fdb51ca8e8a6a0d367ffcc143b66b4d Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Thu, 25 Jul 2019 11:47:39 +0200
Subject: [PATCH] Date not in the future validation

---
 .../entityfields/entrydate/onValidation.js        |  4 ++--
 entity/Competition_entity/Competition_entity.aod  |  1 +
 .../entityfields/date_cancelled/onValidation.js   |  7 +++++++
 .../entityfields/dateofbirth/onValidation.js      |  4 ++--
 .../_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod   |  3 +++
 language/_____LANGUAGE_de/_____LANGUAGE_de.aod    |  4 ++++
 language/_____LANGUAGE_en/_____LANGUAGE_en.aod    |  3 +++
 process/Date_lib/process.js                       | 15 ++++++++++++++-
 8 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100644 entity/Competition_entity/entityfields/date_cancelled/onValidation.js

diff --git a/entity/Activity_entity/entityfields/entrydate/onValidation.js b/entity/Activity_entity/entityfields/entrydate/onValidation.js
index 0f2440a772..437a5ee635 100644
--- a/entity/Activity_entity/entityfields/entrydate/onValidation.js
+++ b/entity/Activity_entity/entityfields/entrydate/onValidation.js
@@ -1,9 +1,9 @@
-import("system.datetime");
+import("Date_lib");
 import("system.translate");
 import("system.vars");
 import("system.result");
 import("Entity_lib");
 
 var entryDate = vars.get("local.value");
-if (Number(datetime.clearTime(entryDate)) > Number(vars.get("$sys.today")))
+if (!DateUtils.validateNotInFuture(entryDate))
     result.string(translate.text("Entrydate must not be in the future"));
\ No newline at end of file
diff --git a/entity/Competition_entity/Competition_entity.aod b/entity/Competition_entity/Competition_entity.aod
index 53eff28a3c..364d1c995d 100644
--- a/entity/Competition_entity/Competition_entity.aod
+++ b/entity/Competition_entity/Competition_entity.aod
@@ -16,6 +16,7 @@
       <resolution>DAY</resolution>
       <outputFormat>dd.MM.yyyy</outputFormat>
       <inputFormat>dd.MM.yyyy</inputFormat>
+      <onValidation>%aditoprj%/entity/Competition_entity/entityfields/date_cancelled/onValidation.js</onValidation>
     </entityField>
     <entityField>
       <name>INFO</name>
diff --git a/entity/Competition_entity/entityfields/date_cancelled/onValidation.js b/entity/Competition_entity/entityfields/date_cancelled/onValidation.js
new file mode 100644
index 0000000000..193af4e5f9
--- /dev/null
+++ b/entity/Competition_entity/entityfields/date_cancelled/onValidation.js
@@ -0,0 +1,7 @@
+import("system.translate");
+import("system.vars");
+import("system.result");
+import("Date_lib");
+
+if (!DateUtils.validateNotInFuture(vars.get("$local.value")))
+    result.string(translate.text("Excreted can't be in the future"));
diff --git a/entity/Person_entity/entityfields/dateofbirth/onValidation.js b/entity/Person_entity/entityfields/dateofbirth/onValidation.js
index c21866aca6..43c36ddb3d 100644
--- a/entity/Person_entity/entityfields/dateofbirth/onValidation.js
+++ b/entity/Person_entity/entityfields/dateofbirth/onValidation.js
@@ -1,9 +1,9 @@
-import("system.datetime");
+import("Date_lib");
 import("system.translate");
 import("system.vars");
 import("system.result");
 import("Entity_lib");
 
 var dob = vars.get("local.value");
-if (Number(datetime.clearTime(dob)) > Number(vars.get("$sys.today")))
+if (!DateUtils.validateNotInFuture(dob))
     result.string(translate.text("date of birth must not be in the future"));
\ No newline at end of file
diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
index 4d777ed847..9aed5eb39b 100644
--- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
+++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod
@@ -5088,6 +5088,9 @@
     <entry>
       <key>Download</key>
     </entry>
+    <entry>
+      <key>Copy Campaign</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
   <sqlModels>
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index 642ac35f69..241d2d67eb 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -34,6 +34,10 @@
       <key>No data has been anonymized.</key>
       <value>Keine Daten wurden anonymisiert.</value>
     </entry>
+    <entry>
+      <key>Excreted can't be in the future</key>
+      <value>Ausgeschieden darf nicht in der Zukunft liegen</value>
+    </entry>
     <entry>
       <key>Anonymization</key>
       <value>Anonymisierung</value>
diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
index 15d6919df1..0c3ad5948c 100644
--- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
+++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod
@@ -5137,6 +5137,9 @@
     <entry>
       <key>Download</key>
     </entry>
+    <entry>
+      <key>Copy Campaign</key>
+    </entry>
   </keyValueMap>
   <font name="Dialog" style="0" size="11" />
 </language>
diff --git a/process/Date_lib/process.js b/process/Date_lib/process.js
index 5e157445c3..60a391e0f5 100644
--- a/process/Date_lib/process.js
+++ b/process/Date_lib/process.js
@@ -1,3 +1,4 @@
+import("system.vars");
 import("system.eMath");
 import("system.translate");
 import("system.datetime");
@@ -142,4 +143,16 @@ DateUtils.formatDurationFromStartTillEnd = function(pStartTime, pEndTime, pLocal
     var duration = eMath.subInt(pEndTime , pStartTime);
     duration = Math.max(0, Number(duration));
     return DateUtils.formatDuration(duration, pLocale);
-};
\ No newline at end of file
+};
+
+/**
+ * validates if the given date is not in the future
+ * 
+ * @param {string|number} pDate
+ * 
+ * @return {boolean} true if the date is today or before today
+ */
+DateUtils.validateNotInFuture = function (pDate)
+{
+    return Number(datetime.clearTime(pDate)) <= Number(vars.get("$sys.today"));
+}
\ No newline at end of file
-- 
GitLab