If a cck date field is configured to have both a start and end time, you can easily have access to the start time, end time or both as a field in a View, but having access to the duration isn't as convenient.
Attached patch adds a new option to date formatters to get this.
The core functionnality is rather simple: it adds a new formatter, and calls date_difference on the two date objects for this new mode in the theme function. The trickier part was the need to add a granularity setting to get meaningful result: in this patch I've reused the code from date_sql_handler::granularity_form to avoid duplication, but the options keys of the select generated by granularity_form doesn't match the granularity argument expected by date_difference, hence the not so beautiful concatenation with 's' in the theme function before calling date_difference.
While developed primarily for Views, this seems to work just fine for formating the field on the node display too. The granularity setting is displayed no matter what the Formatter value is in the CCK Field Display Setting page though, matching the style of the other fields of this form.
| Comment | File | Size | Author |
|---|---|---|---|
| date_difference.patch | 2.4 KB | DeFr |
Comments
Comment #1
slybud commentedAwesome !
Comment #2
quadbyte commentedSweet !
Comment #3
damienmckennaThis would be a useful feature on D7 too.