[Tool] Create Date/Time Formatter tool
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3554737. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) Related to !70 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>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&rsquo;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.</p> <p>This tool should allow both human-readable and machine-readable output formats, and support different timezones and locales for display or processing purposes.</p> <p>The tool could be named **"Format Date/Time"** or **"Date/Time Formatter"**, consistent with existing "Load Data" naming conventions.</p> <p>The inputs for this tool should be:</p> <p>* **Input Value** (string|int, required). The date/time input. Can be a timestamp, an ISO8601 date, or a relative expression like &ldquo;+1 day&rdquo;.<br> * **Input Format** (string, default null). Optional format of the input date if it&rsquo;s a formatted string (e.g., `Y-m-d H:i:s`). If null, attempt to auto-detect or treat as ISO8601.<br> * **Output Format** (string, default `Y-m-d H:i:s`). The PHP date format string or Drupal-compatible format identifier to produce.<br> * **Timezone** (string, default site timezone). The timezone to apply for output formatting.<br> * **Locale** (string, default null). Optional locale override for language-aware formatting.<br> * **Relative (boolean, default false)**. If true, output relative time in English (&ldquo;3 hours ago&rdquo;, &ldquo;in 2 days&rdquo;) instead of absolute date.</p> <p>The output format will be a single string with the formatted date/time.<br> If **Relative** is enabled, it returns a human-readable relative difference instead.</p> <p>No access checks needed</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>* If the tool_utilities submodule does not exist yet, create the metadata for it.<br> * Create the **"Date/Time Formatter"** tool according to the specification above.<br> * Implement logic using Drupal&rsquo;s `DateFormatterInterface` for localization and timezone handling.<br> * Support PHP date format strings and core Drupal date format identifiers.<br> * Implement unit tests to verify:<br> * Timestamp and string input handling.<br> * Timezone conversion correctness.<br> * Locale-based formatting consistency.<br> * Relative formatting output accuracy.<br> * Provide example usages and documentation for both static and dynamic date/time transformations.</p>
issue