Index: openacs-4/packages/acs-templating/tcl/date-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/date-procs.tcl,v diff -u -r1.62 -r1.63 --- openacs-4/packages/acs-templating/tcl/date-procs.tcl 8 Nov 2018 16:37:58 -0000 1.62 +++ openacs-4/packages/acs-templating/tcl/date-procs.tcl 9 Nov 2018 13:36:08 -0000 1.63 @@ -43,18 +43,18 @@ variable fragment_formats variable token_exp - array set month_data { - 1 {January Jan 31} - 2 {February Feb 28} - 3 {March Mar 31} - 4 {April Apr 30} - 5 {May May 31} - 6 {June Jun 30} - 7 {July Jul 31} - 8 {August Aug 31} - 9 {September Sep 30} - 10 {October Oct 31} - 11 {November Nov 30} + array set month_data { + 1 {January Jan 31} + 2 {February Feb 28} + 3 {March Mar 31} + 4 {April Apr 30} + 5 {May May 31} + 6 {June Jun 30} + 7 {July Jul 31} + 8 {August Aug 31} + 9 {September Sep 30} + 10 {October Oct 31} + 11 {November Nov 30} 12 {December Dec 31} } @@ -78,7 +78,7 @@ # Reverse lookup foreach key [array names fragment_widgets] { set fragment_formats([lindex $fragment_widgets($key) 1]) $key - } + } # Expression to match any valid format token set token_exp "([join [array names fragment_widgets] |])(t*)" @@ -108,7 +108,7 @@ variable month_data set month_desc $month_data($month) set days [lindex $month_desc 2] - + if { $month == 2 && ( (($year % 4) == 0 && ($year % 100) != 0) || (($year % 400) == 0) ) @@ -120,11 +120,11 @@ } ad_proc -public template::util::date::create { - {year {}} {month {}} {day {}} {hours {}} + {year {}} {month {}} {day {}} {hours {}} {minutes {}} {seconds {}} {format "DD MONTH YYYY"} } { Create a new Date object - I chose to implement the date objects as lists instead of + I chose to implement the date objects as lists instead of arrays, because arrays are not first-class in Tcl } { return [list $year $month $day $hours $minutes $seconds $format] @@ -254,7 +254,7 @@ short_hours { if {[lindex $date 3] eq ""} { return {} - } else { + } else { set value [expr {[lindex $date 3] % 12}] if { $value == 0 } { return 12 @@ -266,7 +266,7 @@ ampm { if {[lindex $date 3] eq ""} { return {} - } else { + } else { if { [lindex $date 3] > 11 } { return "pm" } else { @@ -278,7 +278,7 @@ for { set i 0 } { $i < 6 } { incr i } { if { [lindex $date $i] ne {} } { return 1 - } + } } return 0 } @@ -302,14 +302,14 @@ } 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. + # 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 { + } else { return "to_timestamp('$value', '$format')" } } @@ -437,7 +437,7 @@ if {$value eq ""} { return $date } - + # Erase leading zeroes from the value, but make sure that 00 # is not completely erased - but only for single-element properties @@ -459,7 +459,7 @@ if { $value < 69 } { return [lreplace $date 0 0 [expr {$value + 2000}]] } else { - return [lreplace $date 0 0 [expr {$value + 1900}]] + return [lreplace $date 0 0 [expr {$value + 1900}]] } } short_hours { @@ -468,7 +468,7 @@ ampm { if {[lindex $date 3] eq ""} { return $date - } else { + } else { set hours [lindex $date 3] # robustness check: make sure we handle form of 08:00am --jfr @@ -511,7 +511,7 @@ 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]} { @@ -551,18 +551,18 @@ } ad_proc -public template::util::date::unpack { date } { - Set the variables for each field of the date object in + Set the variables for each field of the date object in the calling frame. - sets: year month day hours minutes seconds format from a list formatted date string + sets: year month day hours minutes seconds format from a list formatted date string @see template::util::date::from_ans } { uplevel [list foreach {year month day hours minutes seconds format} $date { break }] } ad_proc -public template::util::date::now_min_interval {} { - Create a new Date object for the current date and time + Create a new Date object for the current date and time with the default interval for minutes @author Walter McGinnis (wtem@olywa.net) @@ -572,7 +572,7 @@ foreach v [clock format [clock seconds] -format "%Y %m %d %H %M %S"] { lappend now [util::trim_leading_zeros $v] } - + # manipulate the minute value so it rounds up to nearest minute interval set minute [lindex $now 4] # there is a definition for minute interval: 0 59 5 @@ -596,7 +596,7 @@ } ad_proc -public template::util::date::now_min_interval_plus_hour {} { - Create a new Date object for the current date and time + Create a new Date object for the current date and time plus one hour with the default interval for minutes @@ -607,7 +607,7 @@ foreach v [clock format [clock seconds] -format "%Y %m %d %H %M %S"] { lappend now [util::trim_leading_zeros $v] } - + # manipulate the minute value so it rounds up to nearest minute interval set minute [lindex $now 4] # there is a definition for minute interval: 0 59 5 @@ -632,10 +632,10 @@ } ad_proc -public template::util::date::add_time { {-time_array_name:required} {-date_array_name:required} } { - set the time and date and new format properties + set the time and date and new format properties into one date object (list) which is returned not sure this proc should live here... - + @author Walter McGinnis (wtem@olywa.net) @creation-date 2002-01-04 } { @@ -649,7 +649,7 @@ # create an empty date object with the new format set the_date [template::util::date::create \ "" "" "" "" "" "" ""] - + set the_date [template::util::date::set_property format $the_date $new_format] set have_values 0 @@ -697,7 +697,7 @@ return [list $the_date] } else { return {} - } + } } ad_proc -public template::util::negative { value } { @@ -729,7 +729,7 @@ set error_msg [list] - foreach {field exp} { year "YYYY|YY" month "MM|MON|MONTH" day "DD" + foreach {field exp} { year "YYYY|YY" month "MM|MON|MONTH" day "DD" hours "HH24|HH12" minutes "MI" seconds "SS" } { # If the field is required, but missing, report an error @@ -756,7 +756,7 @@ if { [string trimleft $month "0"] < 1 || [string trimleft $month "0"] > 12 } { lappend error_msg [_ acs-templating.Month_must_be_between_1_and_12] } else { - if { $year > 0 } { + if { $year > 0 } { if { $day ne {} } { set maxdays [get_property days_in_month $date] if { [string trimleft $day "0"] < 1 || [string trimleft $day "0"] > $maxdays } { @@ -774,15 +774,15 @@ if { [template::util::negative $hours] || $hours > 23 } { lappend error_msg [_ acs-templating.Hours_must_be_between_0_and_23] - } + } if { [template::util::negative $minutes] || $minutes > 59 } { lappend error_msg [_ acs-templating.Minutes_must_be_between_0_and_59] - } + } if { [template::util::negative $seconds] || $seconds > 59 } { lappend error_msg [_ acs-templating.Seconds_must_be_between_0_and_59] - } + } if { [llength $error_msg] > 0 } { set error_msg "[join $error_msg {
}]" return 0 @@ -824,9 +824,9 @@ # interval_def is in form { start stop interval } ad_proc -public template::widget::numericrange {element_reference tag_attributes} { - Widget proc usable with ad_form, need to define interval_def as + Widget proc usable with ad_form, need to define interval_def as {interval_def {start end step}} -} { +} { upvar $element_reference element if { [info exists element(html)] } { @@ -841,7 +841,7 @@ interval_def is in form { start stop interval } } { array set attributes $tag_attributes - + set interval_size [lindex $interval_def 2] set options [list [list "--" {}]] @@ -871,7 +871,7 @@ } { upvar $element_reference element - + set value [template::util::date::get_property $fragment $value] set value [util::trim_leading_zeros $value] @@ -882,8 +882,8 @@ set interval $element(${fragment}_interval) } else { # Display text entry for some elements, or if the type is text - if { $type == "t" - || [regexp "year|short_year" $fragment] + if { $type == "t" + || [regexp "year|short_year" $fragment] } { set output "SSseconds AMam/pm flag - Any format field may be followed by "t", in which case a text + Any format field may be followed by "t", in which case a text widget will be used to represent the field. the array in range_ref determines interval ranges; the keys are the date fields and the values are in form {start stop interval} @@ -995,7 +995,7 @@ set output "\n" - if { ! [info exists element(format)] } { + if { ! [info exists element(format)] } { set element(format) [_ acs-lang.localization-formbuilder_date_format] } @@ -1011,7 +1011,7 @@ set current_year [expr {$current_year % 100}] set element(short_year_interval) \ [list $current_year [expr {$current_year + 10}] 1] - set element(help) 1 + set element(help) 1 } } @@ -1021,8 +1021,8 @@ append output "value=\"$element(format)\" >\n" # Prepare the value to set defaults on the form - if { [info exists element(value)] - && [template::util::date::get_property not_null $element(value)] + if { [info exists element(value)] + && [template::util::date::get_property not_null $element(value)] } { set value $element(value) foreach v $value { @@ -1087,7 +1087,7 @@ } append output "\n" - + return $output } @@ -1103,11 +1103,11 @@ {} {} {} {} {} {} [ns_queryget "$element_id.format"]] set have_values 0 - foreach field { - year short_year month day + foreach field { + year short_year month day short_hours hours minutes seconds ampm } { - set key "$element_id.$field" + set key "$element_id.$field" if { [ns_queryexists $key] } { set value [ns_queryget $key] # Coerce values to non-negative integers @@ -1148,14 +1148,14 @@ # format isn't matched we will use the iso standard YYYY-MM-DD. # # %d-%m-%y %d.%m.%y %d/%m-%y %d/%m/%y %m/%d/%y %y-%m-%d %y.%m.%d "%d-%m-%y" - + set format [lc_get "d_fmt"] regsub -all -nocase {\"} $format {} format regsub -all -nocase {\%} $format {} format set format [string tolower $format] # this format key must now be at max five characters, and contain one y, one m and one d # as well as two punction marks ( - . / ) - if { [regexp {^([y|m|d])([\-|\.|/])([y|m|d])([\-|\.|/])([y|m|d])} $format match first first_punct second second_punct third] + if { [regexp {^([y|m|d])([\-|\.|/])([y|m|d])([\-|\.|/])([y|m|d])} $format match first first_punct second second_punct third] && [string length $format] == 5 } { if { [lsort [list $first $second $third]] eq "d m y" } { @@ -1271,7 +1271,7 @@ set date_valid_p [string is false [catch { clock scan "${textdate}" }]] # we have a correctly formatted iso date that we # can reformat for display, we don't use lc_time_fmt - # because it could fail and cause a server error. + # because it could fail and cause a server error. # The date may be formatted correctly but it may be # an invalid date (which is caught by # template::data::validate::textdate) so we need to @@ -1296,7 +1296,7 @@ set id $element(id)_input_field append output [subst { - + }] template::add_event_listener \ @@ -1307,7 +1307,7 @@ } else { append output $textdate [subst {}] } - + return $output } @@ -1371,7 +1371,7 @@ upvar $element_reference element - if { ! [info exists element(format)] } { + if { ! [info exists element(format)] } { set element(format) "[_ acs-lang.localization-formbuilder_date_format] [_ acs-lang.localization-formbuilder_time_format]" } return [template::widget::date element $tag_attributes] @@ -1424,7 +1424,7 @@ upvar $element_reference element - if { ! [info exists element(format)] } { + if { ! [info exists element(format)] } { set element(format) "[_ acs-lang.localization-formbuilder_date_format] [_ acs-lang.localization-formbuilder_time_format]" } return [template::widget::date element $tag_attributes]