Module Monday: Office Hours

Office Hours module

Lets say you are building a site for an institution with multiple locations, each of which have varying hours depending on time of year or other variables. What is the best way to manage this data? This is a pretty common type of content modeling problem. The easiest thing to do is to just give each location a text field for their hours, but that limits display options and is prone to data entry errors. You could also build out a whole fancy content type with multi-instance date fields, but that could get bloated and difficult to maintain pretty quickly.

How about option three - the Office Hours module, which was created for exactly this purpose. Office Hours implements a custom field type just for storing location opening and closing times. It also integrates with Views and Feeds, and has a ton of configuration options for storing and displaying hours exactly how you want.

Setup is pretty typical. Install the module, then add the field to your content type. You will be offered a wide range of options for setting up your field, including defaults, formatting options and the ability to set multiple sets of hours per day (think of a restaurant that is open for lunch and dinner.) Once you're all setup, add a node and you'll be able setup the hours for it. Save the node and there you are, a nice display of your hours.

Office Hours display

However what if those hours aren't displayed exactly how you want? Lucky for you there is an extensive array of display hours available in the display settings for the field. These allow you to adjust time format, compress days with the same hours, manage separators, and a wide array of other options. There number of uses cases covered by this configuration should meet any need you have.

Office Hours formatter config

Additionally, since Office Hours integrates with Views, you can build whatever types of listings you want. The README contains extensive documentation about how to build those Views for a variety of use cases.

One downside of Office Hours is that the results are not indexable by Solr, which means they can't be searched. How big a deal this is will depend on your implementation.

Otherwise, Office Hours is a great example of a well done module that meets a common use case just as you would want it to. On top of that, it provides a great reference point for developing a custom field type, with lots of examples for implementing different types of formatting and confiugration.

Get in touch with us

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