Setting up a dynamic start time to run a WF

So I have created a data type, Sequence, that has a text field (start time, for example, 9:30am), a number (delay time, in minutes), and a list of steps (another data type that can execute actions such as send an email, write a note, etc). Another data type, userSequence, uses a sequence for instructions, as well as the user data type to know who to do the actions on.

So I have a BEWF that can be triggered with the parameters of a user and a sequence, which will create a new userSequence, that will in turn begin to schedule steps listed in the attached sequence. This is where I run into a problem, as I want to schedule the BEWF to wait at least the delay time specified in the sequence, and then run at the specified start time.

For example, suppose my sequence had a delay time of 30 minutes, and a start time of 9:30am. Let’s say a user is added to a userSequence at 8:00am. The program would wait 30 minutes, (now 8:30am) and then wait until 09:30am to run. Another instance, if it was run at (9:01am), it would wait 30 minutes (09:31am), then wait until the following day at 9:30am.

So the first problem would be to convert the text time into a date. I would feed the parameters of the text time and the current date (date1) and compare that to the current date plus the delay time (date2). If date1>=date2, then schedule for date1. If date1<date2, add 1440 minutes (24 hours) and check again, repeating as necessary.

Question 1 - what would be the most efficient way of converting text time (h:MM tt format) into a date?

Question 2 - Is this logic I’m using for scheduling sound? Or is there a cleaner way of scheduling I’m overlooking?

So I went a different way and instead of using a text field for the time, I replaced it with 2 number fields, one for hours and one for minutes (24 hour time format). I then was able to create a logic for running the steps in that sequence based on the start hour, start minute, and delay as follows:

Condition 1: The current date changed to use the start time is greater than or equal to the current date plus the delay time. This means that the step can run on the current day.


Condition 2a: The current date changed to use the start time is less than the current date plus the delay time. That means day(s) need to be added. We need to compare the current date using the start time versus the current date and see which is later.

Condition 2b: If the current date using the start time is less than the current date, we divide the delay time by 1440 (minutes to day conversion), round down and add a day, ensuring the soonest possible start at that start time. If the current date using start time is greater than the current date, then we divide the delay time by 1440 and round up to ensure the earliest start time.

Condition 3: If there is no start time specified, then we just run on current date plus delay time.
condition3

So far this seems to have worked as intended. It doesn’t seem very clean, as doing all the math requires using arbitrary text and within that a comparison to get the calculation and then converting it into a number, and using three different steps to run the BEWF steps using conditionals. If anyone has any input, I’m all ears.