PureConnect

Discussion Thread View
Expand all | Collapse all

Best way to select time in a handler

  • 1.  Best way to select time in a handler

    Posted 06-15-2021 14:58
    This seems like a basic question but I want to make sure I'm approaching this the right way. I have handler that uses a timer initiator but I really only want it to perform it's function during business hours. Right now it is assigning a date/time variable using $now, then I am extracting the time using toS to get HHMMSS and using comparison steps to see if it falls within the working hours. Is there a better way to do this?
    #Handlers

    ------------------------------
    Tony Curoso
    American Telesource, Inc.
    ------------------------------


  • 2.  RE: Best way to select time in a handler

    GCAP Member
    Posted 06-15-2021 15:10
    Generally instead of converting to string I'll use the datetimefunctions to get integer values for minutes/hours  (GetHourTZ, GetMinuteTZ) and then compare them to boundary values that I set in a structured parameter so that I don't need to edit the handler to change the start and end times.

    You can also useGetDOWTZ to get an integer return value for the day of the week (1 for sunday, 2 for monday, etc) and use that to exclude specific days/weekends.

    ------------------------------
    AARON LAEL
    State of Utah
    ------------------------------



  • 3.  RE: Best way to select time in a handler

    Posted 06-16-2021 14:01
    Aaron,
    Converting those strings to integers definitely made this work better. Thanks .

    ------------------------------
    Tony Curoso
    American Telesource, Inc.
    ------------------------------



  • 4.  RE: Best way to select time in a handler

    GENESYS
    Posted 06-16-2021 15:33
    As a general principle, try to avoid string comparisons. Think of comparing a variable to the number 12345. If they are both strings, that's five comparisons before we can be sure they are the same. If it's an integer, it's one. Depending on the frequency of doing this, it can make a big difference to performance.

    ------------------------------
    Paul Simpson
    Senior Technical Instructor
    ------------------------------



  • 5.  RE: Best way to select time in a handler

    Posted 06-15-2021 19:05
    I use $now and work off UTC time, since we have BU's in multiple time zones and countries.

    But yea I do it like you are and have been for over a decade.

    ------------------------------
    ryan hedlund
    Stericycle
    ------------------------------



  • 6.  RE: Best way to select time in a handler

    Posted 06-16-2021 06:49
    You can control it via a schedule in Administrator.
    Create a schedule, and assign it a specific keyword.
    Then in the handler, ask for the schedule that applies to the current time, and has the keyword you set.
    If none are found, then the handler is running outside of the schedule.

    This enables you to take advantage of the power of schedules.

    ------------------------------
    Wayne Rhodeback
    Astute, Inc.
    ------------------------------



  • 7.  RE: Best way to select time in a handler

    Posted 06-16-2021 14:00
    Wayne,
    That is very interesting. I'll try this out. Looks like it the handler returns an empty string I can assume that there are no matching schedules.

    ------------------------------
    Tony Curoso
    American Telesource, Inc.
    ------------------------------



  • 8.  RE: Best way to select time in a handler

    GENESYS
    Posted 06-16-2021 15:34
    I like that approach! Interesting idea and one I will definitely add to my "grab bag" for class.

    Thanks!

    ------------------------------
    Paul Simpson
    Senior Technical Instructor
    ------------------------------



  • 9.  RE: Best way to select time in a handler

    Posted 06-16-2021 16:14
    Yes the approach recommended by Wayne led to a much cleaner handler. Thanks everyone for your advice!​

    ------------------------------
    Tony Curoso
    American Telesource, Inc.
    ------------------------------



  • 10.  RE: Best way to select time in a handler

    Posted 06-17-2021 05:09
    Wayne,

    Would you share more details on how you achieved this part?

    I believe using Get Schedule Tool Step in the Designer will return List of String with the Schedules Names only that match the Keyword entered in the Input Box, but how you can retrieve the Schedule Details (i.e. Start Time / End Time / Days ...etc.)

    Cheers,

    ------------------------------
    Youssef Atef
    Jathwa Technology Solutions
    ------------------------------



  • 11.  RE: Best way to select time in a handler

    Posted 06-17-2021 09:29
    The beauty of this approach, is that you don't need to know anything about the schedule other than the keyword assigned to it.
    Say you have a schedule controlling business hours. You assign that schedule the keyword "BusinessHours".
    When the handler starts, it makes a call to "Get Schedules", specifying the keyword in the argument. You'll be returned a list of schedulers with only one schedule. Then, make a call to "Get Best Schedule", passing the list of schedules, the current date and time ($Now), and "Best".
    If receive no schedule back, then the handler is running outside of the scheduled time.

    I use this a lot when I have a timer initiated handler. A handler that will run on schedule, even though you know there is nothing for it to do outside of Business Hours. The handler starts by calling a subroutine with code like above, and is returned a boolean. True, continue to process. False, stop processing.

    ------------------------------
    Wayne Rhodeback
    Astute, Inc.
    ------------------------------