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. However, additional tests need to be added for 2.x specific functionality/output, and an upgrade method from 1.x to 2.x still needs to be created so users can update. At that point, a full release of 2.x will be released.

Verson 8.x-1.x

Version 8.x-1.x will no longer be supported once a full release of 8.x-2.0 is released. Until that time, version 8.x-1.x will only receive security updates.

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.
Supporting organizations: 
Full development

Project information

Releases