From 59c27e39e66e778dbfa20a8fe6bccfd2f2cbf074 Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Sat, 5 Mar 2016 17:18:14 +0100
Subject: [PATCH] Revert "[BUGFIX] Fix date conversion of neg timestamps"

This reverts commit 41b350dc84876c282a7309911287622591b05995.

Default values do not work well.

Change-Id: Idfadf5482d12e2f51fa14aa574061c0c2b65176d
Reviewed-on: https://review.typo3.org/47107
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Classes/Form/Element/InputTextElement.php |   2 +-
 .../Public/JavaScript/FormEngineValidation.js |   2 +-
 .../Form/Element/InputTextElementTest.php     | 114 ------------------
 .../core/Classes/DataHandling/DataHandler.php |   5 +-
 .../Unit/DataHandling/DataHandlerTest.php     |  42 -------
 5 files changed, 4 insertions(+), 161 deletions(-)
 delete mode 100644 typo3/sysext/backend/Tests/Unit/Form/Element/InputTextElementTest.php

diff --git a/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php b/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php
index 5a145793b52f..65a16c4c115e 100644
--- a/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php
+++ b/typo3/sysext/backend/Classes/Form/Element/InputTextElement.php
@@ -79,7 +79,7 @@ class InputTextElement extends AbstractFormElement
             } elseif (in_array('date', $evalList)) {
                 $attributes['data-date-type'] = 'date';
             }
