Problem/Motivation

Timestamps in Drupal come in two forms:

1. Unix timestamps (integer):
This type has been used in Drupal from the beginning. It's mostly used for base entity fields ('created' and 'changed').

2. Datetime strings (varchar):
This type was adopted from the Drupal 7 Date module.

There are a few issues with the current implementation:

  1. This duality complicates DX (Developer Experience). It's not easy to compare different types in SQL expressions.
  2. Neither of these types uses native DB types for storing datetime values.
  3. Mocking system time in tests is a bit tricky. The TimeInterface from the Datetime component is not compatible with PSR-20, and Drupal does not provide any helpers for mocking system time.

Proposed Solution

Create a new field type for timestamps that utilizes native DB timestamp types and integrates with PSR-20.

I created a module that can serve as PoC for the new implementation.

Comments

chi created an issue. See original summary.

chi’s picture

Issue summary: View changes
catch’s picture

Project: Drupal core ideas » Drupal core
Version: » 11.x-dev
Component: Idea » database system

I think this is better discussed in the core queue, moving to database system because using native db types is probably the hardest thing to change.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.