Forum OpenACS Q&A: ad_form date

Collapse
Posted by James Thornton on
Trying to use ad_form to set and get dates in postgres 7.2.3; it's setting it ok, but when it displays it in the edit form, it sets the values to 12:00 AM.

ad_form -name dealer_location_hours -export {location_id} -form {

    location_hours_id:key(moto_location_hours_id_seq)

    {day_begin:text(select) {label "Beginning Day"} {options {$day_options}}}
    {day_end:text(select) {label "Ending Day"} {options {$day_options}}}
    {time_open:date,to_sql(linear_date),from_sql(sql_date)
      {label "Opening Time"}
      {format "HH12:MI AM"}
      {help}}
    {time_close:date,to_sql(linear_date),from_sql(sql_date)
      {label "Closing Time"}
      {format "HH12:MI AM"}
      {help}}

} -select_query {
    select day_begin,
          day_end,
          to_char(time_open,'YYYY MM DD HH24 MI SS') as time_open,
          to_char(time_close,'YYYY MM DD HH24 MI SS') as time_close
    from  moto_location_hours
    where  location_hours_id = :location_hours_id
} -validate {
} -new_data {

    db_dml do_insert "
    insert into moto_location_hours (
      location_hours_id,
      day_begin,
      day_end,
      time_open,
      time_close,
      location_id
    ) values (
      :location_hours_id,
      :day_begin,
      :day_end,
      to_timestamp(:time_open,'YYYY MM DD HH24 MI SS'),
      to_timestamp(:time_close,'YYYY MM DD HH24 MI SS'),
      :location_id
    )"

}

moto=# select * from moto_location_hours;
location_hours_id | day_begin | day_end |      time_open      |    time_close      | location_id
-------------------+-----------+---------+---------------------+---------------------+-------------
                22 |        2 |      5 | 0001-01-01 09:00 BC | 0001-01-01 19:00 BC |          12
(1 row)

Collapse
2: Re: ad_form date (response to 1)
Posted by Jerry Asher on
Let me know if you come up with a good solution, under time pressure, I've resorted to using a -edit_request block and then within that block manually setting the time widget's value with things like:

set v [template::util::date::create ... ]
template::element set_value my_form time_widget $v

In general, I've found the time templating stuff could use a good cleaning.  I can't get year select boxes, they always are text boxes even if I don't specify the little "t".

Collapse
3: Re: ad_form date (response to 1)
Posted by Jade Rubick on
Please let me know what you find out, and if you would like to help others out, I can put something up on http://rubick.com/openacs/ad_form

There is some stuff there on ad_form and dates, but I'm not sure that it deals with times. It might provide some help, though.