Period Functions

Redwood Server features rich calendaring possibilities; Time Windows offer great flexibility while remaining easy to define. However, sometimes complex calculations are required to determine if certain conditions are met for a Time Window to be open, Easter for example. For this matter it is possible to create period functions. Period functions are boolean functions used in Time Windows that calculate when a Time Window is supposed to be open or closed. Period functions are complex functions written in RedwoodScript, stored in the Repository, that are used in Time Windows to calculate the dates and times that a time interval is open.

When you import SAP Calendars (like the Factory and Holiday calendars), these become available as period functions.

You can also define your own period functions, however, since all Time Windows using a period function share the same instance of a period function, parameter values can be cached for performance reasons. You must be very careful and check your parameters.

The following period functions are built-in:

Period Function Description
SAP_FactoryCalendar Use the SAP calendar from an SAP instance to schedule SAP jobs; the calendaring data needs to be imported from the instance
SAP_HolidayCalendar Use the SAP calendar from an SAP instance to schedule SAP jobs; the calendaring data needs to be imported from the instance
System_InDayRecurrence Recurrence within a day
System_Easter Calculates Easter or Easter-based holidays
System_FiscalPeriods Calculates open days based on periods in a fiscal year.

Note: You need the scripting module, which requires the Module.Scripting license key, to be able to create period functions.

Caching Objects in Period Functions

You should not cache SchedulerEntities, such as Time Windows, in period functions as these might have a long life-time or the dispatcher may refresh the session, causing JCS-122017: Trying to use non-attached object TimeWindow errors, for a Time Window in this example.

Easter Period Function

The easter period function accepts one dayNumber parameter, which is the offset to easter Sunday.

No parameter or dayNumber=0 means easter Sunday.

SAP Calendars

SAP calendars are imported and converted to period functions to be used in Time Windows. Period functions of SAP calendars take arguments, as the factory calendar, for example, can include several different calendars, which all must have a unique calendar ID.

SAP Calendar period functions accept the following arguments:

  • calendar=<SAP Instance> <Calendar ID>
Parameter Description
<SAP Instance> The SAP Instance Name
<Calendar ID> The Calendar ID, usually two characters, can be found in the output file of the SAP_ImportCalendar process.

You should only specify instances for which you have imported the calendar with the SAP_ImportCalendar Process Definition and the specific calendar ID must exist in that SAP instance. Use the Opens at tab of the Time Window edit screen to ensure you are using the correct values.

Fiscal Period Function

The fiscal period function is used to calculate open days based on the fiscal year, both US and ISO-8601 fiscal years are supported. Fiscal years divide quarters in 1 five- and 2 four-week periods.

US style fiscal years start on January 1st. ISO-8601 fiscal years always start on Monday. The 4-5-4 fiscal period starts on the 2nd workday to the 6th workday of each period.

Parameter Description Values Default
week{1|2|3} Specifies the number of weeks for the first, second and third period of the quarter 4 (period is 4 weeks long) 5 (period is 5 weeks long) week1=4 week2=4 week3=5
weekday{From|To} Specifies the day(s) of the week. 1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday), 8 (Workday), 9 (Weekends), 10 (Workweek), 0 (Anyday) weekdayFrom=8 (Workday) weekdayTo=8 (Workday)
weekOrDay{From|To} Specifies the number of the day in the period; if the number is larger than the number of days in the period, it specifies the last weekday. integers >=1 (1, 2, 3 ...) weekOrDayFrom=1 (first day of the period) weekOrDayTo=1 (first day of the period)
weekStartsAtWeekday Specifies the first day of a week (requires isoPeriod to be set to true) 1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday) weekStartsAtWeekday=2
weekDayDefiningFirstWeek Specifies the day to use to calculate first week of the year 1 (Sunday), 2 (Monday), 3 (Tuesday), 4 (Wednesday), 5 (Thursday), 6 (Friday), 7 (Saturday) weekDayDefiningFirstWeek=5
isISOPeriod Specifies the start of the year. true (Monday) false (January 1st) false (Year starts on January 1st).

Note: The period function parameters are case-sensitive.

Note: All parameters must be filled or you will not get the desired result.

Using Fiscal Period Functions

When you create a fiscal period function, you first specify the number weeks of your three periods, for example week1=4 week2=4 week3=5.

Next, you specify an open time frame which can be a day or a number of days using the weekdayFrom and weekdayTo parameters, for example weekdayFrom=2 and weekdayTo=6 is equivalent to weekdayFrom=8 and weekdayTo=8; your workweek is from Monday to Friday. The difference between weekdayFrom=8 and weekdayFrom=10 is that the latter is a week, not individual days - this is important when we start counting below.

Finally, you specify when the time frame occurs in your 3 periods using the weekOrDayFrom and weekOrDayTo parameters, for example weekOrDayFrom=5 and weekOrDayTo=5, meaning the last workweek of each period ( 5 is greater than 4 ).

If you only want to have the process run on the 5th week of a period, that is skip it on two of the three periods (those that are 4 weeks in length), you need to create a second Time Window which is open on the 4th week of a period; this Time Window must then be specified in the Disabled During Time Window field of the Time Window element where you specified the period function.

To illustrate the difference between weekdayFrom=8 and weekdayFrom=10, the following table lists equivalent combinations:

Time frame in Workdays Time frame in Workweeks
weekdayFrom=8weekdayTo=8weekOrDayFrom=1weekOrDayTo=5 weekdayFrom=10weekdayTo=10weekOrDayFrom=1weekOrDayTo=1
weekdayFrom=8weekdayTo=8weekOrDayFrom=1weekOrDayTo=10 weekdayFrom=10weekdayTo=10weekOrDayFrom=1weekOrDayTo=2

