Posted by kmonty on February 27, 2009 at 9:29pm
| Project: | Duration |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
I am setting up a athletic training log and finding Duration to be the ideal CCK extension to allow people to enter in the duration of a days activity. I was hoping to use Views Calc to display the SUM and Average of the the daily duration for a specified period of time, however, the Views Calc method cannot sum ISO 8601. I created a custom display that converted the H:i data to be a decimal (read: 2hrs 30mins -> 2.50) but quickly realized that Views Calc sums the values from the database, not the output.
Can anyone think of any potential solutions?
Comments
#1
Background to ISO 8601 in a nutshell: One cannot know the exact duration of "1 month" without knowing the start or end date of the duration. ISO 8601 captures that information correctly even if the start or end date is not known. The downside of that additional flexibility is that performing calculations on ISO 8601 values requires code that knows how to handle dates and durations. (Which is mainly why there is a Duration API.)
However, the Duration field also stores the approximate duration ("what we can guess without knowing the start or end date") in a cached field named "approx_seconds". If you don't use months or years then this field is still accurate, so you can tell Views Calc to calculate on that field instead of the "iso8601" one.
#2
Oh right, issue status. I'm setting this to "active (needs more info)", please close it as fixed if the approx_seconds column solves the issue. Otherwise, please explain what doesn't work out still.
#3
Currently, as far as I can tell, there is no way to access the approx_second database column through views, which is basically the problem. Views Calc works by doing math on the database columns defined in a view's fields. Unless I am completely missing something, there is not a way to get the approx_seconds as a field. Even so, that would only sum the seconds (which would at least be useful because I could easily convert that to hours/minutes using php in preprocessing.)
Maybe a solution is to create a second selectable field that accesses approx_second in addition to ISO 8601?
#4
Did anyone solve this?
#5
Subscribing.
#6
Trying to do the same thing. Want to do calculations based on a users time spent completing a particular activity. Hours, Minutes, Seconds only.
#7
Needs an implementation of 'views data' for hook_field_info(). Some other CCK modules have similar implementations, so the best bet is probably finding a CCK field module that provides two kinds of field data for Views, and copying/adapting the respective code.
Unless you're massively lucky though, I probably won't spend time implementing this feature. Which means for you: talk is bronze, code is gold.
#8
subscribing
#9
I've created a patch which provides another field type for the views UI and another field formatter.
Also, I've added a new field handler specific for this field.
This new field type returns the duration in seconds instead of ISO 8601.
This way we can SUM the values.
The only problem is: this new field option works only with the new formatter and handler.
Which means you can't fetch the duration in seconds and display the sum in any other format (eg HMS, time ago)
I think this is caused by the "Views Calc" module.
Files:
1. The patch includes both formatter and views field option.
2. The .zip includes the new handler.
#10
@mathrm - thanks this looks useful. After applying the patch I can't use the duration field as a sort criteria in views. Is there something further I need to do to be able to sort by approx_second?
#11
pragnatek, I don't know if you're aware of this patch for sorting: http://drupal.org/node/494612 (and I have no idea if these two patches are incompatible!)
Speaking of which, I'm not patch-savvy! Is there any chance of this patch being rolled into a new release? I'd really like to be able to show average speed in my bike-ride-logging site. Thanks.
#12
I would like to now more on how to set this, i use the Date module now, with date and time.
Any advise on how to implement this? I'm not patch savy either.
#13
subscribe