RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.4k stars 2.17k forks source link

Treat 24:00 as an equivalent of 00:00 #1237

Open leonvet opened 8 years ago

leonvet commented 8 years ago

We have users entering punch in / punch out times into a timesheet and we use this great inputmask library with a basic 'h:s' mask.

Users can enter in/out times like '08:30' - '17:00', which works great.

When the user works a night shift and started working before midnight and finishes after midnight he enters time like so '23:00' - '06:00' (for example Monday night 23:00 until Tuesday morning 06:00)

In cases where we don't allow time entry that passes into the next day we currently set the 'punch out' time to '00:00', signifying the user can only enter time until midnight. So '23:00' - '06:00' gets truncated to '23:00' - '00:00'. (Some customers' back-end systems don't allow timespans across multiple days)

We would like to truncate to '24:00' so it becomes clear to the user they entered a valid punch out time but the system doesn't allow more than 24:00 hours.

If i simply set the input field value like this j$(element).val('24:00') the input field value becomes '20:0_' instead of '24:00'.

I understand 24:00 is not exactly a valid moment in time but for a nicer user experience it would be great to allow this input and treat it as '00:00'

Thanks for reading this far, can't wait to get some thoughts on this.

Regards,

Leon

RobinHerbots commented 8 years ago

@leonvet ,

To implement this you will need to extend the h and s defintions to allow setting the 24:00.

Create a custom alias, with its own definitions for hour and time. This way you do not alter the default definitions which may be used by other masks..

leonvet commented 8 years ago

Thanks @RobinHerbots for looking into this, i'll give it a go.

mz87 commented 5 years ago

I also need an option to enter just time 24:00 (alias hh:mm), but I'm confused how to extend the inputmask.date.extensions.js to add new alias that will allow this without ruining default mask. Can you please help?