fgelinas / timepicker

A jQuery UI Time Picker
http://fgelinas.com/code/timepicker
GNU General Public License v2.0
266 stars 84 forks source link

Feature Request: Custom parsing and formatting functions #58

Closed remyroy closed 8 years ago

remyroy commented 11 years ago

Hello,

It would be nice to be able to define custom parsing and formatting functions for the time picker. This would help me with my use case where the user may input his time using different formats which are all accepted by the application but are not by the time picker since the time picker may only potentially accept one.

Regards,

remyroy commented 11 years ago

I did manage to do it using something like

$(function() {
    $.extend($.timepicker, {
        parseTime: function (inst, timeVal) {
            var retVal = new Object();
            retVal.hours = -1;
            retVal.minutes = -1;

            if(!timeVal)
                return '';

            // My own function here overwriting retVal.hours and retVal.minutes

            return retVal;
        }
    });
});

If you feel like this is what people should do, just close this issue.

fgelinas commented 11 years ago

Hi Remy, I think you solution to define your own parseTime function is good. I'd like to know what time format you need to parse, maybe the parseTime function can be more flexible on that.

remyroy commented 11 years ago

I wanted the application to be able to parse different formats and be kind of tolerant in a Canadian mixed English/French locale. I wanted to support 4 different formats:

I also wanted to support optional 0 in front of the hour value in as cases. For instance '08' (8 o'clock or 8:00).

I know that this might not be a common use case but I strongly believe that the application should be as tolerant as possible for input values when it can be parsed and understood without ambiguity.