Forum OpenACS Development: datetime widget problems

Collapse
Posted by Eduardo Pérez on
What is the correct way to create a date time widget and setting and getting its contents?

Right now I'm using:

template::element create new_meeting meetingdate \
    -widget date \
    -label "Date" \
    -datatype date \
    -format {YYYY-MM-DD HH24:MI} \
    -value [calendar::from_sql_datetime -sql_date "$meetingdate" -format {YYYY-MM-DD HH24:MI}]

and:

  set meetingdate [calendar_make_datetime $meetingdate]

and added this code to:
calendar/tcl/calendar-2-procs.tcl

            {YYYY-MM-DD HH24:MI} {
                regexp {([0-9]*)-([0-9]*)-([0-9]*).([0-9]*):([0-9]*)} $sql_date all year month day hours minutes

                set date [template::util::date::set_property format $date {YYYY-MM-DD HH24:MI}]
                set date [template::util::date::set_property year $date $year]
                set date [template::util::date::set_property month $date $month]
                set date [template::util::date::set_property day $date $day]
                set date [template::util::date::set_property hours $date $hours]
                set date [template::util::date::set_property minutes $date $minutes]
            }

but it fails with this error:
Request Error

can't read "year": no such variable
    while executing
"template::util::date::set_property year $date $year"
    ("YYYY-MM-DD HH24:MI" arm line 5)
    invoked from within
"switch -exact -- $format {
            {YYYY-MM-DD HH24:MI} {
                regexp {([0-9]*)-([0-9]*)-([0-9]*).([0-9]*):([0-9]*)} $sql_date all year..."
    (procedure "calendar::from_sql_datetime" line 7)
    invoked from within
"calendar::from_sql_datetime -sql_date "$meetingdate" -format {YYYY-MM-DD HH24:MI}"
    invoked from within
"template::element create new_meeting meetingdate  -widget date  -label "Date"  -datatype date  -format {YYYY-MM-DD HH24:MI}  -value [calendar::from_sq..."
    ("uplevel" body line 48)
    invoked from within
"uplevel {
          # packages/meetings/www/add-edit.tcl

Collapse
Posted by Jon Griffin on
See:
http://jongriffin.com/static/openacs/ad_form/using-ad-form
Collapse
3: ad_form (response to 2)
Posted by Eduardo Pérez on
I've seen that ad_form is not used in many places in OpenACS.
Are there any efforts to port current code to ad_form?
Should new code for OpenACS always use ad_form?
Collapse
Posted by Eduardo Pérez on
I've converted to ad_form and it's now working.

I used:
{meetingdate:date,to_sql(linear_date),from_sql(sql_date)
  {label "Date"}
  {format "YYYY-MM-DD HH24:MI"}
  {today}
  {help}
  {value {$meetingdate}}}

copied from the happenings example. Where are the fields documented?

I had to use:
to_timestamp(:meetingdate,'YYYY MM DD HH24 MI SS')
and:
to_char(meetingdate, 'YYYY MM DD HH24 MI SS') as meetingdate

to convert to sql and from sql the date format.

Is this correct?

Collapse
Posted by Don Baccus on
It's documented in the piece Jon wrote and referenced above, and it's documented in the code - you can use the API browser to read that piece of documentation.