A few years ago I wrote a complex prolog rule to act on an event based on the time of day, however it wasn't until very recently that I revisited the subject after a person on the Tivoli mailing list and also an Orb Data customer both simultaneously asked how to do this.
Thankfully in TEC 3.7, 3.8 and 3.9 the solution is much simpler than the one I worked on and this short tip supplies and explains the finished solution.
As I mentioned earlier the later versions of TEC supplies a number of rule predicates for manipulating time value. In this tip I will mention two of them:
get_local_time
The predicate get_local_time returns a value into the argument _time. The _time variable must be empty (un-instantiated) at execution.
get_local_time(_time)
The time returned is not epoch time; instead it is time structure that can be interrogated by other predicates
resolve_time
The resolve_time predicate turns this time structure (represented by the _time variable returned from the get_local_time predicate) into more readable format including hours, minutes etc. This then allows you to compare the current time/date with your range of "acceptable hours".
resolve_time(_time, _seconds, _minutes, _hours, _day_of_month, _month, _year, _day_of_week, _day_of_year, _daylight_saving)
_time must be set before calling resolve_time and the other arguments must be free.
The values will be in Greenwich Mean Time (GMT).
Most values return values as would be expected using a 24 hour clock (e.g hours return a value from 0 to 23 and minutes returns a value from 0 to 59) however the following exceptions should be noted:
The following example shows the values from a Solaris system:
| Return Value | Code | Description |
|---|---|---|
| 0 | DST_NONE | not on dst |
| 1 | DST_USA | USA style dst |
| 2 | DST_AUST | Australian style dst |
| 3 | DST_WET | Western European dst |
| 4 | DST_MET | Middle European dst |
| 5 | DST_EET | Eastern European dst |
| 6 | DST_CAN | Canada |
| 7 | DST_GB | Great Britain and Eire |
| 8 | DST_RUM | Romania |
| 9 | DST_TUR | Turkey |
| 10 | DST_AUSTALT | Australian style with |
Now the predicates have been explained the rule is not that difficult. The example we will create is a rule that drops all events that do not arrive between Monday and Friday, 9am to 5pm.
The flow diagram below describes the event flow through the rule however essentially the rule does the following:

The complete rule listing is shown below.