template::util::date::get_property (public)

 template::util::date::get_property what date

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

Returns a property of a date list, usually created by ad_form.

Parameters:
what (required)
the name of the property. One of:
  • year
  • month
  • day
  • hours
  • minutes
  • seconds
  • format
  • long_month_name
  • short_month_name
  • days_in_month
  • short_year
  • short_hours
  • ampm
  • not_null
  • sql_date
  • linear_date
  • linear_date_no_time
  • display_date
  • clock
date (required)
the date widget list

Partial Call Graph (max 5 caller/called nodes):
%3 test_sql_date sql_date (test acs-templating) template::util::date::get_property template::util::date::get_property test_sql_date->template::util::date::get_property test_template_date_api template_date_api (test acs-templating) test_template_date_api->template::util::date::get_property db_type db_type (public) template::util::date::get_property->db_type db_version db_version (public) template::util::date::get_property->db_version lc_time_fmt lc_time_fmt (public) template::util::date::get_property->lc_time_fmt template::util::date::daysInMonth template::util::date::daysInMonth (public) template::util::date::get_property->template::util::date::daysInMonth template::util::date::monthName template::util::date::monthName (public) template::util::date::get_property->template::util::date::monthName calendar::to_sql_datetime calendar::to_sql_datetime (public, deprecated) calendar::to_sql_datetime->template::util::date::get_property packages/edit-this-page/www/etp-edit.tcl packages/edit-this-page/ www/etp-edit.tcl packages/edit-this-page/www/etp-edit.tcl->template::util::date::get_property template::data::to_sql::date template::data::to_sql::date (public) template::data::to_sql::date->template::util::date::get_property template::data::validate::textdate template::data::validate::textdate (public) template::data::validate::textdate->template::util::date::get_property template::util::date::validate template::util::date::validate (public) template::util::date::validate->template::util::date::get_property

Testcases:
sql_date, template_date_api
Source code:
    variable month_data

    switch -- $what {
        year       { return [lindex $date 0] }
        month      { return [lindex $date 1] }
        day        { return [lindex $date 2] }
        hours      { return [lindex $date 3] }
        minutes    { return [lindex $date 4] }
        seconds    { return [lindex $date 5] }
        format     { return [lindex $date 6] }
        long_month_name {
            if {[lindex $date 1] eq ""} {
                return {}
            } else {
                return [monthName [lindex $date 1] long]
            }
        }
        short_month_name {
            if {[lindex $date 1] eq ""} {
                return {}
            } else {
                return [monthName [lindex $date 1] short]
            }
        }
        days_in_month {
            if { [lindex $date 1] eq "" || [lindex $date 0] eq "" } {
                return 31
            } else {
                return [daysInMonth [lindex $date 1] [lindex $date 0]]
            }
        }
        short_year {
            if {[lindex $date 0] eq ""} {
                return {}
            } else {
                return [expr {[lindex $date 0] % 100}]
            }
        }
        short_hours {
            if {[lindex $date 3] eq ""} {
                return {}
            } else {
                set value [expr {[lindex $date 3] % 12}]
                if { $value == 0 } {
                    return 12
                } else {
                    return $value
                }
            }
        }
        ampm {
            if {[lindex $date 3] eq ""} {
                return {}
            } else {
                if { [lindex $date 3] > 11 } {
                    return "pm"
                } else {
                    return "am"
                }
            }
        }
        not_null {
            for { set i 0 } { $i < 6 } { incr i } {
                if { [lindex $date $i] ne {} } {
                    return 1
                }
            }
            return 0
        }
        sql_date -
        sql_timestamp {
            # LARS: Empty date results in NULL value
            if { $date eq "" } {
                return "NULL"
            }
            set value ""
            set format ""
            set space ""
            set pad "0000"
            foreach { index sql_form } { 0 YYYY 1 MM 2 DD 3 HH24 4 MI 5 SS } {
                set piece [lindex $date $index]
                if { $piece ne {} } {
                    append value "$space[string range $pad [string length $piece] end]$piece"
                    append format $space
                    append format $sql_form
                    set space " "
                }
                set pad "00"
            }
            # DRB: We need to differentiate between date and timestamp, for PG, at least,
            # and since Oracle supports to_timestamp() we'll just do it for both DBs.
            # DEDS: revert this first as to_timestamp is only for
            # oracle9i. no clear announcement that OpenACS has dropped
            # support for 8i
            if { [llength $date] <= 3 || ([db_type] eq "oracle" && [string match "8.*" [db_version]]) } {
                return "to_date('$value', '$format')"
            } else {
                return "to_timestamp('$value', '$format')"
            }
        }
        ansi {
            # LARS: Empty date results in NULL value
            if { $date eq "" } {
                return {}
            }
            set value ""
            set pad "0000"
            set prepend ""
            set clipped_date [lrange $date 0 2]
            foreach fragment $clipped_date {
                append value "$prepend[string range $pad [string length $fragment] end]$fragment"
                set pad "00"
                set prepend "-"
            }
            append value " "
            set prepend ""
            set clipped_time [lrange $date 3 5]
            foreach fragment $clipped_time {
                append value "$prepend[string range $pad [string length $fragment] end]$fragment"
                set prepend ":"
            }
            return $value
        }
        linear_date {
            # Return a date in format "YYYY MM DD HH24 MI SS"
            # For use with karl's non-working form builder API
            set clipped_date [lrange $date 0 5]
            set ret [list]
            set pad "0000"
            foreach fragment $clipped_date {
                lappend ret "[string range $pad [string length $fragment] end]$fragment"
                set pad "00"
            }
            return $ret
        }
        linear_date_no_time {
            # Return a date in format "YYYY MM DD"
            set clipped_date [lrange $date 0 2]
            set ret [list]
            set pad "0000"
            foreach fragment $clipped_date {
                lappend ret "[string range $pad [string length $fragment] end]$fragment"
                set pad "00"
            }
            return $ret
        }
        display_date {

            # Return a beautified date.  It should use the widget format string but DRB
            # doesn't have the time to dive into that today.  The simple hack would be
            # to use the database's to_char() function to do the conversion but that's
            # not a terribly efficient thing to do.

            set clipped_date [lrange $date 0 2]
            set date_list [list]
            set pad "0000"
            foreach fragment $clipped_date {
                lappend date_list "[string range $pad [string length $fragment] end]$fragment"
                set pad "00"
            }
            set value [lc_time_fmt [join $date_list "-""%q"]
            unpack $date
            if { $hours ne "" && $minutes ne "" } {
                append value " [string range $pad [string length $hours] end]${hours}:[string range $pad [string length $minutes] end]$minutes"
                if { $seconds ne {} } {
                    append value ":[string range $pad [string length $seconds] end]$seconds"
                }
            }
            return $value
        }
        clock {
            set value ""
            # Unreliable !
            unpack $date
            if { $year ne "" && $month ne "" && $day ne "" } {
                append value "$month/$day/$year"
            }
            if { $hours ne "" && $minutes ne "" } {
                append value ${hours}:${minutes}"
                if { $seconds ne "" } {
                    append value ":$seconds"
                }
            }
            return [clock scan $value]
        }
        default {
            error "util::date::get_property: unknown property: '$what'."
        }
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: