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 -r1.29.2.7 -r1.29.2.8 --- openacs-4/packages/acs-lang/tcl/localization-procs.tcl 13 Dec 2019 18:26:40 -0000 1.29.2.7 +++ openacs-4/packages/acs-lang/tcl/localization-procs.tcl 16 Dec 2019 12:12:28 -0000 1.29.2.8 @@ -253,7 +253,15 @@ } { Formats a time for the specified locale. - @param datetime Strictly one of the formats 'YYYY-MM-DD HH24:MI:SS' or 'YYYY-MM-DD' + @param datetime A time string in one of the following formats as + from clock tcl command specifications: "%Y-%m-%d + %H:%M:%S", "%Y-%m-%d %H:%M" and + "%Y-%m-%d". Database timestamps such as + "2019-12-16 12:50:14.049896+01" are also + tolerated, by normalizing them to "2019-12-16 + 12:50:14". Note that in this case all information + about timetzone and fractions of second will be + discarded. @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. @@ -326,15 +334,22 @@ set locale [ad_conn locale] } - if {[catch { - set date_clock [clock scan $datetime -format "%Y-%m-%d"] - }]} { - if {[catch { - set date_clock [clock scan $datetime -format "%Y-%m-%d %H:%M:%S"] - }]} { - error "Invalid date: $datetime" + set datetime [string range [string trim $datetime] 0 18] + foreach format { + "%Y-%m-%d %H:%M:%S" + "%Y-%m-%d %H:%M" + "%Y-%m-%d" + } { + set invalid_format_p [catch { + set date_clock [clock scan $datetime -format $format] + }] + if {!$invalid_format_p} { + break } } + if {$invalid_format_p} { + error "Invalid date: $datetime" + } set date_tokens [list] foreach token [clock format $date_clock -format "%Y %m %d %H %M %S %w"] { Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl,v diff -u -r1.4.2.2 -r1.4.2.3 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl 1 Jul 2019 16:26:56 -0000 1.4.2.2 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-localization-procs.tcl 16 Dec 2019 12:12:28 -0000 1.4.2.3 @@ -21,7 +21,7 @@ lang::catalog::import lang::system::locale_set_enabled - } lang_test__lc_numeric { + } lang_test__lc_procs { Minimal testset for localization functions. To be extended. @@ -57,6 +57,37 @@ aa_equals "asian time " [lc_time_utc_to_local "2013-09-21 23:11:22" "Asia/Tokyo"] "2013-09-22 08:11:22" aa_equals "local time " [lc_time_local_to_utc "2013-09-22 08:11:22" "Asia/Tokyo"] "2013-09-21 23:11:22" + set time [lc_time_fmt "2013-09-21 23:11:22" "%c" en_US] + aa_equals "format en_US time" [lrange $time 0 end-1] "Sat September 21, 2013 11:11 PM" + + set time [lc_time_fmt "2013-09-21 23:11:22" "%c" de_DE] + aa_equals "format de_DE time" [lrange $time 0 end-1] "Sa, 21. September 2013 23:11" + + set time [lc_time_fmt "2013-09-21 23:11:22" "%c" it_IT] + aa_equals "format it_IT time" [lrange $time 0 end-1] "Sab 21 Settembre 2013 23:11" + + aa_equals "asian time " [lc_time_utc_to_local "2013-09-21 23:11:22" "Asia/Tokyo"] "2013-09-22 08:11:22" + aa_equals "local time " [lc_time_local_to_utc "2013-09-22 08:11:22" "Asia/Tokyo"] "2013-09-21 23:11:22" + + set db_timestamp "2019-12-16 12:11:52.125541+01" + set time [lc_time_fmt $db_timestamp "%c" en_US] + aa_equals "format en_US time" [lrange $time 0 end-1] "Mon December 16, 2019 12:11 PM" + + set time [lc_time_fmt $db_timestamp "%c" de_DE] + aa_equals "format de_DE time" [lrange $time 0 end-1] "Mo, 16. Dezember 2019 12:11" + + set time [lc_time_fmt $db_timestamp "%c" it_IT] + aa_equals "format it_IT time" [lrange $time 0 end-1] "Lun 16 Dicembre 2019 12:11" + + set short_timestamp "2019-12-16 12:11" + set time [lc_time_fmt $short_timestamp "%c" en_US] + aa_equals "format en_US time" [lrange $time 0 end-1] "Mon December 16, 2019 12:11 PM" + + set time [lc_time_fmt $short_timestamp "%c" de_DE] + aa_equals "format de_DE time" [lrange $time 0 end-1] "Mo, 16. Dezember 2019 12:11" + + set time [lc_time_fmt $short_timestamp "%c" it_IT] + aa_equals "format it_IT time" [lrange $time 0 end-1] "Lun 16 Dicembre 2019 12:11" } }