Automic Workload Automation

 View Only
  • 1.  AE scripting: time functions trigger runtime error upon encountering input in seconds

    Posted Dec 12, 2022 06:03 PM

    Because there is no CONV_TIME function, to convert from one time format to another one must use a function like DIFF_TIME. (Subtracting zero seconds returns the same value, optionally in a different format.)

    The following script fails with a runtime error on line 4.

    :SET &HHMM#     = "01:01"
    :SET &SS#       = DIFF_TIME("HH:MM;&HHMM#", "HH:MM;00:00", "SS")
    :PRINT &&SS#    : &SS#
    :SET &HHMMSS#   = DIFF_TIME("SS;&SS#", "SS;01", "HH:MM:SS")
    :PRINT &&HHMMSS : &HHMMSS#

    The error is:

    U00020437 Runtime error in object 'EBM.ARITHMETIC.SCRI', line '00004': Time '0000003661' does not correspond to time format 'SS'.


    The same problem affects ADD_TIME and SUB_TIME. Declaring the &SS# variable as signed, unsigned, or string does not help.

    This seems like a bug. If it's possible to convert from HH:MM:SS to seconds, it ought to work the other way around.



  • 2.  RE: AE scripting: time functions trigger runtime error upon encountering input in seconds

    Posted Dec 13, 2022 02:35 AM

    Hi @Michael A. Lowry,

    I would assume "this works like designed"...

    The easiest way to transform seconds back to hours, minutes and seconds is probably this (the percent character means "modulo"):

    :set &number_of_seconds# = "385"
    
    :set &seconds# = &number_of_seconds# % 60
    :set &seconds# = format(&seconds#,"00")
    :set &minutes# = (&number_of_seconds# / 60)  % 60
    :set &minutes# = format(&minutes#,"00")
    :set &hours# = (&number_of_seconds# / 3600)
    :set &hours# = format(&hours#,"00")
    
    : print &hours#:&minutes#:&seconds#

    ​Cheers
    Christoph 



    ------------------------------
    ----------------------------------------------------------------
    Automic AE Consultant and Trainer since 2000
    ----------------------------------------------------------------
    ------------------------------



  • 3.  RE: AE scripting: time functions trigger runtime error upon encountering input in seconds

    Posted Dec 13, 2022 02:43 AM
    Edited by Michael A. Lowry Dec 13, 2022 03:00 AM

    Hi @Christoph Rekers. Yeah, I came up with something similar two minutes ago. :)

    :SET &MM# = 0
    :SET &HH# = 0
    :IF &SS# > 59
    :  SET &MM# = &SS# / 60
    :  SET &SS# = MOD(&SS#,60)
    :ENDIF
    :IF &MM# > 59
    :  SET &HH# = &MM# / 60
    :  SET &MM# = MOD(&MM#,60)
    :ENDIF
    :SET &HH# = FORMAT(&HH#,"00")
    :SET &MM# = FORMAT(&MM#,"00")
    :SET &SS# = FORMAT(&SS#,"00")
    :PRINT HH:MM:SS : &HH#:&MM#:&SS#

    Your version is more succinct.

    I had forgotten about the modulo operator %. I also didn't realize that one could combine arithmetic operations and use parentheses to group & order operations.




  • 4.  RE: AE scripting: time functions trigger runtime error upon encountering input in seconds

    Posted Dec 15, 2022 08:44 AM
    Edited by Michael A. Lowry Dec 15, 2022 08:56 AM
    I opened a support ticket about this problem.


  • 5.  RE: AE scripting: time functions trigger runtime error upon encountering input in seconds

    Posted Dec 27, 2022 08:54 AM
    Edited by Michael A. Lowry Dec 27, 2022 08:55 AM
    I expected, Broadcom Support has claimed that the AE is working as designed. I requested that Broadcom update the documentation page Date, Time and Period Formats in Scripts to make this limitation clear. I proposed the following update:

    ...
    You can specify the following special terms for time formats:

      • HH
      • MM
      • SS

    Note: These special time formats are valid only as target formats, not source formats. If you try to use HH, MM, or SS as a source format, a runtime error will occur. To convert from hours, minutes, or seconds to other formats like HHMMSS, you must use ordinary arithmetic functions. For an example, see the script snippet below.

    Script

    :SET &SS# = 3723
    :SET &MM# = 0
    :SET &HH# = 0
    :IF &SS# > 59
    :  SET &MM# = &SS# / 60
    :  SET &SS# = &SS# % 60
    :ENDIF
    :IF &MM# > 59
    :  SET &HH# = &MM# / 60
    :  SET &MM# = &MM# % 60
    :ENDIF
    :SET &HH# = FORMAT(&HH#,"00")
    :SET &MM# = FORMAT(&MM#,"00")
    :SET &SS# = FORMAT(&SS#,"00")
    :PRINT HHMMSS : &HH#&MM#&SS#

    Output

    HHMMSS : 010203



  • 6.  RE: AE scripting: time functions trigger runtime error upon encountering input in seconds

    Posted Dec 29, 2022 05:09 AM
    Edited by Michael A. Lowry Dec 29, 2022 05:12 AM
    I submitted a new idea for this:
    Time functions should accept HH, MM, and SS input formats

    If you like the idea, please vote for it.