A time form function
Ninja Overlord - June 1, 2008 - 18:55
| Project: | Helpers |
| Version: | 5.x-1.x-dev |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Ninja Overlord |
| Status: | duplicate |
Description
A form function to return time in a way to put into an options set for something would be good - have an hour field that could be 0-23 or 1-12 depending on another input for 12 or 24 hour, if it is 12 be sure to include am/pm select box at the end. Also good to have it be optional or which fields are returned (I can see reasons why some would want a seconds field, although I myself have no direct need for that).

#1
Sounds useful. Do you have a patch and documentation?
#2
The post was to see if it would be friendly, I'll start writing it now.
#3
Yes, it would be a good idea. First, see if the Date API module has this before spending much time on it.
I do ask that documentation (see the docs link from the project page) accompany the patch.
And when you submit a patch, assign the issue to yourself.
#4
Here's a patch - in looking at the other functions it seems the trend is to create an entire field to put in, but I felt uncomfortable doing that - what I wrote could be utilized to produce that easily enough though should that be the desired direction.
I havn't spent that much time on this, doing 5 things at once is the only reason why it took so long. I haven't yet looked at the date api either (saw your post after I produced the patch)
#5
Can't change assign when not creating a new post.
#6
For the documentation page, should this patch be integrated:
time_select_for_form($hour = 12)
This will return the options selection for an '#options' for a selection. From this point, it is a relatively easy thing to construct a time selection.
#7
I think typically, we would actually produce a form element(s). I'll take a look.
Only 5 things? That's taking it easy! ;-)
#8
Okay, updated it to fit with other parts of the module.
Documentation:
time_select_for_form($select, $hour = FALSE, $title = 'Time', $default_value = NULL, $required = FALSE, $description = '', $multiple = FALSE)
As far as other developments I could forsee doing in time (came to me when writing this post)
Add a prefix and suffix to the select adding div's (being dependant on the $select) for CSS guru's - having an hour select, a minute select, a second select, and an ampm select is all well and good, but by default they would be one above the other. Better if they are side by side.
In addition to provide an 'NA' option if it is not required (NA would work in a select for 2 numbers/letters as these all are).
#9
Thanks for this. I didn't particularly like it, but I did like the idea. #371604: Add a time form builder for forms
#10