Project

General

Profile

Actions

Bug #96890

open

Wrong processing and display of native datetime(dbType) fields due to server timezone

Added by Imko Schumacher almost 3 years ago. Updated about 12 hours ago.

Status:
Under Review
Priority:
Should have
Assignee:
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2022-02-14
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
medium
Is Regression:
Sprint Focus:

Description

Wrong processing and display of native datetime(dbType) fields due to server timezone

Inside DatabaseRowDateTimeFields class native datetime (dbType) values are treated as UTC values, whereas the rest uses the local timezone (e.g. BackendUtility::datetime).
This causes the TCA title (bug 1) and readOnly fields (bug 2) to be formatted wrong (with an time offset).
The conversion also breaks the title for time fields (bug 3) completely.

Prerequisite

  • Timezone != 'UTC', e.g. timezone: America/New_York (.ddev/config.yaml)
  • Specified configuration (see below)

Steps to reproduce

Bug 1

  1. Create a new DateTime title error record and set mydatetime to 12:00 20-02-2022
  2. Save record
  3. Look at the record title
    • Actual value (wrong time): Edit DateTime title error "20-02-22 07:00" on page "recordStorage"
    • Expected value: Edit DateTime title error "20-02-22 12:00" on page "recordStorage"
      Bug 1: Title with time offset

Bug 2

  1. Uncomment readOnly in TCA and clear cache/reload
  2. Open record from bug 1
  3. Look at the disable field (mydatetime)
    • Actual value (wrong time): 20-02-22 07:00
    • Expected value: 20-02-22 12:00
      Bug 2: wrong time for readonly field

Bug 3

  1. Change TCA config for bug 3 and clear cache/reload
  2. Create a new DateTime title error record and set mytime to 12:00
  3. Save record
    • Actual value: 2022-02-12T07:00:00-05:00
    • Expected value: 12:00
      Bug 3: full iso date in title

Configuration

TCA:

return [
    'ctrl' => [
        'title' => 'DateTime title error',
        'label' => 'mydatetime', // Bug 1 and 2
        // 'label' => 'time', // Bug 3
    ],
    'columns' => [
        // Bug 1 and 2
        'mydatetime' => [
            'label' => 'mydatetime',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'dbType' => 'datetime',
                'eval' => 'datetime,null',
                // 'readOnly' => true, // Bug 2
            ],
        ],
        // Bug 3
        'mytime' => [
            'label' => 'mytime',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'dbType' => 'time',
                'eval' => 'time,null',
            ],
        ],
    ],
    'types' => [
        '0' => ['showitem' => 'mydatetime,mytime'],
    ],
];

SQL:

mydatetime datetime default NULL,
mytime time default NULL,

Source of the problem

Classes using this value (as far as I know)

  • Bug 1: TcaRecordTitle:320,360
    • Example dataflow
      • Database: 2022-02-22 12:00
      • DatabaseRowDateTimeFields: generates a string like 2022-02-22T07:00:00-05:00 (UTC)
      • TcaRecordTitle: converted to a timestamp by strtotime to 1645531200
      • TcaRecordTitle: converted by BackendUtility::datetime (with date function, formats in server timezone) to 2022-02-22 07:00
  • Bug 2: InputDateTimeElement:114
  • Bug 3: TcaRecordTitle???#
  • Custom functions using formattedLabel_userFunc

Files

dateTimeTitle-readOnly.png (9.67 KB) dateTimeTitle-readOnly.png Bug 2: wrong time for readonly field Imko Schumacher, 2022-02-14 19:53
dateTimeTitle-saved.png (11.5 KB) dateTimeTitle-saved.png Bug 1: Title with time offset Imko Schumacher, 2022-02-14 19:53
dateTimeTitle-time.png (12.6 KB) dateTimeTitle-time.png Bug 3: full iso date in title Imko Schumacher, 2022-02-14 19:53

Related issues 2 (2 open0 closed)

Related to TYPO3 Core - Feature #61110: Support for timezones in all date fields in TYPO3 BENew2014-08-21

Actions
Related to TYPO3 Core - Task #105643: Transform all dates in DatabaseRowDateTimeFields to DateTimeUnder Review2024-11-19

Actions
Actions #1

Updated by Gabe Troyan almost 3 years ago

  • Assignee set to Gabe Troyan
Actions #2

Updated by Imko Schumacher almost 3 years ago

Some hints for possible solutions:

Option A

Remove the first part of the if clause or even the whole file (DatabaseRowDateTimeFields):
  • Needs adjustments inside InputDateTimeElement
  • Matches "assumptions" inside TcaRecordTitleTest (2014-12-31 23:59:59) better
  • check other places
  • ...

Option B (simple, but not lasting)

Remove the . ' UTC' in DatabaseRowDateTimeFields:47

                    $result['databaseRow'][$column] = date('c', (int)strtotime($result['databaseRow'][$column]));
Problems:
  • Does not fix bug 3
  • This and the current solution does not match expectations in the core
Actions #3

Updated by Imko Schumacher 12 months ago

  • TYPO3 Version changed from 11 to 13

Bugs are still present in TYPO3 v13 (tested with 9e1e9493ff5e0b615e4921b2612226c684759d3f).

Updated TCA;

return [
    'ctrl' => [
        'title' => 'DateTime title error',
        'label' => 'mydatetime', // Bug 1 and 2
        // 'label' => 'mytime', // Bug 3
    ],
    'columns' => [
        // Bug 1 and 2
        'mydatetime' => [
            'label' => 'mydatetime',
            'config' => [
                'type' => 'datetime',
                'format' => 'datetime',
                'dbType' => 'datetime',
                'nullable' => true,
                // 'readOnly' => true, // Bug 2
            ],
        ],
        // Bug 3
        'mytime' => [
            'label' => 'mytime',
            'config' => [
                'type' => 'datetime',
                'format' => 'time',
                'dbType' => 'time',
                'nullable' => true,
            ],
        ],
    ],
    'types' => [
        '0' => ['showitem' => 'mydatetime,mytime'],
    ],
];

Actions #4

Updated by Markus Klein 12 months ago

  • TYPO3 Version changed from 13 to 11
Actions #5

Updated by Markus Klein 4 months ago

  • Related to Feature #61110: Support for timezones in all date fields in TYPO3 BE added
Actions #6

Updated by Benjamin Franzke 1 day ago

  • Related to Task #105643: Transform all dates in DatabaseRowDateTimeFields to DateTime added
Actions #7

Updated by Gerrit Code Review 1 day ago

  • Status changed from New to Under Review

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

Actions #8

Updated by Gerrit Code Review 1 day ago

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

Actions #9

Updated by Gerrit Code Review 1 day ago

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

Actions #10

Updated by Gerrit Code Review about 13 hours ago

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

Actions #11

Updated by Gerrit Code Review about 12 hours ago

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

Actions

Also available in: Atom PDF