killing messages based on date

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library killing messages based on date

  • Creator
    Topic
  • #55054
    Kevin Crist
    Participant

    I need to kill a messages that have an admit date of greater than 3 days. How is the best way to go about this? not that familiar with clock scan so not sure how to proceed.

    thanks.

Viewing 2 reply threads
  • Author
    Replies
    • #83925
      Keith McLeod
      Participant

      clock scan 20160416

      clock scan “today”

      clock scan “3 days ago”

      if {[clock scan ] < [clock scan "3 days ago"]} {

           #Kill the message

      }

      Just thoughts that may be helpful….

      hcitcl>clock scan “today”

      1461096980

      hcitcl>clock scan “3 days ago”

      1460779200

      hcitcl>clock scan 20160404

      1459742400

    • #83926
      Charlie Bursell
      Participant

      I agree that the clock command is very powerful when doing date math

      One caveat.  If the date value to be scanned contains time (datetime) the scan command expects a list in the form od “date time”

      regsub is a simple way to convert a datetime string(there are many other methods):

      Assume PV1.44 = 20160420142424  (YYYYMMDDHHMMSS)

      clock format [clock scan $pv1_44]

      Sat Aug 29 00:00:00 ICT 5215215   ;# Not what you wanted

      regsub — {(d{8})(.*)} $pv1_44 {1 2} pv1_44

      clock format [clock scan $pv1_44]

      Wed Apr 20 14:24:24 ICT 2016    ;# Much better

    • #83927
      Jeff Dinsmore
      Participant

      I would also recommend that you always catch the result of clock scan.  It can be pretty picky and you don’t want to have unhandled Tcl errors.

      Something like this:

      Code:

      if { [catch {set scanSec [clock scan “[string range $pv1_44 0 7] [string range $pv1_44 8 13]”]} err] } {
      puts “handle error here ($err)”
      } else {
      puts “[clock format $scanSec -format “%Y/%m/%d %H:%M:%S – %A”]”
      }

      A value of 20160420142424 for pv1_44 produces this:

      Quote:

      2016/04/20 14:24:24 – Wednesday

      A value of 2016×420142424 for pv1_44 produces this:

      Quote:

      handle error here (unable to convert date-time string “2016×420 142424”: more than one time of day in string)

      Jeff Dinsmore
      Chesapeake Regional Healthcare

Viewing 2 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,074
Forums
28
Topics
9,252
Replies
34,241
Topic Tags
275