When isISOPeriod is true, then the Monday of the first week of the year is calculated as follows:

  • the week with the year's first Thursday in it.
  • the week with 4 January in it.

You can customize this behavior with the following parameter:

  • weekDayDefiningFirstWeek

Recurrence within a day

This period function is used to create recurrences in a day.

Parameter Description Values Default
startHour The hour the recurrence starts 0-23 0
startMinute The minute the recurrence starts 0-59 0
startSecond The second the recurrence starts 0-59 0
endHour The hour the recurrence ends 0-23 23
endMinute The minute the recurrence ends 0-59 59
endSecond The second the recurrence ends 0-59 59
intervalHour The interval hour of the recurrence 0-23 0
intervalMinute The interval minute of the recurrence 0-59 15
intervalSecond The interval second of the recurrence 0-59 0
durationHour The duration of the opening (hours) 0-23 0
durationMinute The duration of the opening (minutes) 0-59 1
durationSecond The duration of the opening (seconds) 0-59 0
  • startHour, startMinute, and startSecond specify the start of the recurrence in the day, default 0:00:00.
  • endHour, endMinute, and endSecond specify the end of the recurrence in the day, default 23:59:59.
  • intervalHour, intervalMinute, and intervalSecond specify interval at which the function should open, default is 0:15:00.
  • durationHour, durationMinute, and durationSecond specify how long the recurrence period should open, default is 0:01:00.

Note the following:

  • if duration >= interval, the period function is always open.
  • endTime = 0 is evaluated as the start of the following day.

Note: When the duration >= interval, the period function is always open. When EndTime=0, the EndTime will be the start of the next day.

Period functions support the following context menu options.

Note: For generally applicable object context menu options, see Object Context Menu.

Action Description
Edit Security Edit the security of the period function
Duplicate Make a copy of the period function to create a similar one
Delete Delete the period function
Edit Edit the period function
New period function Create a new period function

Deleting Period Functions

You can only delete period functions when no other objects relate to them. For example, if there are Time Windows that use the period function, the period function cannot be deleted until all Time Windows that use it have been edited to not use it anymore. You can see all objects that relate to the period function in Related Objects in the lower detail pane and on the show page.

The table in related objects contains three columns:

  • Type - the type of object with a link to it
  • Related Object - the name of the object with a link to it
  • Used As - objects can sometimes be used in different roles

Security

The privileges available in the Security tab are as follows.

For more information, see Security Tab.

Privilege Description
PeriodFunction.Create Create period functions
PeriodFunction.Delete Delete period functions
PeriodFunction.Edit Edit period functions
PeriodFunction.View Access period functions

Example

In the following examples, tables illustrate the fields of the Time Window element that need to be filled, all other fields are left with their default values.

SAP Calendar Period Function Parameter

In this example, you want to have the time open on the fourth workday of the SAP Factory Calendar of every month. You need 3 Time Windows in this case. One that is always closed, one that uses the SAP Factory Calendar and one for the day shift.

Note: We need the TW_AlwaysClosed and TW_GermanFactoryCalendar Time Windows below because we want to force Redwood Server to use the SAP Calendar for determining and counting workdays, this way it takes public holidays into account.

You need to create a Time Window that is always closed. Only the following fields need to be specified:

Field Value
Name TW_AlwaysClosed
Is Calendar true (checked)

You also need a Time Window to use the SAP Factory Calendar:

Field Value
Name TW_GermanFactoryCalendar
Is Calendar true (checked)

The German factory calendar of the PR1 instance is used in a Time Window element as follows:

Field Value
Period Function SAP_FactoryCalendar
with parameters calendar=PR1 FR

The Time Window with the day shift is the one you will use in Redwood Server. In this case, it should be open on the first workday of the month and shift 3 days forward when the open day falls on a day where TW_AlwaysClosed is closed.

Tab Field Value
Time Window Name SAP_4th_Workday
Time Window Is Calendar true (checked)
Time Window If an open day is closed during TW_AlwaysClosed
Time Window the shift this day Forward
Time Window to the 3
Time Window open day in TW_GermanFactoryCalendar
Elements and from the 1st workday of the month

Easter Period Function

The following Time Window element defines Good Friday (Friday preceding easter).

Field Value
Period Function System_Easter
with parameters dayNumber=-2

Fiscal Period Function

You want a Time Window to open on the third Monday of each period

Field Value
Period Function System_FiscalPeriods
with parameters week1=4week2=5week3=4weekdayFrom=2weekdayTo=2weekOrDayFrom=3weekOrDayTo=3isISOPeriod=trueweekStartsAtWeekday=2weekDayDefiningFirstWeek=5

You want a Time Window open on the last weekend of each period

Field Value
Period Function System_FiscalPeriods
with parameters week1=4week2=4week3=5weekdayFrom=9weekdayTo=9weekOrDayFrom=5weekOrDayTo=5isISOPeriod=trueweekStartsAtWeekday=2weekDayDefiningFirstWeek=5

You want your Time Window to open on the second and third Thursday of each period

Field Value
Period Function System_FiscalPeriods
with parameters week1=4week2=4week3=5weekdayFrom=5weekdayTo=5weekOrDayFrom=2weekOrDayTo=3isISOPeriod=trueweekStartsAtWeekday=2weekDayDefiningFirstWeek=5

PeriodFunction