# HG changeset patch # User Matti Hamalainen # Date 1613471477 -7200 # Node ID c11ee9fea4b8e072003b0538abb77df0a2ad76a3 # Parent 5260156d95210183e6edec1a14aeec7b6a11a3ca tj: Use new datefmt_short and datefmt_long and fix up/implement rest of the date delta description logic for miscellaneous messages. diff -r 5260156d9521 -r c11ee9fea4b8 config.tj.example --- a/config.tj.example Tue Feb 16 12:30:07 2021 +0200 +++ b/config.tj.example Tue Feb 16 12:31:17 2021 +0200 @@ -69,7 +69,8 @@ ### array set tj_messages { - "datefmt" "%d.%m.%Y %H:%M" + "datefmt_long" "%d.%m.%Y %H:%M" + "datefmt_short" "%d.%m.%Y" "help_full" {"help" "help_set" "help_list" "help_delete"} "help" "@cmd@ \[#\] \[nimi\]" @@ -105,8 +106,11 @@ "tj_str_sep" ", " "tj_str_sep_last" " ja " - "tj_remaining" "@1@:llä on @3@ jäljellä @2@ (@4@)." + "tj_future" "@1@:llä on @3@ jäljellä @2@ (@4@)." "tj_past" "@1@ on ollut @2@-reservissä @3@ (@4@)." + "tjs_future" "jäljellä @1@" + "tjs_past" "kulunut @1@" + "tj_not_set" "@1@:n @2@-TJ:tä ei ole asetettu." } diff -r 5260156d9521 -r c11ee9fea4b8 tj.tcl --- a/tj.tcl Tue Feb 16 12:30:07 2021 +0200 +++ b/tj.tcl Tue Feb 16 12:31:17 2021 +0200 @@ -116,7 +116,12 @@ proc tj_ctime {ustamp} { - return [clock format $ustamp -format [tj_qm "datefmt"]] + return [clock format $ustamp -format [tj_qm "datefmt_long"]] +} + + +proc tj_ctimes {ustamp} { + return [clock format $ustamp -format [tj_qm "datefmt_short"]] } @@ -162,19 +167,18 @@ } -proc tj_get_tj_str_delta { ustamp } { - set udelta [expr $ustamp - [clock seconds]] +proc tj_get_tj_str_delta {ustamp uclock} { + set udelta [expr $ustamp - $uclock] if {$udelta < 0} { - set ufmt "tj_past" + set ufmt "tjs_past" set useconds [expr -$udelta] } else { - set ufmt "tj_remaining" + set ufmt "tjs_future" set useconds $udelta } -# return [utl_str_map_values [tj_qm $ufmt] [list ]] - return [tj_get_tj_str $useconds] + return [utl_str_map_values [tj_qm $ufmt] [list [tj_get_tj_str $useconds] [tj_ctime $ustamp]]] } @@ -382,8 +386,12 @@ } } - tj_msg $upublic $unick $uchan "tj_updated" [list $cid $uid $uhand $rdesc $udate $utjstr] - tj_log "tj_updated $cid:$uid:$uhand:$rdesc:$rdate:$udate" + set usql "SELECT * FROM tj WHERE uuser='[utl_escape $uhand]' AND uid LIKE '[utl_escape $uid]'" + tj_dbh eval $usql { + set utjstr [tj_get_tj_str_delta [utl_sql_datetime_to_stamp $utarget] $uclock] + tj_msg $upublic $unick $uchan "tj_updated" [list $id $uid $uhand $udesc $udate $utjstr] + tj_log "tj_updated $id:$uid:$uhand:$udesc:$utarget" + } } } elseif {[tj_cmd_match "remind" $rcmd]} { @@ -414,8 +422,9 @@ set usql "SELECT * FROM tj WHERE uuser='[utl_escape $uname]' ORDER BY ucreated" tj_dbh eval $usql { incr nitem - set ustamp [utl_sql_datetime_to_stamp $utarget] - tj_msg $upublic $unick $uchan "list_item" [list $nitem $nitems [tj_ctime $ustamp] $uid $udesc] + set qtarget [utl_sql_datetime_to_stamp $utarget] + set ustr [tj_get_tj_str_delta $qtarget $uclock] + tj_msg $upublic $unick $uchan "list_item" [list $nitem $nitems [tj_ctime $qtarget] [tj_ctimes [utl_sql_datetime_to_stamp $ucreated]] [tj_ctimes [utl_sql_datetime_to_stamp $uupdated]] $uid $udesc $ustr] } if {!$nitem} {