template::data::transform::textdate (public)
template::data::transform::textdate element_ref
Defined in packages/acs-templating/tcl/date-procs.tcl
Collect a textdate from the form, it automatically reformats it from the users locale to the ISO standard YYYY-MM-DD this is useful because it doesn't need reformatting in Tcl code.
- Parameters:
- element_ref (required)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
Source code: upvar $element_ref element set element_id $element(id) set value [ns_queryget "$element_id"] if { $value eq "" } { # they didn't enter anything return "" } # we get the format they need to use set format [template::util::textdate_localized_format] set exp $format regsub -all -- {(\-|\.|/)} $exp {(\1)} exp regsub -all -- {dd|mm} $exp {([0-9]{1,2})} exp regsub -all -- {yyyy} $exp {([0-9]{2,4})} exp # results is what comes out in a regexp set results $format regsub {\-|\.|/} $results { format_one} results regsub {\-|\.|/} $results { format_two} results regsub {mm} $results { month} results regsub {dd} $results { day} results regsub {yyyy} $results { year} results set results [string trim $results] if { [regexp {([\-|\.|/])yyyy$} $format match year_punctuation] } { # we might be willing to accept this date if it doesn't have a year # at the end, since we can assume that the year is the current one # this is useful for fast keyboard based date entry for formats that # have years at the end (such as in en_US which is mm/dd/yyyy or # de_DE which is dd.mm.yyyy) # we check if adding the year and punctuation makes it a valid date if { [regexp $exp "${value}${year_punctuation}[dt_sysdate -format %Y]" match {*}$results] } { if { ![catch { clock scan "${year}-${month}-${day}" }] } { # we add the missing year and punctuation to the value # we don't return it here because formatting is done # later on (i.e. adding leading zeros if needed) append value "${year_punctuation}[dt_sysdate -format %Y]" } } } # now we verify that we have a valid date # and adding leading/trailing zeros if needed if { [regexp $exp $value match {*}$results] } { # the regexp will have given us: year month day format_one format_two if { [string length $month] eq "1" } { set month "0$month" } if { [string length $day] eq "1" } { set day "0$day" } if { [string length $year] eq "2" } { # we'll copy microsoft excel's default assumptions # about the year it is so if the year is 29 or # lower its in this century otherwise its last century if { $year < 30 } { set year "20$year" } else { set year "19$year" } } return "${year}-${month}-${day}" } else { # they did not provide a correctly formatted date so we send it back to them return $value }XQL Not present: Generic, PostgreSQL, Oracle