Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
13 posts Page 2 of 2
Update: for consecutive increasing (no reset each hour) see this post: viewtopic.php?f=8&t=11424

A known way to create dropdown for time selection is to type in manually editable's opt_values as in following (non-optimal) example.
Code: Select all
<cms:editable name="start_time" label="Time From (24 Hrs)"
    opt_values=' Unspecified |
              00:00 | 00:30 | 01:00 | 01:30 | 02:00 | 02:30 | 03:00 | 03:30 |
              04:00 | 04:30 | 05:00 | 05:30 | 06:00 | 06:30 | 07:00 | 07:30 |
              08:00 | 08:30 | 09:00 | 09:30 | 10:00 | 10:30 | 11:00 | 11:30 |
              12:00 | 12:30 | 13:00 | 13:30 | 14:00 | 14:30 | 15:00 | 15:30 |
              16:00 | 16:30 | 17:00 | 17:30 | 18:00 | 18:30 | 19:00 | 19:30 |
              20:00 | 20:30 | 21:00 | 21:30 | 22:00 | 22:30 | 23:00 | 23:30 |'
    type='dropdown'
/>


What if we need 5 minutes step? It could become a very sad experience.. Not to mention if step is 3,2,1 minutes ;)
We definitely can have a helper.

Code: Select all
Minutes reset every hour no matter what.
Prints timetable suitable for time-selection dropdown
<cms:call 'time_options' minute_steps='45' from='12' to='15' sep='|' />
=> 12:00 | 12:45 | 13:00 | 13:45 | 14:00 | 14:45 | 15:00 | 15:45

Get it as json => ["12:00","12:45","13:00","13:45","14:00","14:45","15:00","15:45"]
<cms:call 'time_options' minute_steps='45' from='12' to='15' as_json='1' />


An dropdown definition becomes as follows:
Code: Select all
<cms:embed 'functions/date-time/time_options.func' />

<cms:editable name="start_time" label="Time From (24 Hrs)"
    opt_values=" Unspecified | <cms:call 'time_options' minute_steps='30' />"
    type='dropdown'
/>
I have a datetime editable whose value is saved through a DBF as:

Code: Select all
<cms:editable name="departure_time" label="Departure Time" type="datetime" show_labels="0" allow_time='1' am_pm='0' only_time='1' default_time='@current' minute_steps="1" />


Now is it possible to add 5hours and 21minutes to the value of the above region and display the new time as
Code: Select all
<cms:date new_departure_time format='H:i' />


For example:
if value saved in the departure_time is: 23:15
so after adding the 5hrs and 21mins the value should be: 04:36

I am using php code to achieve this (currently) but was eager to know if the same can be done using couch tags:
Code: Select all
<cms:php>
$date = new DateTime("<cms:date departure_time format='H:i' />");
$date->add(new DateInterval('PT10H'));
echo $date->format('H:i');
</cms:php>


Please advice.

Regards,
GenXCoders
Image
where innovation meets technology
genxcoders wrote: Please advice.

@genxcoders, do you have any issues while using my code examples from this topic? Please clarify.
13 posts Page 2 of 2

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 2 guests

cron