-            if (MathUtility::canBeInterpretedAsInteger($parameterArray['itemFormElValue'])) {
+            if ($parameterArray['itemFormElValue'] > 0) {
                 $parameterArray['itemFormElValue'] += date('Z', $parameterArray['itemFormElValue']);
             }
             if (isset($config['range']['lower'])) {
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js
index 5871dadf0bd9..0c6fc4675926 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js
@@ -153,7 +153,7 @@ define(['jquery', 'TYPO3/CMS/Backend/FormEngine'], function ($, FormEngine) {
 		switch (type) {
 			case 'date':
 				var parsedInt = parseInt(value);
-				if (isNaN(parsedInt)) {
+				if (!parsedInt) {
 					return '';
 				}
 				theTime = new Date(parsedInt * 1000);
diff --git a/typo3/sysext/backend/Tests/Unit/Form/Element/InputTextElementTest.php b/typo3/sysext/backend/Tests/Unit/Form/Element/InputTextElementTest.php
deleted file mode 100644
index 18e7541e2ea9..000000000000
--- a/typo3/sysext/backend/Tests/Unit/Form/Element/InputTextElementTest.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-namespace typo3\sysext\backend\Tests\Unit\Form\Element;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Backend\Form\Element\InputTextElement;
-use TYPO3\CMS\Backend\Form\NodeFactory;
-use TYPO3\CMS\Core\Imaging\IconFactory;
-use TYPO3\CMS\Core\Tests\UnitTestCase;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
-/**
- * Test case
- */
-class InputTextElementTest extends UnitTestCase
-{
-    /**
-     * @var string Selected timezone backup
-     */
-    protected $timezoneBackup = '';
-
-    /**
-     * We're fiddling with hard timestamps in the tests, but time methods in
-     * the system under test do use timezone settings. Therefore we backup the
-     * current timezone setting, set it to UTC explicitly and reconstitute it
-     * again in tearDown()
-     */
-    protected function setUp()
-    {
-        $this->timezoneBackup = date_default_timezone_get();
-    }
-
-    /**
-     * Tear down
-     */
-    protected function tearDown()
-    {
-        date_default_timezone_set($this->timezoneBackup);
-        parent::tearDown();
-    }
-
-
-    /**
-     * Data provider for renderAppliesCorrectTimestampConversion
-     *
-     * @return array
-     */
-    public function renderAppliesCorrectTimestampConversionDataProvider()
-    {
-        // Three elements: input (UTC), timezone of output, expected output
-        return [
-            // German standard time (without DST) is one hour ahead of UTC
-            'date in 2016 in German timezone' => [
-                1457103519, 'Europe/Berlin', 1457103519 + 3600
-            ],
-            'date in 1969 in German timezone' => [
-                -7200, 'Europe/Berlin', -3600
-            ],
-            'begin of the UTC epoch in German timezone' => [
-                0, 'Europe/Berlin', +3600
-            ],
-            // Los Angeles is 8 hours behind UTC
-            'date in 2016 in Los Angeles timezone' => [
-                1457103519, 'America/Los_Angeles', 1457103519 - 28800
-            ],
-            'date in UTC' => [
-                1457103519, 'UTC', 1457103519
-            ]
-        ];
-    }
-
-    /**
-     * @test
-     * @dataProvider renderAppliesCorrectTimestampConversionDataProvider
-     * @param int $input
-     * @param string $serverTimezone
-     * @param int $expectedOutput
-     */
-    public function renderAppliesCorrectTimestampConversion($input, $serverTimezone, $expectedOutput)
-    {
-        date_default_timezone_set($serverTimezone);
-        $data = [
-                'parameterArray' => [
-                    'tableName' => 'table_foo',
-                    'fieldName' => 'field_bar',
-                    'fieldConf' => [
-                        'config' => [
-                            'type' => 'input',
-                            'dbType' => 'datetime',
-                            'eval' => 'datetime',
-                            'default' => '0000-00-00 00:00:00'
-                        ]
-                    ],
-                    'itemFormElValue' => $input
-            ]
-        ];
-        /** @var NodeFactory $nodeFactoryProphecy */
-        $nodeFactoryProphecy = $this->prophesize(NodeFactory::class)->reveal();
-        $subject = new InputTextElement($nodeFactoryProphecy, $data);
-        $result = $subject->render();
-        $this->assertContains('<input type="hidden" name="" value="' . $expectedOutput  . '" />', $result['html']);
-    }
-}
diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index e977bfdde6ea..56b8ef08437e 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -2662,10 +2662,9 @@ class DataHandler
                     break;
                 case 'date':
                 case 'datetime':
-                    if (MathUtility::canBeInterpretedAsInteger($value) && !$this->dontProcessTransformations) {
+                    $value = (int)$value;
+                    if ($value > 0 && !$this->dontProcessTransformations) {
                         $value -= date('Z', $value);
-                    } elseif (!MathUtility::canBeInterpretedAsInteger($value)) {
-                        $value = 0;
                     }
                     break;
                 case 'double2':
diff --git a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
index f96dc535822c..725ad8a8c0a7 100644
--- a/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
+++ b/typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
@@ -167,48 +167,6 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         }
     }
 
-
-    public function dataProviderDatetime()
-    {
-        // Three elements: input, timezone of input, expected output (UTC)
-        return [
-            // German standard time (without DST) is one hour ahead of UTC
-            'date in 2016 in German timezone' => [
-                1457103519, 'Europe/Berlin', 1457103519 - 3600
-            ],
-            'date in 1969 in German timezone' => [
-                -7200, 'Europe/Berlin', -10800
-            ],
-            'begin of the epoch in German timezone' => [
-                0, 'Europe/Berlin', -3600
-            ],
-            // Los Angeles is 8 hours behind UTC
-            'date in 2016 in Los Angeles timezone' => [
-                1457103519, 'America/Los_Angeles', 1457103519 + 28800
-            ],
-            'date in UTC' => [
-                1457103519, 'UTC', 1457103519
-            ]
-        ];
-    }
-
-    /**
-     * @test
-     * @dataProvider dataProviderDatetime
-     */
-    public function evalCheckValueDatetime($input, $serverTimezone, $expectedOutput)
-    {
-        $oldTimezone = date_default_timezone_get();
-        date_default_timezone_set($serverTimezone);
-
-        $output = $this->subject->checkValue_input_Eval($input, ['datetime'], '');
-
-        // set before the assertion is performed, so it is restored even for failing tests
-        date_default_timezone_set($oldTimezone);
-
-        $this->assertEquals($expectedOutput, $output['value']);
-    }
-
     /**
      * Data provider for inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly
      *
-- 
GitLab