util::age_pretty (public)
util::age_pretty -timestamp_ansi timestamp_ansi \ -sysdate_ansi sysdate_ansi [ -hours_limit hours_limit ] \ [ -days_limit days_limit ] [ -mode_2_fmt mode_2_fmt ] \ [ -mode_3_fmt mode_3_fmt ] [ -locale locale ]
Defined in packages/acs-tcl/tcl/utilities-procs.tcl
Formats past time intervals in one of three different modes depending on age. The first mode is "1 hour 3 minutes" and is NOT currently internationalized. The second mode is e.g. "14:10, Thursday" and is internationalized. The third mode is "14:10, 01 Mar 2001" and is internationalized. Both the locale and the exact format string for modes 2 and 3 can be overridden by parameters. (Once mode 1 is i18nd, the following sentence will be true:'In mode 1, only the locale can be overridden.' Until then, move along. These aren't the timestamps you're looking for.)
- Switches:
- -timestamp_ansi (required)
- The older timestamp in full ANSI: YYYY-MM-DD HH24:MI:SS
- -sysdate_ansi (required)
- The newer timestamp.
- -hours_limit (optional, defaults to
"12"
)- The upper limit, in hours, for mode 1.
- -days_limit (optional, defaults to
"3"
)- The upper limit, in days, for mode 2.
- -mode_2_fmt (optional, defaults to
"%X, %A"
)- A formatting string, as per lc_time_fmt, for mode 2
- -mode_3_fmt (optional, defaults to
"%X, %d %b %Y"
)- A formatting string, as per lc_time_fmt, for mode 3
- -locale (optional)
- If present, overrides the default locale
- Returns:
- Interval between timestamp and sysdate, as localized text string.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- util__age_pretty
Source code: set age_seconds [expr {[clock scan $sysdate_ansi] - [clock scan $timestamp_ansi]}] if { $age_seconds < 30 } { # Handle with normal processing below -- otherwise this would require another string to localize set age_seconds 60 } if { $age_seconds < $hours_limit * 60 * 60 } { set hours [expr {abs($age_seconds / 3600)}] set minutes [expr {round(($age_seconds% 3600)/60.0)}] if {$hours < 24} { switch -- $hours { 0 { set result "" } 1 { set result "One hour " } default { set result "$hours hours "} } switch -- $minutes { 0 {} 1 { append result "$minutes minute " } default { append result "$minutes minutes " } } } else { set days [expr {abs($hours / 24)}] switch -- $days { 1 { set result "One day " } default { set result "$days days "} } } append result "ago" } elseif { $age_seconds < $days_limit * 60 * 60 * 24 } { set result [lc_time_fmt $timestamp_ansi $mode_2_fmt $locale] } else { set result [lc_time_fmt $timestamp_ansi $mode_3_fmt $locale] }XQL Not present: PostgreSQL, Oracle Generic XQL file: packages/acs-tcl/tcl/utilities-procs.xql