Thread: Time Column
View Single Post
Old 12-18-2011, 03:32 AM   #5
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
It seems that you want a column to express duration in minutes, not a time. I can think of one way to do this, but it isn't particularly pretty.

First: what doesn't work. Using the formatting feature of float and integer doesn't work because you cannot separate the number into the two hours/minutes components. Using a datetime with a format of "hh:mm" doesn't work because it isn't a duration; the rest of the date will be set to something, making the column not sortable.

What does work is to use a custom integer field to enter the number of minutes, and then use a custom composite field and a custom template function to format that number-of-minutes into hours and minutes. One possible template function is
Code:
Function: myHoursMinutes
Arg count: 1
Program code:
def evaluate(self, formatter, kwargs, mi, locals, x):
	if not x:
		return ''
	r = int(x)
	return "%d h %d min"%(r/60, r%60)
Assuming that the number-of-minutes column is named #myint, The template in the composite column would be something like:
Code:
{#myint:myHoursMinutes()}
Personally, I wouldn't bother with any of this. I would use a floating point column and enter the number of hours as the integer part and the number of minutes as the fractional part, and let it display as "1.45" or "2.00", etc.
chaley is offline   Reply With Quote