From 2dc0a952df1b0b18f9fb951bb20a0e9ab8ada69d Mon Sep 17 00:00:00 2001
From: Frank Naegler <frank.naegler@typo3.org>
Date: Fri, 27 Oct 2017 17:59:47 +0200
Subject: [PATCH] [!!!][TASK] Remove fixed year 2038 in FormEngine validation
 JavaScript

This patch removes the fixed year 2038 from the validation.
The validation has been simplified.

Resolves: #81973
Releases: master
Change-Id: If5577b1ce59c8a0310e6a63a8e1ac14dd8944387
Reviewed-on: https://review.typo3.org/54488
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
---
 .../Public/JavaScript/FormEngineValidation.js | 15 -------
 ...neValidationparseDateRemoveFixYear2038.rst | 40 +++++++++++++++++++
 .../Formhandler/ElementsBasicInputCest.php    |  6 +--
 3 files changed, 43 insertions(+), 18 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-81973-FormEngineValidationparseDateRemoveFixYear2038.rst

diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js
index 999cee0a9515..da7b1ca3e9d7 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js
@@ -716,13 +716,6 @@ define(['jquery', 'moment'], function ($, moment) {
 				}
 
 				var year = (values.values[3]) ? FormEngineValidation.parseInt(values.values[3]) : FormEngineValidation.getYear(today);
-				if ((year >= 0 && year < 38) || (year >= 70 && year < 100) || (year >= 1902 && year < 2038)) {
-					if (year < 100) {
-						year = (year < 38) ? year += 2000 : year += 1900;
-					}
-				} else {
-					year = FormEngineValidation.getYear(today);
-				}
 				var usMode = FormEngineValidation.USmode ? 1 : 2;
 				var month = (values.values[usMode]) ? FormEngineValidation.parseInt(values.values[usMode]) : today.getUTCMonth() + 1;
 				usMode = FormEngineValidation.USmode ? 2 : 1;
@@ -731,7 +724,6 @@ define(['jquery', 'moment'], function ($, moment) {
 
 				var theTime = moment.utc();
 				theTime.year(parseInt(year)).month(parseInt(month)-1).date(parseInt(day)).hour(0).minute(0).second(0);
-
 				FormEngineValidation.lastDate = theTime.unix();
 		}
 		FormEngineValidation.lastDate += add * 24 * 60 * 60;
@@ -836,13 +828,6 @@ define(['jquery', 'moment'], function ($, moment) {
 					add = FormEngineValidation.pol(values.valPol[2], FormEngineValidation.parseInt(values.values[2]));
 				}
 				var year = (values.values[1]) ? FormEngineValidation.parseInt(values.values[1]) : FormEngineValidation.getYear(today);
-				if ((year >= 0 && year < 38) || (year >= 70 && year<100) || (year >= 1902 && year < 2038)) {
-					if (year < 100) {
-						year = (year < 38) ? year += 2000 : year += 1900;
-					}
-				} else {
-					year = FormEngineValidation.getYear(today);
-				}
 				FormEngineValidation.lastYear = year;
 		}
 		FormEngineValidation.lastYear += add;
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-81973-FormEngineValidationparseDateRemoveFixYear2038.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-81973-FormEngineValidationparseDateRemoveFixYear2038.rst
new file mode 100644
index 000000000000..b0741d91f61f
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-81973-FormEngineValidationparseDateRemoveFixYear2038.rst
@@ -0,0 +1,40 @@
+.. include:: ../../Includes.txt
+
+========================================================================
+Breaking: #81973 - FormEngineValidation.parseDate remove fixed year 2038
+========================================================================
+
+See :issue:`81973`
+
+Description
+===========
+
+In issue :issue:`81940` the TCA range upper bound was removed.
+But in the file ``typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js`` in method
+:js:`FormEngineValidation.parseDate` a fixed year 2038 was included.
+
+The result: it was impossible to set a date after year 2038 in datetime fields.
+This limitation is now removed. The date is always set to the current date.
+
+A second problem: It was impossible to enter a date < 100 because there were magically added numbers: 2000 for values
+between 0 and 38 and 1900 for values between 39 and 100.
+
+
+Impact
+======
+
+The magic in calculating date values, e.g. entering 12 will result in 2012, is now removed.
+
+
+Affected Installations
+======================
+
+This affects only the behavior in backend record editing forms. Values of 0 to 100 will not be changed anymore.
+
+
+Migration
+=========
+
+No migration, this behavior was wrong and there is no migration possible.
+
+.. index:: Backend, FlexForm, JavaScript, NotScanned
diff --git a/typo3/sysext/core/Tests/Acceptance/Backend/Formhandler/ElementsBasicInputCest.php b/typo3/sysext/core/Tests/Acceptance/Backend/Formhandler/ElementsBasicInputCest.php
index 12a592a95812..95fdbc4fca7f 100644
--- a/typo3/sysext/core/Tests/Acceptance/Backend/Formhandler/ElementsBasicInputCest.php
+++ b/typo3/sysext/core/Tests/Acceptance/Backend/Formhandler/ElementsBasicInputCest.php
@@ -183,9 +183,9 @@ class ElementsBasicInputCest extends AbstractElementsBasicCest
                 ],
                 [
                     'inputValue' => '12',
-                    'expectedValue' => '2012',
-                    'expectedInternalValue' => '2012',
-                    'expectedValueAfterSave' => '2012',
+                    'expectedValue' => '12',
+                    'expectedInternalValue' => '12',
+                    'expectedValueAfterSave' => '12',
                     'comment' => '',
                 ],
                 [
-- 
GitLab