Bug (approved)

effort logged as a duration without ':'/#7268

Summary

approved
Dec 2, 2008
100%
Jan 11, 2011
Dec 2, 2008 / brasti
Jan 11, 2011 / pixtur
 

Attached files

Summary
effort.inc.php
37233 bytes / ID 7415 / Dec 19, 2008
Show Details
 
This task does not have any text yet.
Doubleclick here to add some.

Issue report

Minor
Always
Windows
0.0803 also with online demo 807
Change the settings of a user to "log effort as duration"

If then the user creates a new effort and he wants to log a duration of ... say ... 8h.
So he fills in "8" instead of "8:00". Then this results in an error message:
"Tue, 02.12.2008 8 is not a known format for date"
But still there's a an effort created at date Thu Jan 1, 1970 01:00am 01:00am whith a length of 0h.

See the efforts of user3 for project with ID=4615 in the online demo of streber.
Streber should accept values without ":"

and furthermore if an user files in "8.25h" Streber should be able to transform this to "8:15".
So one can choose the format of the duration.
Adding the following if statement to /render/render_fields.inc.php at line 168 will check if the inserted value is numerical and convert the value to houres and minutes, resolving the mentioned bug:


from /render/render_fields.inc.php line 168


    # Checking if the inserted value for time is numeric, this means the user filled in a float value.
    # Converting the float value to the format "00:00:00" Where by the function rounds on minutes. 
    # This can be expanded to round on seconds.
    if(is_numeric($value_time)){
	#houres
	$thoures = (int)$value_time;
 	$thoures = sprintf("%02d",$thoures);
        #minutes
        $tminutes = $value_time - $thoures;
        $tminutes *=60;
        $tminutes = sprintf("%02d",round($tminutes));
	#resulting time string
	$value_time = $thoures.":".$tminutes.":00";
	new FeedbackMessage(sprintf(__("<b>%s</b> is the inserted time."), $value_time));    
	}


A remark:
This is code for the function "FieldDatetime_parseForm"
So this will apply for all Datetime fields.
Don't think that's a problem.
 

5 Comments

pixtur:sounds reasonable to me...

4 years ago

But best solution would be a splitted duration input field like suggested earlier: One float and one dropdown-list with minutes, hours, days, weeks.


brasti:some remarks

4 years ago

I added a suggestion to convert a float value to hours and minutes.

But I have the following question:
When there's a problem with the value not in the correct format, is there a way to cancel the insert or update to the database and return to the edit effort page?

This to avoid the creation of the useless effort record "00-00-00 00:00:00"?

Regards

pixtur:I will have to take a look at this.

4 years ago


brasti:found it!

4 years ago (4. update 3 years ago)

At some point in the function effortEditSubmit() in effort.inc.php the fields are getting parsed.

When there is a problem with parsing of the Datetime fields voor time_start en time_end then the parse function returns zero.
So by checking if:
strToGMTime($effort->time_end) ==0
we can put the validatingvariable $failure to true.
Like this the insert of the record is cancelled and we return back to the effortedit form.
Like that we avoid the creation of records containing zero.

I've uploaded an "effort.inc.php" file where you can see how I solved it.
(look for: Edited by Brasti)

Some remarks:
  • I did not find a way to remember the inserted values of the user before parsing them and re-use this values in the editform after the submit. So I chose a default value to avoid the zero for the time_start and time_end value.
  • A better way for this would be self-validating fields. So when a user leaves the field the inserted value get's validated. Like suggested in field validation
  • When a user creates a new effort in "As_duration" mode streber calculates a value depending on the last booked effort. I don't think this makes any sense. For me a default value of 0 houres at date today is enough.
  • I don't now if you now but in the effortedit page (not only but every datetime field) you can change the value of the houres by clicking and dragging the mouse to the left or right on the *h* in <h>. I find this feature not very usefull or handy. I realy doubt if it's used a lot. For me you can dump it.


Regards


pixtur:

3 years ago

ok, added to revision. Thanks for pointing this out!