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.49 -r1.50
--- openacs-4/packages/acs-templating/tcl/date-procs.tcl 27 Oct 2014 16:40:11 -0000 1.49
+++ openacs-4/packages/acs-templating/tcl/date-procs.tcl 7 Aug 2017 23:48:01 -0000 1.50
@@ -1,14 +1,17 @@
-# Date widgets for the ArsDigita Templating System
+ad_library {
+ Date widgets for the ArsDigita Templating System
+ @author Stanislav Freidin (sfreidin@arsdigita.com)
+ @cvs-id $Id$
+}
+
# Copyright (C) 1999-2000 ArsDigita Corporation
-# Author: Stanislav Freidin (sfreidin@arsdigita.com)
-#
-# $Id$
# This is free software distributed under the terms of the GNU Public
# License. Full text of the license is available from the GNU Project:
# http://www.fsf.org/copyleft/gpl.html
+
# Prepare an array to map symbolic month names to their indices
namespace eval template {}
@@ -85,7 +88,7 @@
Return the specified month name (short or long)
} {
# trim leading zeros to avoid octal problem
- set month [template::util::leadingTrim $month]
+ set month [util::trim_leading_zeros $month]
if {$length eq "long"} {
return [lc_time_fmt "2002-[format "%02d" $month]-01" "%B"]
} else {
@@ -98,20 +101,23 @@
@return the number of days in a month, accounting for leap years
LOOKATME: IS THE LEAP YEAR CODE CORRECT ?
} {
- set month [string trimleft $month 0]
- variable month_data
- set month_desc $month_data($month)
- set days [lindex $month_desc 2]
+ set month [string trimleft $month 0]
+ set year [string trimleft $year 0]
+ if {$year eq ""} {set year 0}
+
+ 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
- ) } {
- return [expr {$days + 1}]
- } else {
- return $days
- }
-}
+ if { $month == 2
+ && ( (($year % 4) == 0 && ($year % 100) != 0) ||
+ (($year % 400) == 0) )
+ } {
+ return [expr {$days + 1}]
+ } else {
+ return $days
+ }
+}
ad_proc -public template::util::date::create {
{year {}} {month {}} {day {}} {hours {}}
@@ -141,7 +147,7 @@
foreach v $now {
# trim leading zeros to avoid octal problem
- lappend today [template::util::leadingTrim $v]
+ lappend today [util::trim_leading_zeros $v]
}
return [create {*}$today]
@@ -154,7 +160,7 @@
set today [list]
foreach v $now {
- lappend today [template::util::leadingTrim $v]
+ lappend today [util::trim_leading_zeros $v]
}
return [create {*}$today]
@@ -299,7 +305,7 @@
# 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
+ # 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')"
@@ -437,7 +443,7 @@
switch $value {
year - month - day - hour - minutes - seconds - short_year - short_hours - ampm {
- set value [template::util::leadingTrim $value]
+ set value [util::trim_leading_zeros $value]
}
}
@@ -484,7 +490,7 @@
set old_date [clock format $value -format "%Y %m %d %H %M %S"]
set new_date [list]
foreach field $old_date {
- lappend new_date [template::util::leadingTrim $field]
+ lappend new_date [util::trim_leading_zeros $field]
}
lappend new_date [lindex $date 6]
return $new_date
@@ -493,7 +499,7 @@
set old_format [lindex $date 6]
set new_date [list]
foreach fragment $value {
- lappend new_date [template::util::leadingTrim $fragment]
+ lappend new_date [util::trim_leading_zeros $fragment]
}
lappend new_date $old_format
return $new_date
@@ -563,7 +569,7 @@
} {
set now [list]
foreach v [clock format [clock seconds] -format "%Y %m %d %H %M %S"] {
- lappend now [template::util::leadingTrim $v]
+ lappend now [util::trim_leading_zeros $v]
}
# manipulate the minute value so it rounds up to nearest minute interval
@@ -597,7 +603,7 @@
} {
set now [list]
foreach v [clock format [clock seconds] -format "%Y %m %d %H %M %S"] {
- lappend now [template::util::leadingTrim $v]
+ lappend now [util::trim_leading_zeros $v]
}
# manipulate the minute value so it rounds up to nearest minute interval
@@ -699,7 +705,7 @@
if {$value eq ""} {
return 0
} else {
- return [expr {[template::util::leadingTrim $value] < 0}]
+ return [expr {[util::trim_leading_zeros $value] < 0}]
}
}
@@ -799,16 +805,11 @@
}
-ad_proc -public template::util::leadingTrim { value } {
+ad_proc -public -deprecated template::util::leadingTrim { value } {
Trim the leading zeroes from the value, but preserve the value
as "0" if it is "00"
} {
- set empty [string equal $value ""]
- set value [string trimleft $value 0]
- if { !$empty && $value eq "" } {
- set value 0
- }
- return $value
+ return [util::trim_leading_zeros $value]
}
# Create an html fragment to display a numeric range widget
@@ -864,7 +865,7 @@
upvar $element_reference element
set value [template::util::date::get_property $fragment $value]
- set value [template::util::leadingTrim $value]
+ set value [util::trim_leading_zeros $value]
if { $mode ne "edit" } {
set output {}
@@ -1020,7 +1021,7 @@
} {
set value $element(value)
foreach v $value {
- lappend trim_value [template::util::leadingTrim $v]
+ lappend trim_value [util::trim_leading_zeros $v]
}
set value $trim_value
} else {
@@ -1287,11 +1288,19 @@
}
if {$element(mode) eq "edit"} {
- append output ""
- append output ""
+ set id $element(id)_input_field
+ append output [subst {
+
+
+ }]
+
+ template::add_event_listener \
+ -id $id-control \
+ -script [subst {
+ showCalendarWithDefault('$element(id)_input_field', '$javascriptdate', '[template::util::textdate_localized_format]');
+ }]
} else {
- append output $textdate
- append output ""
+ append output $textdate [subst {}]
}
return $output
@@ -1416,3 +1425,9 @@
return [template::widget::date element $tag_attributes]
}
+
+# Local variables:
+# mode: tcl
+# tcl-indent-level: 4
+# indent-tabs-mode: nil
+# End: