Question
· Jul 5, 2022

Given a Start Time, Time Zone and Duration (in Minutes): How to calculate End Time

Newbie stuck again, hoping this won't be as bad as I'm thinking. In my DTL Editor I've got 

Source.Appointments.(k1).Date = 07/05/2022

Source.Appointments.(k1).StartTime = 14:30

Source.Appointments.(k1).Duration = 30

 

Looking to Formation a target StartTime and End Time based on the above values (and known time Zone) so they are formatted in this format 2022-07-05T02:30:00Z005:00" as the end goal right now I've got it to where I can get this for a start time as I really want to figure out the duration part before I figure out the format above: 07/05/2022 14:30 

In the Data Transform Builder I've done two sets to get StartTime where I want it

 

source.Appointments.(k1).Date_" "_source.Appointments.(k1).StartTime

and then a second set using ..ConvertDateTime(target.Appointments.(k1).StartTime,"%k(-5) %#D %R","%q")

The next call is trying to do a conversion on both the duration and the start time and add them together to get an output but I feel like I'm heading in the wrong direction

..ConvertDateTime(..ConvertDateTime(target.Appointments.(k1).StartTime,"%q","%q(3)")+..ConvertDateTime(source.Appointments.(k1).Duration,"%M","%q(3)"),"%q(3)","%q")

We are trying to be as low code as possible so trying to do this all via GUI and was wondering if you all think this is even possible. Thanks in advance, your assistance is much appreciated. 

Product version: IRIS 2022.1
$ZV: IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2021.2 (Build 651U) Mon Jan 31 2022 18:07:01 EST
Discussion (3)1
Log in or sign up to continue

rushed this out but may help. Remember utc you could extend the rules and then these would appear in the function dropdown. This would allow you to use objectscript to return the starttime and another method to return the enddatetime. You'd need to focus on yr default values in case any "in" values are invalid and for the second method - the 'duration' is this always in seconds? e.g Class GEN.Transform.cusFunctions Extends Ens.Rule.FunctionSet [ ProcedureBlock ] { ClassMethod retStartTime(in1 As %String = "", in2 As %String = "") As %String { s ret="" //default value? q:in1="" ret q:in2="" ret s ret=$zdt($zdth(in1_" "_in2,4),3,7) q ret } ClassMethod retEndTime(in1 As %String = "", in2 As %String = "", in3 As %String = "") As %String { s ret="" //default value? q:in1="" ret q:in2="" ret q:in3="" ret //need to determine if in3 is always in seconds - if yes then following may work s dt=$zdth(in1_" "_(in2),4) s $p(dt,",",2)=$p(dt,",",2)+in3 s ret=$zdt(dt,3,7) q ret } ------- test from terminal BPTLIVE>w in1 07/05/2022 BPTLIVE>w in2 14:30 BPTLIVE>w in3 30 BPTLIVE>w ##Class(GEN.Transform.cusFunctions).retStartTime(in1,in2) 2022-05-07T13:30:00Z BPTLIVE>w ##Class(GEN.Transform.cusFunctions).retEndTime(in1,in2,in3) 2022-05-07T13:30:30Z BPTLIVE>

ClassMethod ConvertAthenaTimes(pDate As %String = "", pStartTime As %String = "", pDuration As %String = "", pTZ As %String = "") As %String
{
    //Set Defaults and Return if no Values Passed in
    Set return = ""
    q:pDate="" return
    q:pStartTime="" return
    //Convert pDuration into Seconds
    s:pDuration]"" pDuration=pDuration*60
    s dt=$zdth(pDate_" "_pStartTime_pTZ,1,5)
    if pDuration set $p(dt,",",2)=$p(dt,",",2)+pDuration
    set return=$zdt(dt_pTZ,3,5)

    // do something
    q return
}

ClassMethod TestFunction()
{
    try{
        w ##class(SERVICESVCPKG.Model.Functions.ProcessFunctions).ConvertAthenaTimes("7/21/2022","08:00",30,"-05:00")
    }catch(ex){
    #dim ex As %Exception.AbstractException
    w ex.DisplayString()
    }
}

I made a few tweaks and got to this:

2022-07-21T08:30:00+00:00

Not Quite sure how to get that TZ to change outside of changing the display format and just appending the pTZ parameter which would work. Not sure if $ZDATETIMEH handles time zone conversions when going from internal time or not.