Index: openacs-4/packages/acs-lang/tcl/localization-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/localization-procs.tcl,v diff -u -N -r1.26 -r1.27 --- openacs-4/packages/acs-lang/tcl/localization-procs.tcl 29 Dec 2017 11:13:40 -0000 1.26 +++ openacs-4/packages/acs-lang/tcl/localization-procs.tcl 29 Dec 2017 11:17:34 -0000 1.27 @@ -8,20 +8,20 @@ http://www.fsf.org/copyleft/gpl.html @creation-date 30 September 2000 - @author Jeff Davis (davis@xarg.net) + @author Jeff Davis (davis@xarg.net) @author Ashok Argent-Katwala (akatwala@arsdigita.com) @cvs-id $Id$ } -ad_proc -public lc_parse_number { - num - locale +ad_proc -public lc_parse_number { + num + locale {integer_only_p 0} } { - Converts a number to its canonical - representation by stripping everything but the - decimal separator and triming left 0's so it + Converts a number to its canonical + representation by stripping everything but the + decimal separator and triming left 0's so it won't be octal. It can process the following types of numbers:
- Takes a grouping specifier and - inserts the given separator into the string. - Given a separator of : + Takes a grouping specifier and + inserts the given separator into the string. + Given a separator of : and a number of 123456789 it returns:
grouping Formatted Value - {3 -1} 123456:789 - {3} 123:456:789 - {3 2 -1} 1234:56:789 - {3 2} 12:34:56:789 - {-1} 123456789 + {3 -1} 123456:789 + {3} 123:456:789 + {3 2 -1} 1234:56:789 + {3 2} 12:34:56:789 + {-1} 123456789@param num Number @@ -132,52 +132,52 @@ @param num_re Regular expression for valid numbers @return Number formatted with thousand separator } { - # with empty separator or grouping string we behave + # with empty separator or grouping string we behave # posixly - if {$grouping eq "" || $sep eq "" } { + if {$grouping eq "" || $sep eq "" } { return $num } - + # we need to sanitize the subspec regsub -all -- "(\[&\\\\\])" $sep "\\\\\\1" sep set match "^(-?$num_re+)(" set group [lindex $grouping 0] - - while { $group > 0} { + + while { $group > 0} { set re "$match[string repeat $num_re $group])" - if { ![regsub -- $re $num "\\1$sep\\2" num] } { - break - } - if {[llength $grouping] > 1} { + if { ![regsub -- $re $num "\\1$sep\\2" num] } { + break + } + if {[llength $grouping] > 1} { set grouping [lrange $grouping 1 end] } set group [lindex $grouping 0] - } - - return $num + } + + return $num } ad_proc -public lc_numeric { - num - {fmt {}} + num + {fmt {}} {locale ""} -} { +} { Given a number and a locale return a formatted version of the number for that locale. @param num Number in canonical form - @param fmt Format string used by the Tcl format + @param fmt Format string used by the Tcl format command (should be restricted to the form "%.Nf" if present). @param locale Locale @return Localized form of the number -} { - if {$fmt ne ""} { +} { + if {$fmt ne ""} { set out [format $fmt $num] - } else { + } else { set out $num } @@ -191,9 +191,9 @@ set sep , set dec . set grouping 3 - + } - + regsub {\.} $out $dec out return [lc_sepfmt $out $grouping $sep] } @@ -202,7 +202,7 @@ seconds } { Convert a time in the Tcl internal clock seeconds format to ANSI format, usable by lc_time_fmt. - + @author Lars Pind (lars@pinds.com) @return ANSI (YYYY-MM-DD HH24:MI:SS) formatted date. @see lc_time_fmt @@ -231,17 +231,17 @@ } ad_proc -public lc_time_fmt { - datetime - fmt + datetime + fmt {locale ""} } { - Formats a time for the specified locale. + Formats a time for the specified locale. @param datetime Strictly in the form "YYYY-MM-DD HH24:MI:SS". - Formulae for calculating day of week from the Calendar FAQ + Formulae for calculating day of week from the Calendar FAQ (http://www.tondering.dk/claus/calendar.html) @param fmt An ISO 14652 LC_TIME style formatting string. The highlighted functions localize automatically based on the user's locale; other strings will use locale-specific text but not necessarily locale-specific formatting. -
+%a FDCC-set's abbreviated weekday name. %A FDCC-set's full weekday name. %b FDCC-set's abbreviated month name. @@ -268,7 +268,7 @@ %n Acharacter. %p FDCC-set's equivalent of either AM or PM. %r Hours and minutes using 12-hour clock AM/PM - notation, e.g. '06:12 AM'. + notation, e.g. '06:12 AM'. %q Long date without weekday (OpenACS addition to the standard) %Q Long date with weekday (OpenACS addition to the standard) %S Seconds as a decimal number (00-61). @@ -294,7 +294,7 @@ @error Fails if given a non-existent locale or a malformed datetime Doesn't check for impossible dates. Ask it for 29 Feb 1999 and it will tell you it was a Monday (1st March was a Monday, it wasn't a leap year). Also it only works with the Gregorian calendar - - but that's reasonable, but could be a problem if you are running a seriously historical site + but that's reasonable, but could be a problem if you are running a seriously historical site (or have an 'on this day in history' style page that goes back a good few hundred years). @return A date formatted for a locale } { @@ -305,38 +305,38 @@ if { $locale eq "" } { set locale [ad_conn locale] } - + # Some initialisation... # Now, expect d_fmt, t_fmt and d_t_fmt to exist of the form in ISO spec # Rip $date into $lc_time_* as numbers, no leading zeroes 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 lc_time_p 1 if {![regexp -- $matchfull $datetime match lc_time_year lc_time_month lc_time_days lc_time_hours lc_time_minutes lc_time_seconds]} { - if {[regexp -- $matchdate $datetime match lc_time_year lc_time_month lc_time_days]} { - set lc_time_hours 0 - set lc_time_minutes 0 - set lc_time_seconds 0 - } else { - error "Invalid date: $datetime" - } + if {[regexp -- $matchdate $datetime match lc_time_year lc_time_month lc_time_days]} { + set lc_time_hours 0 + set lc_time_minutes 0 + set lc_time_seconds 0 + } else { + error "Invalid date: $datetime" + } } set lc_time_year [util::trim_leading_zeros $lc_time_year] - + set a [expr {(14 - $lc_time_month) / 12}] set y [expr {$lc_time_year - $a}] set m [expr {$lc_time_month + 12*$a - 2}] - + # day_no becomes 0 for Sunday, through to 6 for Saturday. Perfect for addressing zero-based lists pulled from locale info. set lc_time_day_no [expr {(($lc_time_days + $y + $y/4 - $y/100 + $y/400) + (31 * $m / 12)) % 7}] - + return [subst [util_memoize [list lc_time_fmt_compile $fmt $locale]]] } ad_proc -public lc_time_fmt_compile { - fmt + fmt locale } { Compiles ISO 14652 LC_TIME style formatting string to variable substitions and proc calls. @@ -347,46 +347,46 @@ after local variables have been set. } { set to_process $fmt - + set compiled_string "" while {[regexp -- {^(.*?)%(.)(.*)$} $to_process match done_portion percent_modifier remaining]} { - - switch -exact -- $percent_modifier { - x { - append compiled_string $done_portion - set to_process "[lc_get -locale $locale "d_fmt"]$remaining" - } - X { - append compiled_string $done_portion - set to_process "[lc_get -locale $locale "t_fmt"]$remaining" - } - c { - append compiled_string $done_portion - set to_process "[lc_get -locale $locale "d_t_fmt"]$remaining" - } - q { - append compiled_string $done_portion - set to_process "[lc_get -locale $locale "dlong_fmt"]$remaining" - } - Q { - append compiled_string $done_portion - set to_process "[lc_get -locale $locale "dlongweekday_fmt"]$remaining" - } - default { - append compiled_string "${done_portion}$::lang::util::percent_match($percent_modifier)" - set to_process $remaining - } - } + + switch -exact -- $percent_modifier { + x { + append compiled_string $done_portion + set to_process "[lc_get -locale $locale "d_fmt"]$remaining" + } + X { + append compiled_string $done_portion + set to_process "[lc_get -locale $locale "t_fmt"]$remaining" + } + c { + append compiled_string $done_portion + set to_process "[lc_get -locale $locale "d_t_fmt"]$remaining" + } + q { + append compiled_string $done_portion + set to_process "[lc_get -locale $locale "dlong_fmt"]$remaining" + } + Q { + append compiled_string $done_portion + set to_process "[lc_get -locale $locale "dlongweekday_fmt"]$remaining" + } + default { + append compiled_string "${done_portion}$::lang::util::percent_match($percent_modifier)" + set to_process $remaining + } + } } - + # What is left to_process must be (%.)-less, so it should be included without transformation. append compiled_string $to_process - + return $compiled_string } ad_proc -public lc_time_utc_to_local { - time_value + time_value {tz ""} } { Converts a Universal Time to local time for the specified timezone. @@ -402,21 +402,21 @@ set local_time $time_value ad_try { - set local_time [db_exec_plsql utc_to_local {}] + set local_time [db_exec_plsql utc_to_local {}] } on error {errorMsg} { ad_log Warning "lc_time_utc_to_local: Query exploded on time conversion from UTC, probably just an invalid date, $time_value: $errorMsg" } if {$local_time eq ""} { - # If no conversion possible, log it and assume local is as given (i.e. UTC) - ns_log Notice "lc_time_utc_to_local: Timezone adjustment in ad_localization.tcl found no conversion to UTC for $time_value $tz" + # If no conversion possible, log it and assume local is as given (i.e. UTC) + ns_log Notice "lc_time_utc_to_local: Timezone adjustment in ad_localization.tcl found no conversion to UTC for $time_value $tz" } return $local_time } ad_proc -public lc_time_local_to_utc { - time_value + time_value {tz ""} } { Converts a local time to a UTC time for the specified timezone. @@ -431,14 +431,14 @@ set utc_time $time_value ad_try { - set utc_time [db_exec_plsql local_to_utc {}] + set utc_time [db_exec_plsql local_to_utc {}] } on error {errorMsg} { - ad_log Warning "lc_time_local_to_utc: Query exploded on time conversion to UTC, probably just an invalid date, $time_value: $errorMsg" + ad_log Warning "lc_time_local_to_utc: Query exploded on time conversion to UTC, probably just an invalid date, $time_value: $errorMsg" } if {$utc_time eq ""} { - # If no conversion possible, log it and assume local is as given (i.e. UTC) - ns_log Notice "lc_time_local_to_utc: Timezone adjustment in ad_localization.tcl found no conversion to local time for $time_value $tz" + # If no conversion possible, log it and assume local is as given (i.e. UTC) + ns_log Notice "lc_time_local_to_utc: Timezone adjustment in ad_localization.tcl found no conversion to local time for $time_value $tz" } return $utc_time @@ -448,7 +448,7 @@ ad_proc -public lc_time_system_to_conn { - time_value + time_value } { Converts a date from the system (database) to the connection's timezone, using the OpenACS timezone setting and user's preference @@ -471,9 +471,9 @@ } ad_proc -public lc_time_conn_to_system { - time_value + time_value } { - Converts a date from the connection's timezone to the system (database) timezone, + Converts a date from the connection's timezone to the system (database) timezone, using the OpenACS timezone setting and user's preference @param time_value Timestamp from conn input in the ISO datetime format. @@ -531,9 +531,9 @@ Converts HH24 to HH12. } { if {$hours > 12} { - incr hours -12 + incr hours -12 } elseif {$hours == 0} { - set hours 12 + set hours 12 } return $hours } @@ -543,35 +543,35 @@ to 1(Mon) - 7(Sun) } { if {$day_no==0} { - return 7 + return 7 } else { - return $day_no + return $day_no } } ad_proc -private lc_time_name_meridian { locale hours } { Returns locale data depending on AM or PM. } { if {$hours > 11} { - return [lc_get -locale $locale "pm_str"] + return [lc_get -locale $locale "pm_str"] } else { - return [lc_get -locale $locale "am_str"] + return [lc_get -locale $locale "am_str"] } } ad_proc -private lc_leading_space {num} { Inserts a leading space for numbers less than 10. } { if {$num < 10} { - return " $num" + return " $num" } else { - return $num + return $num } } ad_proc -private lc_leading_zeros { - the_integer + the_integer n_desired_digits } { Adds leading zeros to an integer to give it the desired number of digits