Clock Command

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Clock Command

  • Creator
    Topic
  • #49001
    Ricci Graham
    Participant

      Can anyone tell me why this error is happening:

      This is being called from within an Xlate  and the code in the Pre tcl Proc is as follows:

      lassign $xlateInVals dt

      set dt [clock format [clock scan $dt] -format “%m%d%Y”]

      set xlateOutVals

        errorInfo:

        unable to convert date-time string “200701091244”

          while executing

        “clock scan $dt”

          invoked from within

        “clock format [clock scan $dt] -format “%m%d%Y””

          invoked from within

        “set dt [clock format [clock scan $dt] -format “%m%d%Y”]”

        I am using this same code on other dates in the Xlate and they work fine. So I thought it must be that some of the date are set as a Date and some are as a Date Time Stamp, but I changed the ones that were a Date Time Stamp on the inbound variant and the outbound variant and I am still getting the error.

        I am out of ideas, so any suggestion or ideas would be very much appreciated.

        Thanks,

        Ricci

    Viewing 12 reply threads
    • Author
      Replies
      • #60386
        Jim Kosloskey
        Participant

          Ricci,

          I have found clock scan to be rather picky.

          I use convert_date (HCI provided) to do what you want.

          In your case:

          set dt [convert_date ts $dt yd 8]

          should do the trick and return 01092007.

          To find out more about convert_date go into hcitcl and do a help convert_date.

          Jim Kosloskey

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #60387
          Charlie Bursell
          Participant

            While as Jim said, the clock command is picky, the power of this command as compared to the outdated convert_date command makes it worthwhile.  All Tcl commands if not used correctly are picky  ðŸ™‚

            The clock scan command expects the date and time to be in a list (space separated).  For example “20070117 011323” would scan as would just the date alone (the default of 12:00:00 AM would be used.

            Using the regsub command it is simple to make an HL7 date scanable

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

            The formatting capabilities plus the ability to do date math with the clock command makes it much more powerful than the convert_date command.

            For example

            assume dt = 20070116131522

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

            set yesterday [clock format [clock scan yesterday -base

                     [clock scan $dt]] -format %Y%m%d%H%M%S]

            echo $yesterday

             => 20070115131522

            Try that with convert_date  ðŸ˜‰

          • #60388
            Ricci Graham
            Participant

              Thanks so much to both of you (Jim and Charlie). I ended up using your suggestion, Charlie, because when I tried your’s, Jim, it failed if there wasn’t a date in the field, but otherwise it worked great.

              It is so great to have this as a resource and I appreciate you guys SO much.

              Ricci Graham

            • #60389
              Mike Kim
              Participant

                The good thing about convert_date is that it handles dates prior to 1903.  Clock scan doesn’t.

                Mike

              • #60390
                Rob Parnell
                Participant

                  Why will this time not work with clock scan

                  20080816005200

                • #60391
                  Keith McLeod
                  Participant

                    You may need to insert a ‘T’ between date and time if you want it that granular.

                    hcitcl>clock scan 20080816T005200

                    1218862320

                    hcitcl>clock format 1218862320

                    Sat Aug 16 00:52:00 EDT 2008

                    hcitcl>

                    Hope this helps

                  • #60392
                    Rob Parnell
                    Participant

                      It works fine if I change the hour to 01 intead of 00

                    • #60393
                      Charlie Bursell
                      Participant

                        The clock scan command expects a list of one element (YYYYMMDD) or two elements (YYYYMMDD HHMMSS)

                        A simple solution:

                        set dt 20080816T005200

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

                        It will scan now

                      • #60394
                        John Mercogliano
                        Participant

                          Please read my response in this post, this will give you some more insites to the problem:

                          https://usspvlclovertch2.infor.com/viewtopic.php?t=2613&highlight=” class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=2613&highlight=

                          Adding the T does not work if your original time does not have seconds like a lot of time inputs in messages.  You will need to make sure that you add a 00 for seconds or use one of the regsub expressions in the attached post.

                          John Mercogliano
                          Sentara Healthcare
                          Hampton Roads, VA

                        • #60395
                          Rob Parnell
                          Participant

                            Charlie,

                            Can you explain why this command did not work for the hour of 00 but works for every other time.

                          • #60396
                            Charlie Bursell
                            Participant

                              I can only say it is an anomaly with the clock command.  Given the power of this command, it is well worth the effort to learn the small nuances you encounter.

                              I am sure if you post the question on comp.lang.tcl you will get more answers than you need  ðŸ˜€

                            • #60397
                              Mark Thompson
                              Participant

                                Rob,

                                The problem might be that after clock scan removes the leading zeroes in the time (remember Tcl is picky about numbers with leading zeroes) it doesn’t recognize what’s left as a date/time anymore.  If you colon delimit your time, then clock scan works fine as far back as 1903.  For example: ‘clock scan “20080829 00:01″‘ = 1219986060.

                                - Mark Thompson
                                HealthPartners

                              • #60398
                                John Mercogliano
                                Participant

                                  Rob,

                                    This is actually a bug that is not fixed till version 8.5.  This sourceforge link talks about it:

                                  http://sourceforge.net/tracker/index.php?func=detail&aid=1090413&group_id=10894&atid=110894” class=”bbcode_url”>http://sourceforge.net/tracker/index.php?func=detail&aid=1090413&group_id=10894&atid=110894

                                    Basicly, without the colons in the time it treats the value as an integer chopping off the leading zero’s.  

                                    This link has some regsub commands you can use:

                                  https://usspvlclovertch2.infor.com/viewtopic.php?t=2613&highlight=” class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=2613&highlight=

                                  John Mercogliano
                                  Sentara Healthcare
                                  Hampton Roads, VA

                              Viewing 12 reply threads
                              • The forum ‘Cloverleaf’ is closed to new topics and replies.