template::data::validate::h5time (public)

 template::data::validate::h5time value_ref message_ref

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

Validate that a date submitted via HTML 5 input type "time". The sbumitted value is also checked against any set "min" and "max" constraint set on the input element itself.

Parameters:
value_ref (required)
Reference variable to the submitted value.
message_ref (required)
Reference variable for returning an error message.
Returns:
True (1) if valid, false (0) if not.

Partial Call Graph (max 5 caller/called nodes):
%3 _ _ (public) template::data::validate::h5time template::data::validate::h5time template::data::validate::h5time->_

Testcases:
No testcase defined.
Source code:
    upvar 2 $message_ref message $value_ref value

    # get the elements definition
    upvar 2 element element

    # A HTML time field will always return a value in 24-hour format
    # including leading zeros (hh:mm), regardless of the input
    # format. If the step attribute is used time always includes
    # seconds (hh:mm:ss). However, on the server side, we must be able
    # to accept and process both formats, so we must check for both.
    set clock_formats {
        "%H:%M"
        "%H:%M:%S"
    }

    if {$value ne ""} {
        foreach clock_format $clock_formats {
            set invalid_time_p [catch {
                set supplied_time [clock scan $value -format $clock_format]
            }]
            if {!$invalid_time_p} {
                break
            }
        }

        if {$invalid_time_p} {
            lappend message [_ acs-templating.Invalid_time]
            return 0
        }

        if {[info exists element(min)]} {
            foreach clock_format $clock_formats {
                set invalid_time_p [catch {
                    set min [clock scan $element(min) -format $clock_format]
                }]
                if {!$invalid_time_p} {
                    break
                }
            }
            if {$invalid_time_p || $min > $supplied_time} {
                lappend message [_ acs-templating.Time_must_be_after_min_time  [list min_time $element(min)]]
                return 0
            }
        }

        if {[info exists element(max)]} {
            foreach clock_format $clock_formats {
                set invalid_time_p [catch {
                    set max [clock scan $element(max) -format $clock_format]
                }]
                if {!$invalid_time_p} {
                    break
                }
            }
            if {$invalid_time_p || $supplied_time > $max} {
                lappend message [_ acs-templating.Time_must_be_before_max_time  [list max_time $element(max)]]
                return 0
            }
        }
    }

    return 1
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: