Jump to content

Time Field


Macrura
 Share

Recommended Posts

I need to have a time field, for a recurring class start and end; i can't do it with the built in date/time field because i don't need the date...

i was wondering if anyone had already come up with a way to implement a time value without date.. something like this?

https://drupal.org/project/timefield

i previously implemented a time picker on a formbuilder form which allowed you to pick time only; maybe i'll need to build a module to put the time selector in a text field on my form... maybe something like this

http://jonthornton.github.io/jquery-timepicker/

Link to comment
Share on other sites

How about using text field and simple pattern to keep it like date?

If you put this into pattern setting of your textfield: [0-9]{1,2}:[0-9]{2} it will only allow values like 9:15, 14:20 etc... Of course that regexp could be tweaked to US friendly if pm / am etc are needed.

I find all the timepickers clumsy compared to clear and simple text input.

Oh, and if data needs to be 100% valid, then this is no good of course, since this allows values like 99:99. Regexp could be tweaked though...

  • Like 3
Link to comment
Share on other sites

  • 4 months later...

Thanks apeisa,

this is a very good solution, i will use this!!

And for the record, here is my solution for the 24h format:

^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$

Logic:

The first number (hours) is either:
a number between 0 and 19 --> [0-1]?[0-9] (allowing single digit number)

or

a number between 20 - 23 --> 2[0-3]



the second number (minutes) is always a number between 00 and 59 --> [0-5][0-9] (not allowing a single digit)

  • Like 4
Link to comment
Share on other sites

Assuming that those time entries alway have a start and an end. And as the date is not necessary I assume that those time stamps never overlap the span of 24 hours.

I do think it's not that difficult to "rebuild" Soma's slider a bit.

Set it to RangeSlider and set the Max value to 86400 (seconds a day). or to 96 (  all quarter of hours a day  )

Then the only thing you need to change is the value for the slider labels.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...