template::util::date::set_property (public)

 template::util::date::set_property what date value

Defined in packages/acs-templating/tcl/date-procs.tcl

Replace a property in a list created by a date widget.

Parameters:
what - name of the property (see source for allowed values)
date - the date list
value - the new value
Returns:
the modified list

Partial Call Graph (max 5 caller/called nodes):
%3 test_template_date_api template_date_api (test acs-templating) template::util::date::set_property template::util::date::set_property test_template_date_api->template::util::date::set_property template::util::date template::util::date (public) template::util::date::set_property->template::util::date template::util::date::now template::util::date::now (public) template::util::date::set_property->template::util::date::now util::trim_leading_zeros util::trim_leading_zeros (public) template::util::date::set_property->util::trim_leading_zeros calendar::from_sql_datetime calendar::from_sql_datetime (public, deprecated) calendar::from_sql_datetime->template::util::date::set_property template::data::transform::date template::data::transform::date (public) template::data::transform::date->template::util::date::set_property template::util::date::acquire template::util::date::acquire (public) template::util::date::acquire->template::util::date::set_property template::util::date::add_time template::util::date::add_time (public) template::util::date::add_time->template::util::date::set_property template::util::date::from_ansi template::util::date::from_ansi (public) template::util::date::from_ansi->template::util::date::set_property

Testcases:
template_date_api
Source code:

    # if value is an empty string, just return the date that was
    # passed in, otherwise this procedure will fail.
    # This is needed for the automated sql/linear conversion used by
    # ad_form.

    if {$value eq ""} {
        return $date
    }

    # This trimming is actually more of a noop, as one should actually
    # switch on the 'what' variable, expected to match one of the
    # keys, while 'value' will just be a date. The probable typo is 18
    # years old, so I am commenting out the code, rather than "fixing
    # it", with possible unexpected consequences. Might go away for
    # good at some point.
    # # Erase leading zeros from the value, but make sure that 00
    # # is not completely erased - but only for single-element properties
    #
    # switch -- $value {
    #     year - month - day - hour - minutes - seconds - short_year - short_hours - ampm {
    #         set value [util::trim_leading_zeros $value]
    #     }
    # }

    switch -- $what {
        year       { return [lreplace $date 0 0 $value] }
        month      { return [lreplace $date 1 1 $value] }
        day        { return [lreplace $date 2 2 $value] }
        hours      { return [lreplace $date 3 3 $value] }
        minutes    { return [lreplace $date 4 4 $value] }
        seconds    { return [lreplace $date 5 5 $value] }
        format     { return [lreplace $date 6 6 $value] }
        short_year {
            if { $value < 69 } {
                return [lreplace $date 0 0 [expr {$value + 2000}]]
            } else {
                return [lreplace $date 0 0 [expr {$value + 1900}]]
            }
        }
        short_hours {
            return [lreplace $date 3 3 $value]
        }
        ampm {
            if {[lindex $date 3] eq ""} {
                return $date
            } else {
                set hours [lindex $date 3]

                # robustness check: make sure we handle form of 08:00am  --jfr
                if {[regexp {0([0-9])} $hours match trimmed_hours]} {
                    if {$trimmed_hours ne ""} {
                        set hours $trimmed_hours
                    }
                }

                if { $value eq "pm" && $hours < 12 } {
                    return [lreplace $date 3 3 [expr {$hours + 12}]]
                } elseif {$value eq "am"} {
                    return [lreplace $date 3 3 [expr {$hours % 12}]]
                } else {
                    return $date
                }
            }
        }
        clock {
            set old_date [clock format $value -format "%Y %m %d %H %M %S"]
            set new_date [list]
            foreach field $old_date {
                lappend new_date [util::trim_leading_zeros $field]
            }
            lappend new_date [lindex $date 6]
            return $new_date
        }
        sql_date {
            set old_format [lindex $date 6]
            set new_date [list]
            foreach fragment $value {
                lappend new_date [util::trim_leading_zeros $fragment]
            }
            lappend new_date $old_format
            return $new_date
        }
        ansi {
            # Some initialization...
            # Rip $date into $ansi_* as numbers, no leading zeros
            set matchdate {([0-9]{4})\-0?(1?[0-9])\-0?([1-3]?[0-9])}
            set matchtime {0?([1-2]?[0-9]):0?([1-5]?[0-9]):0?([1-6]?[0-9])}
            set matchfull "$matchdate $matchtime"

            set time_p 1
            if {![regexp -- $matchfull $value match ansi_year ansi_month ansi_days ansi_hours ansi_minutes ansi_seconds]} {
                if {[regexp -- $matchdate $value match ansi_year ansi_month ansi_days]} {
                    set ansi_hours 0
                    set ansi_minutes 0
                    set ansi_seconds 0
                } else {
                    error "Invalid date: $value"
                }
            }
            # Return new date, but use old format
            return [list $ansi_year $ansi_month $ansi_days $ansi_hours $ansi_minutes $ansi_seconds [lindex $date 6]]
        }
        now {
            return [template::util::date set_property clock $date [clock seconds]]
        }
        default {
            error "util::date::set_property: unknown property: '$what'."
        }
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: