Index: openacs-4/packages/acs-datetime/tcl/acs-datetime-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-datetime/tcl/acs-datetime-procs.tcl,v diff -u -r1.12 -r1.13 --- openacs-4/packages/acs-datetime/tcl/acs-datetime-procs.tcl 1 Mar 2005 00:01:22 -0000 1.12 +++ openacs-4/packages/acs-datetime/tcl/acs-datetime-procs.tcl 27 Oct 2014 16:39:32 -0000 1.13 @@ -10,7 +10,8 @@ } ad_proc -public dt_systime { - {-format "%Y-%m-%d %H:%M:%S" -gmt f} + {-format "%Y-%m-%d %H:%M:%S"} + {-gmt f} } { Returns current server time in the standard format "yyyy-mm-dd hh:mi:ss". With the optional -gmt flag it returns the time in @@ -32,15 +33,16 @@ } { Returns 1 if "time" is a valid time specification, 0 otherwise. } { - if [catch { clock scan $time }] { + if {[catch { clock scan $time }]} { return 0 } else { return 1 } } ad_proc -deprecated dt_format { - {-format "%Y-%m-%d %H:%M:%S" -gmt f} + {-format "%Y-%m-%d %H:%M:%S"} + {-gmt f} time } { This proc should not be used, because it does not take internationalization into account. Use lc_time_fmt instead. @@ -89,7 +91,7 @@ of an invalid ANSI date argument (year less than 4713 BCE, greater than 9999 CE, or equal to 0) } { - if [empty_string_p $era] { + if {$era eq ""} { set era CE } @@ -101,28 +103,28 @@ # 1582-10-04; 1582-10-15) set julian_date [dt_ansi_to_julian 1582 10 15 CE] } else { - if {$era == "BCE"} { - set year [expr -$year + 1] + if {$era eq "BCE"} { + set year [expr {-$year + 1}] } if {$month > 2} { set year_n $year - set month_n [expr $month + 1] + set month_n [expr {$month + 1}] } else { - set year_n [expr $year - 1] - set month_n [expr $month + 13] + set year_n [expr {$year - 1}] + set month_n [expr {$month + 13}] } - set julian_date [expr floor(floor(365.25 * $year_n) + floor(30.6001 * $month_n) + ($day + 1720995))] + set julian_date [expr {floor(floor(365.25 * $year_n) + floor(30.6001 * $month_n) + ($day + 1720995))}] # check for change to the Gregorian Calendar - set gregorian [expr 15 + 31 * (10 + 12 * 1582)] + set gregorian [expr {15 + 31 * (10 + 12 * 1582)}] if {$day + 31 * ($month + 12 * $year) >= $gregorian} { - set julian_date [expr $julian_date + (2 - floor(0.01 * $year_n) + floor(0.25 * floor(0.01 * $year_n)))] + set julian_date [expr {$julian_date + (2 - floor(0.01 * $year_n) + floor(0.25 * floor(0.01 * $year_n)))}] } } - return [expr int($julian_date)] + return [expr {int($julian_date)}] } ad_proc -public dt_julian_to_ansi { @@ -134,32 +136,32 @@ set gregorian 2299161 if {$julian_date >= $gregorian} { - set calc [expr floor((($julian_date - 1867216) - 0.25) / 36524.25)] - set calc [expr $julian_date + 1 + $calc - floor(0.25 * $calc)] + set calc [expr {floor((($julian_date - 1867216) - 0.25) / 36524.25)}] + set calc [expr {$julian_date + 1 + $calc - floor(0.25 * $calc)}] } else { set calc $julian_date } # get initial calculations to set year, month, day - set calc [expr $calc + 1524] - set calc2 [expr floor(6680 + (($calc - 2439870) - 122.1) / 365.25)] - set calc3 [expr floor($calc2 * 365.25)] - set calc4 [expr floor(($calc - $calc3) / 30.6001)] + set calc [expr {$calc + 1524}] + set calc2 [expr {floor(6680 + (($calc - 2439870) - 122.1) / 365.25)}] + set calc3 [expr {floor($calc2 * 365.25)}] + set calc4 [expr {floor(($calc - $calc3) / 30.6001)}] # set year, month, day - set year [expr floor($calc2 - 4715)] - set month [expr floor($calc4 - 1)] + set year [expr {floor($calc2 - 4715)}] + set month [expr {floor($calc4 - 1)}] if {$month > 12} { - set month [expr $month - 12] + set month [expr {$month - 12}] } if {$month > 2 || $year <= 0} { - set year [expr $year - 1] + set year [expr {$year - 1}] } - set day [expr floor($calc - $calc3 - floor($calc4 * 30.6001))] + set day [expr {floor($calc - $calc3 - floor($calc4 * 30.6001))}] - set year [expr int($year)] - set month [expr int($month)] - set day [expr int($day)] + set year [expr {int($year)}] + set month [expr {int($month)}] + set day [expr {int($day)}] if {$month < 10} { set month 0$month @@ -179,7 +181,7 @@ returns the current date based on server time. Works for both date and date-time strings. } { - if [empty_string_p $ansi_date] { + if {$ansi_date eq ""} { set ansi_date [dt_sysdate] } @@ -193,7 +195,7 @@ hour, minute, and second. Works for any date than can be parsed by clock scan. } { - if [empty_string_p $ansi_date] { + if {$ansi_date eq ""} { set ansi_date [dt_systime] } @@ -213,13 +215,13 @@ if {$month == 0} { set month 01 } elseif {$month == 12} { - set year [expr $year + 1] + set year [expr {$year + 1}] set month 01 } elseif {$month == 13} { - set year [expr $year + 1] + set year [expr {$year + 1}] set month 02 } else { - set month [expr $month + 1] + set month [expr {$month + 1}] } return [clock format [clock scan "last day" -base [clock scan $year-$month-01]] -format %d] @@ -232,7 +234,7 @@ Returns the weekday number of the first day for the given month/year } { # calendar widgets are expecting integers 1-7, so we must adjust - return [expr [clock format [clock scan $year-$month-01] -format %w] + 1] + return [expr {[clock format [clock scan $year-$month-01] -format %w] + 1}] } ad_proc -public dt_next_month { @@ -242,10 +244,10 @@ Returns the ANSI date for the next month } { if {$month == 12} { - set year [expr $year + 1] + set year [expr {$year + 1}] set month 01 } else { - set month [expr $month + 1] + set month [expr {$month + 1}] } # jarkko: added this check to avoid calendars bombing when prev month goes @@ -263,10 +265,10 @@ Returns the ANSI date for the previous month } { if {$month == 1} { - set year [expr $year - 1] + set year [expr {$year - 1}] set month 12 } else { - set month [expr $month - 1] + set month [expr {$month - 1}] } # jarkko: added this check to avoid calendars bombing when prev month goes @@ -285,10 +287,10 @@ Returns the ANSI date for the next month } { if {$month == 12} { - set year [expr $year + 1] + set year [expr {$year + 1}] set month 01 } else { - set month [expr $month + 1] + set month [expr {$month + 1}] } # jarkko: added this check to avoid calendars bombing when next month goes @@ -308,10 +310,10 @@ Returns the ANSI date for the previous month } { if {$month == 1} { - set year [expr $year - 1] + set year [expr {$year - 1}] set month 12 } else { - set month [expr $month - 1] + set month [expr {$month - 1}] } # jarkko: added this check to avoid calendars bombing when prev month goes @@ -325,8 +327,11 @@ } ad_proc -public dt_widget_datetime { - {-show_date 1 -date_time_sep " " -use_am_pm 0 -default none} - {name} + {-show_date 1} + {-date_time_sep " "} + {-use_am_pm 0} + {-default none} + name {granularity days} } { @@ -351,10 +356,10 @@ } { set to_precision [dt_precision $granularity] - set show_day [expr $to_precision < 1441] - set show_hours [expr $to_precision < 61] - set show_minutes [expr $to_precision < 60] - set show_seconds [expr $to_precision < 1] + set show_day [expr {$to_precision < 1441}] + set show_hours [expr {$to_precision < 61}] + set show_minutes [expr {$to_precision < 60}] + set show_seconds [expr {$to_precision < 1}] if {$to_precision == 0} { set to_precision 1 @@ -363,7 +368,7 @@ switch $default { none { set value [dt_systime] } now { set value [dt_systime] } - default { set value [dt_format $default] } + default { set value [lc_time_fmt $default "%Y-%m-%d %H:%M:%S"] } } set parsed_date [dt_ansi_to_list $value] @@ -378,10 +383,10 @@ # the other values too... if {$to_precision < 60} { - set minutes [expr [dt_round_to_precision $minutes $to_precision] % 60] + set minutes [expr {[dt_round_to_precision $minutes $to_precision] % 60}] } - if {$default == "none"} { + if {$default eq "none"} { set year "" set month "" set day "" @@ -449,16 +454,18 @@ ad_proc -public dt_widget_month_names { name - {default ""} + {selected_month 0} } { Returns a select widget for months of the year. } { + if {$selected_month eq ""} {set selected_month 0} + if {![string is integer $selected_month]} {error "selected_month must be integer"} set month_names [dt_month_names] - set default [expr $default-1] set input "