Project

General

Profile

Actions

Bug #98252

open

TCA Default value for times cannot be set

Added by C. Gogolin over 1 year ago. Updated 11 months ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Start date:
2022-09-02
Due date:
% Done:

0%

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

Description

Hi,

In my extension I have created a table which contains a time field. Under Typo3 10.x everything was fine. But when I switched to Typo3 11, the default value was no longer displayed.

Here is the table.sql:

#
# Table structure for table 'tx_participants_domain_model_event' 
# 
CREATE TABLE tx_participants_domain_model_event (
   uid int(11) UNSIGNED DEFAULT '0' NOT NULL auto_increment,
   pid int(11) DEFAULT '0' NOT NULL,
   ,..
   time VARCHAR(10) DEFAULT '19:00:00' NOT NULL,    
   ...
   PRIMARY KEY (uid),
   KEY parent (pid)
);

Here is the TCA configuration: (works for Typo3 10 , but not for Typo3 11)

'time' => [
            'label' => 'LLL:EXT:participants/Resources/Private/Language/locallang_db.xlf:tx_participants_domain_model_event.time',
            'config' => [
                'type' => 'input',
                'renderType' => 'inputDateTime',
                'dbType' => 'time',
                'eval' => 'time',
                'default' => 68400, // 19:00h
                'mode' => 'useOrOverridePlaceholder'
            ]
        ],

Then I did some searching in the core code and found:
./sysext/core/Classes/Database/Query/QueryHelper.php

The method getDateTimeFormats() does not set the reset to zero but 0 for the type "time".

  /**
     * Returns the date and time formats compatible with the given database.
     *
     * This simple method should probably be deprecated and removed later.
     *
     * @return array
     */
    public static function getDateTimeFormats()
    {
        return [
            'date' => [
                'empty' => '0000-00-00',
                'format' => 'Y-m-d',
                'reset' => null,
            ],
            'datetime' => [
                'empty' => '0000-00-00 00:00:00',
                'format' => 'Y-m-d H:i:s',
                'reset' => null,
            ],
            'time' => [
                'empty' => '00:00:00',
                'format' => 'H:i:s',
                'reset' => 0,
            ],
        ];
    }

This has the consequence that a few steps later my default value is not used. (The fact that I have to patch core again and again can't be a solution ;-) )
Unfortunately I can't understand why a 0 and not (as with "date" and "datetime") zero is specified here. But if I patch the QueryHelper and change 0 to zero, we can use the defaults again.

It would be nice if this is fixed in a timely manner. (Or does this all have to be solved completely different?).

Thanks
Clemens


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #97216: Time value "midnight" (00:00) is not acceptedClosed2022-03-21

Actions
Related to TYPO3 Core - Bug #99847: Null value for time field is ignored in BEResolved2023-02-06

Actions
Actions #1

Updated by C. Gogolin over 1 year ago

  • Target version changed from Candidate for Major Version to Candidate for patchlevel

Currently I use this method version:

 /**
     * Returns the date and time formats compatible with the given database.
     *
     * This simple method should probably be deprecated and removed later.
     *
     * @return array
     */
    public static function getDateTimeFormats()
    {
        return [
            'date' => [
                'empty' => '0000-00-00',
                'format' => 'Y-m-d',
                'reset' => null,
            ],
            'datetime' => [
                'empty' => '0000-00-00 00:00:00',
                'format' => 'Y-m-d H:i:s',
                'reset' => null,
            ],
            'time' => [
                'empty' => '00:00:00',
                'format' => 'H:i:s',
                'reset' => null,
            ],
        ];
    }
Actions #2

Updated by Georg Ringer over 1 year ago

  • Description updated (diff)
Actions #3

Updated by Georg Ringer over 1 year ago

  • Related to Bug #97216: Time value "midnight" (00:00) is not accepted added
Actions #4

Updated by JAKOTA Design Group GmbH about 1 year ago

  • Related to Bug #99847: Null value for time field is ignored in BE added
Actions #5

Updated by JAKOTA Design Group GmbH about 1 year ago

Hi,

The main issue in my opinion is that date/time fields are not nullable by default.
If you use a varchar field you have the empty state (which is ignored in the backend) but for int field its not so easy.

And now we have code that tries to decide what's the meaning of the data....
This is more problematic with time data than dates.

Does 0 aka 00:00:00 means midnight or empty/time not set?

A proper fix for this issue would be to use nullable date/time fields.
The problem with that right now is that nullable date/time fields are broken in the backend. see linked issue #99847

I've created a fix for that:
https://review.typo3.org/c/Packages/TYPO3.CMS/+/78096

Once this is merged the current behaviour could be changed to stop the guessing game if a date/time field is set or not.
Not set or empty translates to null or if null is not allowed the default value from TCA is used.

But this would probably be a breaking change and I wouldn't count on it before v13.

Actions #6

Updated by C. Gogolin 11 months ago

Thanks for analyse and your fix.

Actions

Also available in: Atom PDF