How are monthly Scheduled Events planned?

1
When I want to create a microflow, I can repeat for example every 1 month. Because not every month has a 31st of the month, it cannot be triggered on the same "day indicator". Does someone know what kind of interval is used between two events? For example, every four week / every 30 days or something like that.
asked
4 answers
7

Guys, please be aware the scheduled event is NOT planned as described in the other answers.

The platform schedules the scheduled event by fixed intervals. That means that at startup platform schedules the next iterations/intervals the scheduled event should run.
This is done by retrieving the intervals and in addition the platform does some calculatios.

Seconds, Minutes, Hours, Days, and Weeks are scheduled exactly as configured.
However, Months, and Years might not be executed as you would expect. A month is interpreted as a 31 day interval, a year as a 365 day interval.

If you schedule an event to start at 1-March it will run on 1-April, 2-May, 2-Jun, 3-Jul, 3-Aug, 3-Sep, etc...

So be wary when scheduling your events, because it is easily possible that they will run 1 day of what you have been expecting.



This is a simplefied example of the implementation of how the Mx 5.3.2 release calculates the interval. Later releases might behave slightly different, but I haven't seen a message in the release notes that this has been improved.

switch(scheduledEvent.getIntervalType())
{
    case SECOND:
        timeUnit = TimeUnit.SECONDS;
        interval = scheduledEvent.getInterval();
        break;
    case MINUTE:
        timeUnit = TimeUnit.MINUTES;
        interval = scheduledEvent.getInterval();
        break;
    case HOUR:
        timeUnit = TimeUnit.HOURS;
        interval = scheduledEvent.getInterval();
        break;
    case DAY:
        timeUnit = TimeUnit.DAYS;
        interval = scheduledEvent.getInterval();
        break;
    case WEEK:
        timeUnit = TimeUnit.DAYS;
        interval = scheduledEvent.getInterval()*7;
        break;
    case MONTH:
        timeUnit = TimeUnit.DAYS;
        interval = scheduledEvent.getInterval()*31;
        break;
    case YEAR:
        timeUnit = TimeUnit.DAYS;
        interval = scheduledEvent.getInterval()*365;
        break;
}

If it is absolutely critical to run a scheduled event on a specific day of the month, you should schedule the event to run daily.
In your microflow you should start with an exclusive split and do an expression such as:

  parseInteger( formatDateTime( [%CurrentDateTime%], 'dd') ) = 1
  or 
  parseInteger( formatDateTime( [%CurrentDateTime%], 'dd') ) = 15
  // This will run the scheduled event on the 1th and 15th of the month

Or as Herbert suggest us this expression for running it on the last day of the month:

 formatDateTime([%CurrentDateTime%], 'dd') = formatDateTime([%EndOfCurrentMonth%], 'dd').



Edit:
In addition to Monthly scheduled event you also want to be wary when scheduling daily events. If you schedule an event to run every day at a specific time you also need to be aware of daylight saving time.

Whenever you setup an event to run every day at a certain time, it will start at exactly the specified time. However after this it will run at a fixed interval (internally this is calculated back to run every X nanoseconds). This means that a daily event runs every 24 hours.
Therefore if the time changes because of daylight saving, your event could be an hour off.

But this is only applicable depending on the locale (timezone) your server is hosted in. However no matter what option you pick from your perspective, if you are in a country that adapts daylight saving you will notice the scheduled event run an hour off schedule. When scheduling an event to start at a certain UTC time, the platform technically won't have a problem because UTC doesn't know daylight saving. However your users will still experience the event to run at a different hour.

Unfortunately there isn't a great workaround for this issue, you could create a similar solution as described above. This can be done with the same types of expressions, except instead of using date format expression 'dd', you should use 'HH' (0-23 hours), or 'kk' (1-24 hours)

answered
1

When planning a once a month event starting on 04-09 (4 september) it will execute 04-10, 04-11 and so on. So month length doesn't matter for determining the next run, it's always the same day of month (if day is available in that month).

To run safely on the last day of a month: Add an scheduled event that run once every day. First check in microflow is to check if formatDateTime([%CurrentDateTime%], 'dd') = formatDateTime([%EndOfCurrentMonth%], 'dd'). If so, execute the MF.

answered
1

I filed a bug report (203092). The way that the scheduled events are calculated is in my (and I think in many others opinion) is just plainly wrong. The interval type is called month and year, otherwise they should have called it 31 days and 365 days......

Furthermore should the documentation reflect this, because it is very counter intuative.

Regards,

Ronald

answered
0

When you create a scheduled event you fill the start date time. When you then select repeat every month the schedule will run on that day each month. The above problem could only arise when you select the 30th of every month. Because then april would be skipped.

Regards,

Ronald

answered