A question regarding fromTime and toTime Condition, Please help.

Hi 

Let's see I have a filter, it gives you fromTime and endTime.

and I have 4 time point which is:    00:00,   9:00,    13:00,   17:00

The text number I give to those block as  "00","09","13","17",

now, base on the filter's fromTime and endTime, if my fromTime = 00:00 and endTime is null, it should return me {"00","09","13","17"}.

        if my fromTime = 07:00, endTime is null, it should return me {"09","13","17"},

        if my fromTime = 09:20, endTime is 13:20 , it should return me {"13"},

How should I do the if condition smartly to achieve this, thanks!!!!

  Discussion posts and replies are publicly visible

Parents
  • Here's an example that takes in a list of time points (0,9,13,17) and loops through a dictionary list of from/to times.  You will check if the time point is after the fromTime, and either end time is null or end time is after the time point.  This should get you going:

    a!localVariables(
      local!times: {
        time(0,0,0),
        time(9,0,0),
        time(13,0,0),
        time(17,0,0)
      },
      local!ranges: {
        {fromTime: time(7,0,0), toTime: null},
        {fromTime: time(9,20,0), toTime: time(13,20,0)}
      },
      
      a!forEach(
        items: local!ranges,
        expression: {
          a!localVariables(
            local!currentRange: fv!item,
            reject(
              fn!isnull,
              a!forEach(
                items: local!times,
                expression: {
                  if(
                    and(
                      fv!item>totime(local!currentRange.fromTime),
                      or(
                        fn!isnull(local!currentRange.toTime),
                        totime(local!currentRange.toTime)>fv!item
                      )
                    ),
                    substitute(padleft(hour(fv!item),2)," ",0),
                    null
                  )
                }
              )
            )
          )
        }
      )
    )

  • 0
    A Score Level 1
    in reply to Chris

    This is amazing and worked! 

    Thank you Chris!

Reply Children