Project

General

Profile

Actions

Bug #89914

closed

Native date (TCA dbType) fields are not properly copied or localized

Added by Robert Vock over 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
DataHandler aka TCEmain
Target version:
-
Start date:
2019-12-11
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.3
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

This bug was already reported by Ludwig Rafelsberger for TYPO3 7 (#79925). But the bug was closed without resolution. I just stumpled upon this behavior in TYPO3 v9.5.11

When you use a native DATE-field, translated or copied records will be off-by-one day

Prerequisites:
  • (Server) timezone with positive offset (e.g. Europe/Berlin)

TCA:

  'type' => 'input',
  'eval' => 'date',
  'dbType' => 'date',

How to reproduce:

  • Create such a new record (or use an existing one)
  • Copy it
  • Paste it

Expected result:

  select * from tx_example_domain_model_event;

  uid   pid     some_int_based_tstamp    some_native_dbtype_field
  1     1       1487548800               2019-12-11
  2     1       1487548800               2019-12-11      <-- the copied record as it should be

Actual result:

  select * from tx_example_domain_model_event;

  uid   pid     some_int_based_tstamp    some_native_dbtype_field
  1     1       1487548800               2019-12-11
  2     1       1487548800               2019-12-10      <-- the copied record with wrong date

What happens / the problem:


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #91838: TCA l10n_mode="exclude" with TCA config dbType='datetime' set wrong timezone in translated recordsClosed2020-07-22

Actions
Copied from TYPO3 Core - Bug #79925: Native date/datetime (TCA dbType) fields are not properly copied or localizedClosedLudwig Rafelsberger2017-02-20

Actions
Actions #1

Updated by Susanne Moog about 4 years ago

  • Category set to DataHandler aka TCEmain
Actions #2

Updated by Wolfgang Klinger over 3 years ago

I can confirm this with TYPO3 10.4 too (had the same problem now),

There's a comment above this line

https://github.com/TYPO3/TYPO3.CMS/blob/430d6b5780c4a24a164cc07d3cc1d7569f4f92e8/typo3/sysext/core/Classes/DataHandling/DataHandler.php#L1684

// We store UTC timestamps in the database, which is what getTimestamp() returns.

but then the DateTime is created without specifying the UTC timezone ;-)

The patch fixes this issue:

--- Classes/DataHandling/DataHandler.php.bak    2020-11-16 18:09:28.000000000 +0100
+++ Classes/DataHandling/DataHandler.php    2020-11-16 18:09:55.000000000 +0100
@@ -15,6 +15,7 @@

 namespace TYPO3\CMS\Core\DataHandling;

+use DateTimeZone;
 use Doctrine\DBAL\DBALException;
 use Doctrine\DBAL\Driver\Statement;
 use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
@@ -1869,7 +1870,7 @@
                 // Convert the date/time into a timestamp for the sake of the checks
                 $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
                 // We store UTC timestamps in the database, which is what getTimestamp() returns.
-                $dateTime = new \DateTime($value);
+                $dateTime = new \DateTime($value, new DateTimeZone('UTC'));
                 $value = $value === $emptyValue ? null : $dateTime->getTimestamp();
             }
         }
Actions #3

Updated by Imko Schumacher over 3 years ago

  • Copied from Bug #79925: Native date/datetime (TCA dbType) fields are not properly copied or localized added
Actions #4

Updated by Imko Schumacher over 3 years ago

  • Related to Bug #91838: TCA l10n_mode="exclude" with TCA config dbType='datetime' set wrong timezone in translated records added
Actions #5

Updated by Imko Schumacher over 3 years ago

  • Description updated (diff)

Add note about server timezone, needs to be a positive offset from UTC (e.g. Europe/Berlin).

Actions #6

Updated by Gerrit Code Review over 3 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66670

Actions #7

Updated by Imko Schumacher over 3 years ago

  • Description updated (diff)
  • TYPO3 Version changed from 9 to 10
  • PHP Version changed from 7.2 to 7.3
Actions #8

Updated by Markus Klein over 3 years ago

Wolfgang Klinger wrote in #note-2:

// We store UTC timestamps in the database, which is what getTimestamp() returns.

but then the DateTime is created without specifying the UTC timezone ;-)

This refers to the fact that a \DateTime uses the configured timezone and a unix timestamp is in UTC by definition.
So a new \DateTime('1.1.1970 01:00') in timezone MEZ will yield 0 for getTimestamp().
That is what the comment actually tries to convey.

Actions #9

Updated by Gerrit Code Review over 3 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66670

Actions #10

Updated by Gerrit Code Review over 3 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66670

Actions #11

Updated by Gerrit Code Review over 3 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66670

Actions #12

Updated by Gerrit Code Review over 3 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66670

Actions #13

Updated by Gerrit Code Review over 3 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/66670

Actions #14

Updated by Gerrit Code Review over 3 years ago

Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67200

Actions #15

Updated by Gerrit Code Review over 3 years ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/67201

Actions #16

Updated by Imko Schumacher over 3 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #17

Updated by Benni Mack over 3 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF