Module Monday: HMS Field

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.

Get in touch with us

Tell us about your project or drop us a line. We'd love to hear from you!