Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

duration_field

3,815 sites Security covered
View on drupal.org

Overview

This module creates a new duration field, that can be added to any entity. A duration field can collect any combination of year, month, day, hour, minute and second. Field settings allow for the site builder to determine what level of granularity they wish to collect from users, so if the required level of granularity is a date, the field settings would be set to collect year, month and day. The module is flexible in that users could choose to only collect year and seconds. While this doesn't really make sense for most logical data collection, the module has the flexibility that allows it to happen.

Verson 8.x-2.x

Version 2 of the module has been released. As of 8.x-2.0-rc1, there is an upgrade path between version 8.x-1.x and 8.x-2.x of the module. To update:

  1. Take a backup of your database
  2. Run update.php

Version 2.x of the module is a fairly significant re-write, that ensures it works with Drupal core APIs, including the Typed Data API, the Form Element API, the Field API, and the Constraint API. It is the recommended version at this point for new installations of the module. This version is ready to go, and all the automated tests from version 1 are working, so the module should work fine.

Technical Overview

Version 8.x-2.x of the module fully integrates with Drupal APIs at a deep technical level. The module creates:

  • A new Typed Data type: Date Interval. This data type is a wrapper for PHP DateInterval objects.
  • A new Typed Data type: Granularity String. This data type is used to store granularity strings. For specifics on what a granularity string is, see Drupal\duration_field\Plugin\DataType\GranularityStringData.
  • A new Typed Data type: ISO 8601 Duration String. This data type is used to store ISO 8601 duration strings.
  • A new form element: duration. This form element takes in 8601 Duration Strings or PHP DateInterval objects as its value/default value, and outputs PHP DateInterval objects upon form submission. The form element collects year, month, day, hour, minute and seconds, and by passing the #granularity, the developer can select which time elements should be included.
  • A new form element: granularity. This form element takes in a granularity string as value/default value. The element provides checkboxes for year, month, day, hour, minute, and second, and outputs a granularity sting upon form submission.
  • Validation constraints for date intervals, ISO 8601 duration strings, and granularity strings.

Development

git clone [email protected]:project/duration_field.git
cd duration_field
ddev config --project-type=drupal --docroot=web --php-version=8.3 --corepack-enable --project-name=duration-field
ddev add-on get ddev/ddev-drupal-contrib
ddev add-on get ddev/ddev-selenium-standalone-chrome
ddev start
ddev poser
ddev symlink-project
ddev drush site:install -y
ddev drush pm:install duration_field -y
ddev drush config:export -y
ddev drush user:login

Activity

Total releases
1
First release
Jul 2025
Latest release
9 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
8.x-2.2 Stable Jul 17, 2025