[Tool] Create Date/Time Formatter tool

Created on 28 October 2025, 3 months ago

Problem/Motivation

You need to be able to format and manipulate date and time values in a standardized way. Since Drupal already has strong date and timezone handling built on PHP’s DateTime and the core datetime services, a generic utility tool can provide an easy interface for converting timestamps or date strings into formatted representations.

This tool should allow both human-readable and machine-readable output formats, and support different timezones and locales for display or processing purposes.

The tool could be named **"Format Date/Time"** or **"Date/Time Formatter"**, consistent with existing "Load Data" naming conventions.

The inputs for this tool should be:

* **Input Value** (string|int, required). The date/time input. Can be a timestamp, an ISO8601 date, or a relative expression like “+1 day”.
* **Input Format** (string, default null). Optional format of the input date if it’s a formatted string (e.g., `Y-m-d H:i:s`). If null, attempt to auto-detect or treat as ISO8601.
* **Output Format** (string, default `Y-m-d H:i:s`). The PHP date format string or Drupal-compatible format identifier to produce.
* **Timezone** (string, default site timezone). The timezone to apply for output formatting.
* **Locale** (string, default null). Optional locale override for language-aware formatting.
* **Relative (boolean, default false)**. If true, output relative time in English (“3 hours ago”, “in 2 days”) instead of absolute date.

The output format will be a single string with the formatted date/time.
If **Relative** is enabled, it returns a human-readable relative difference instead.

No access checks needed

Proposed resolution

* If the tool_utilities submodule does not exist yet, create the metadata for it.
* Create the **"Date/Time Formatter"** tool according to the specification above.
* Implement logic using Drupal’s `DateFormatterInterface` for localization and timezone handling.
* Support PHP date format strings and core Drupal date format identifiers.
* Implement unit tests to verify:
* Timestamp and string input handling.
* Timezone conversion correctness.
* Locale-based formatting consistency.
* Relative formatting output accuracy.
* Provide example usages and documentation for both static and dynamic date/time transformations.

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany marcus_johansson

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024