kimai1
kimai1 copied to clipboard
automated formatting of time entry
Feature Request: Automated time formatting in the add entry dialouge
Expected behaviour
if one types "11" is evaluated to 11:00:00 if on types "1145" it is evaluated to 11:45:00 of one types "114532" it is evaluated to 11:45:32 Thereby, the time entries can be entered without the ":" sign which is difficult to enter since it is not included in the num-field and also difficult to enter on mobile devices.
Actual behaviour
if one types in 11 or 1145 the time format is not valid and results in an error message
Steps to reproduce the behaviour
open manual time entry dialog and enter numbers in time fields as described above
Kimai version
0.9.2 and 0.9.3
Relevant log entries from Kimais Debug tab
Here is a code snippet that I found "somewhere" and can be used as a base (code can be optimized)
$('.dateinput').blur(function() {
//check if no letteres are entered in the field
if (!$(this).val().match(/^[a-z|A-Z|ö|ä|ü|Ö|Ä|Ü|ß]+$/)){
//add :00 if only 2 numbers entered
if ($(this).val().length == 2){
$(this).val($(this).val() + ':00');
//check if field value is unlike xx:xx
} else if ($(this).val().match(/^\d{3}|\d{4}$/)){
//format field xx:xx
$(this).val($(this).val().replace(/(\d\d)$/, ':$1'));
if ($(this).val().length < 5){
//split string and add 0 to fill up gaps in time 1:23 -> 01:23
var timeSplit = $(this).val().split(":");
if (timeSplit[0].length < 2){
timeSplit[0] = '0' + timeSplit[0];
}
if (timeSplit[1].length < 2){
timeSplit[1] = timeSplit[1] + '0';
}
$(this).val(timeSplit[0] + ':' + timeSplit[1]);
}
}
//Check if hours are > 24 or minutes > 59 and empty field if true
var timeSplit = $(this).val().split(":");
if (timeSplit[0] > 24){
$(this).val('');
}
if (timeSplit[1] > 59){
$(this).val('');
}
} else {
$(this).val('');
}
});
I figured that typing 11 already works in the current master branch v1.1.0.1389 but when typing 1130 it will round to 12:00. This reduces this ticket to the possibility of omitting the ":". note: I would suggest typing 0120 for 1:20 thereby having a one-to-one relation ship. So the user will be required to alway enter 4 digits when ommiting the ":"