Temporal Expressions Tutorial

This tutorial is intended to be used with the current trunk version of Apache Open For Business.

Log into your local copy of OFBiz as admin. To create or modify temporal expressions, you will need to go to Web Tools -> Configuration -> Temporal Expression. To create calendar events based on temporal expressions, you will need to go to Work Effort -> Work Effort -> Create Work Effort. You should locate these screens and familiarize yourself with these applications before starting the tutorial.

Create A Frequency Expression

Let's say you want to keep track of your pay days - which occur every two weeks on Friday. To do that you will need a Frequency temporal expression.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Frequency section. Type PAYDAY in the Expression ID field. Click the Calendar icon next to the From field to bring up a popup calendar. Select January 8, 2010 08:00. Click OK. Select Day Frequency Type and select 14 in the Frequency Count field. Click the Save button.

In the Create Work Effort screen, type "Pay Day" in the Name field. Select Event for the Type, select Confirmed for the Status, select General for the Scope, and use the Calendar icon to set Estimated Start Date to January 1, 2010. Scroll down the screen to find the Temporal Expression field. Select PAYDAY. Click Save. The Pay Day calendar event has been created. To view it, click the Calendar tab, then select Month View. You will see the pay day appear every two weeks on Friday.

Create A Day Of Month Event

Now that you have your pay days appearing on your calendar, you decide you would also like to see the days your car payment is due - which is the 15th of the month. There is no need to create a temporal expression for that - the OFBiz temporal expression demo data includes every day of the month.

In the Create Work Effort screen, type "Car Payment" in the Name field. Select Event for the Type, select Confirmed for the Status, select General for the Scope, and use the Calendar icon to set Estimated Start Date to January 1, 2010. Scroll down the screen to find the Temporal Expression field. Select DAYOFMONTH_15. Click Save. The Car Payment calendar event has been created. To view it, click the Calendar tab, then select Month View. You will see the car payment due date appear every 15th of the month.

Create A Complicated Recurring Event

You like to play soccer. You like to play soccer so much you practice four days a week - Monday, Tuesday, Wednesday, and Saturday. The Monday through Wednesday practices are at 6 PM, and the Saturday practice is at 10 AM. On the last Saturday of the month a lacrosse team uses the field you practice on, so your teammates agreed to reschedule that practice to 1 PM Sunday. [Having a soccer team surrender a field to a lacrosse team is a supreme act of charity - one that your team is immensely proud of.] There is one other exception to the schedule your teammates agreed on: If a practice falls on Saint Patrick's Day, the practice is canceled (since it is very unlikely anyone would show up).

Now, you have no problem remembering your soccer practice schedule. The problem is, no one else can remember it - so you decide to add it to your calendar. If anyone wants to know when you are at soccer practice, all they have to do is check your calendar.

It would be best to start off by writing out the schedule using the temporal expression notation:

  Difference:
    Include:
      Union:
        Intersection:
          MinuteRange(0, 0)
          HourRange(18, 18)
          DayOfWeekRange(Monday, Wednesday)
        Substitution:
          Include:
            Intersection:
              MinuteRange(0, 0)
              HourRange(10, 10)
              DayOfWeekRange(Saturday, Saturday)
          Exclude:
            DayInMonth(Saturday, -1)
          Substitute:
            Intersection:
              MinuteRange(0, 0)
              HourRange(13, 13)
              DayOfWeekRange(Sunday, Sunday)
    Exclude:
      Intersection:
        DayOfMonthRange(17, 17)
        MonthRange(3, 3)

Complicated temporal expressions like this need to be built from the inside out. So, to start off you will create the Monday through Wednesday intersection, the Saturday intersection, the Sunday intersection, and the Saint Patrick's Day intersection. Finally, you will assemble the intersections into the Union, Substitution, and Difference collections.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Day Of Week Range section. Type MON_THRU_WED in the Expression ID field. Select Monday for the From field and select Wednesday for the To field. Click the Save button. Go back to the Find Temporal Expression screen, and click Create. In the Temporal Expression Maintenance screen, find the Intersection section. Type MON_THRU_WED_6PM in the Expression ID field and click the Save button. Now you can add member expressions to the intersection. Select MINUTE_00 in the Include field and click Save. Select HOUR_18 in the Include field and click Save. Select MON_THRU_WED in the Include field and click Save. Your Monday through Wednesday at 6PM intersection is finished.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Intersection section. Type SAT_10AM in the Expression ID field and click the Save button. Now you can add member expressions to the intersection. Select MINUTE_00 in the Include field and click Save. Select HOUR_10 in the Include field and click Save. Select DAYOFWEEK_07 in the Include field and click Save. Your Saturday at 10AM intersection is finished.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Intersection section. Type SUN_1PM in the Expression ID field and click the Save button. Now you can add member expressions to the intersection. Select MINUTE_00 in the Include field and click Save. Select HOUR_13 in the Include field and click Save. Select DAYOFWEEK_01 in the Include field and click Save. Your Sunday at 1PM intersection is finished.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Intersection section. Type MARCH_17 in the Expression ID field and click the Save button. Now you can add member expressions to the intersection. Select DAYOFMONTH_17 in the Include field and click Save. Select MONTH_RANGE_03 in the Include field and click Save. Your March 17th intersection is finished.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Day In Month section. Type LAST_SATURDAY in the Expression ID field. Select -1 for the Occurrence field and Saturday for the Day field. Click Save. Your last Saturday of the month expression is finished.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Substitution section. Type SOCCER_SUBST in the Expression ID field and click the Save button. Now you can add member expressions to the substitution. Select SAT_10AM in the Include field and click Save. Select LAST_SATURDAY in the Exclude field and click Save. Select SUN_1PM in the Substitution field and click Save. Your soccer practice Saturday substitution is finished.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Union section. Type SOCCER_UNION in the Expression ID field and click the Save button. Now you can add member expressions to the union. Select MON_THRU_WED_6PM in the Include field and click Save. Select SOCCER_SUBST in the Include field and click Save. Your Monday, Tuesday, Wednesday, and Saturday union is finished.

In the Find Temporal Expression screen, click Create. In the Temporal Expression Maintenance screen, find the Difference section. Type SOCCER_PRACTICE in the Expression ID field and click the Save button. Now you can add member expressions to the difference. Select SOCCER_UNION in the Include field and click Save. Select MARCH_17 in the Exclude field and click Save. Your soccer practice temporal expression is finished.

In the Create Work Effort screen, type "Soccer Practice" in the Name field. Select Event for the Type, select Confirmed for the Status, select General for the Scope, and use the Calendar icon to set Estimated Start Date to January 1, 2010. Scroll down the screen to find the Temporal Expression field. Select SOCCER_PRACTICE. Click Save. The Soccer Practice calendar event has been created. To view it, click the Calendar tab, then select Month View. You will see the soccer schedule. Notice how the last Saturday of the month has been rescheduled. Scroll through the months to get to March 2010. Notice how practice has been canceled on March 17th.

  • No labels