Duration variable issue

Duration variable issue

by Marc Grober -
Number of replies: 4
Admin just installed F2F. Using the F2F gui to set a session to be for example between 3:00 and 3:30 results in F2F messaging producing a substitution as follows...

Template-> Duration: [duration]
Result-> Duration 20 hours

I have not looked at the code, but does it do substraction in a time base (i.e. from 3:20 to 4:40 would be 1 hr 20 mins, (or less optimally, 80 mins) or does it try to do things decimally as in 1.33333333333333333333333 hours which seems a bit silly.... and in either case why would "hours" be used but the number fo minutes unless there was a bug....
Average of ratings: -
In reply to Marc Grober

Re: Duration variable issue

by Marc Grober -
OK, I looked over the code briefly....

It looks like duration is stored as a decimal hour (stange, no? why introduce a decimal when the number of minutes is an integer value) so this finds the decimal component of duration and compues the minutes
$minutes = round(($duration - floor($duration)) * 60);
and this is obviously the hours
$hours = floor($duration);
and then I lose my way with

if (1 == $hours) {
$string = get_string('onehour', 'facetoface');
} elseif ($hours > 1) {
$string = get_string('xhours', 'facetoface', $hours);
}
// Insert separator between hours and minutes
if ($string != '') {
$string .= ' ';
}
if (1 == $minutes) {
$string .= get_string('oneminute', 'facetoface');
} elseif ($minutes > 0) {
$string .= get_string('xminutes', 'facetoface', $minutes);
}

because there is no test for $hours<0 though you are storing duration as an hour decimal (i.e. half and hour would be .5)

But if the message is coming out as 20 hours (when the duration is actually 20 minutes) it suggests to me the code can't address meetings less than 1 hour, which seems consistent with the php which seems to address periods of 1 hr or greater

So wouldn't it make more sense to store duration as minutesand parsing the minutes into hours and minutes create a string that said
'Duration:'$hours' hour(s) and '$minute' minute(s)'
or even changed the minute or hour to plural depending if the respective variable was >1 (or save on the code at the cost to the db by saving duration as two separate fields of hours and minutes - LOL) ?

Or you could just use : as the separator between $hours and $minutes instead of a space.....
In reply to Marc Grober

Re: Duration variable issue

by François Marier -
Hi Marc,

The duration field is actually separate from the start and end time. This is done because some sessions can be over multiple days.

When adding/editing a session, the number that is entered is in hours with fractional numbers allowed (see the contextual help next to that field).

Then it is stored in the database as a number of minutes.

Finally, it's displayed to users (on the signup page for example) in a nicer human-readable way: 1 hour 30 minutes.

Cheers,
Francois
In reply to François Marier

Re: Duration variable issue

by Marc Grober -
I see now.....
However, if I set the duraction per the context help screen to "20 minutes" and save and then copy or re-edit, the field is populated with 20, not 20 minutes, which suggests to me that "20 minutes" doesn;t work..... but if I set the field to .33 that does seem to behave as you suggest.....

Soooooo, there is apparently still some issue, though not the one I thought - LOL