Module Monday: HMS Field

Parent Feed: 

Drupal's much-loved Date and Calendar modules are great for storing and displaying calendar-style dates, and can store "time of day" information for extra precision. If you're trying to store a different kind of time, though -- say, the length of a song or the number of minutes in a video -- the Date module is an awkward fit. That's where the HMS Field module comes in.

Screenshot of HMS Field in action

Instead of storing an absolute date and time, HMS Field (short for 'Hours, minutes, and seconds') stores a simple integer representing a number of seconds. The field widget it ships with lets you enter a number like "5:45," while the field formatter allows you to display it in a similar style. There's not much to explain beyond that point -- HMS Field, as the Brits say, does what it says on the tin. It's easy to sort and filter Views based on the field's values, and writing custom display formatters for the field is relatively simple.

Screenshot of the HMS field configuration

The only downside to the module is the relatively limited display formatter it ships with. It's great for displaying the hours, minutes, and seconds that are stored, but it doesn't support natural language output like "10 minutes" or "4 hours." Even without those options, however, HMS Field is a great addition to any site builder's content-modeling toolbox.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web