Time and Date Expressions – isBeforeDate / isAfterDate / isSameDate

isBeforeDate / isAfterDate / isSameDate

In Rainbird, concepts can be ‘date’ concepts.  Date concepts should be used when a date will be either input into or output by Rainbird. Dates in Rainbird are formatted as YYYYMMDD (e.g. 1st of March 2021 would be formatted as 2021-03-01).

Rainbird can use date expressions to transform and calculate dates. Date expressions can be combined with other date, transformative and comparative expressions to ‘retrieve’, ‘add’,  ‘subtract’ or ‘compare’ time

This article will focus on three date expressions:

    • isBeforeDate
    • isAfterDate
    • isSameDate

To demonstrate the isBeforeDate, isAfterDate and isSameDate expressions, this article will demonstrate how to build a map that uses the expressions to let a user know whether a shop voucher is still valid based on the expiration and the redeemed by date of the voucher.

Create the following concepts:

2 string concepts – ‘Person’ and ‘Valid’

1 date concept – ‘Date’ 

Next, connect the concepts with relationships, as shown in figure 1:

Figure 1: Concepts connected with relationship

The main query of the map will be on the ‘is valid’ relationship. The ‘redeemed on date’ and ‘expiry date’ relationships will be used to gather information from the user about a voucher’s redeemed on/expiry date.

Next, create two concept instances for the concept ‘Valid’, ‘Yes‘, and ‘No‘:

Figure 2: ‘Valid’ concept instances

Rainbird will work out if a voucher has expired or not, by comparing the dates entered on runtime. Rainbird will need a rule if a voucher is valid, and if a voucher is not valid. The two rules that the map will use will be built on the relationship ‘is valid‘.

Voucher is valid (Yes):

Open up the ‘is valid‘ relationship, and click ‘add rule’. The rule will be object specific, so the object of the relationship will need to be set to ‘Yes‘ for the first rule.

Rainbird will need to ask the user to enter both the redeem date ‘redeem on date’ and the expiration date ‘expiry date’, so both relationships need to be added as conditions of the rule.

To add a relationship to a rule, click ‘add condition’ and select the relationship from the drop-down menu. The %DATE object for each relationship needs to be renamed to %REDEMPTIONDATE and %EXPIRYDATE (depending on the relationship) so that Rainbird can differentiate between the different date values entered at runtime.

Figure 3: Building the object-specific rule

As we want Rainbird to return ‘Yes‘ if the redemption date is before the expiry date or the same as the expiry date, we need to add an expression using the isBeforeDate and the isSameDate expressions to the ‘yes’ rule, as detailed in figure 4:

Figure 4: using the isBeforeDate and isSameDate expression against the dates entered

Rainbird will check whether the %REDEMPTIONDATE is before the %EXPIRYDATE, or whether the %REDEMPTIONDATE is the same as the %EXPIRYDATE. If either expression is satisfied, then Rainbird will return a ‘Yes’ value.

Voucher is not valid (No):

We also need to create a rule that will tell Rainbird when a voucher is not valid. To save time, we can duplicate the existing Rule and make the appropriate changes to cover the outcome should a voucher be redeemed past the expiry date entered.

To duplicate the rule, open the ‘is valid’ relationship, click the three dots to the side of the ‘coupon is valid yes’ rule, and select duplicate from the drop-down menu:

Figure 5: Duplicating the rule

Open up the duplicated rule, and change the Object of the rule to ‘No‘. The first two conditions can be kept the same, as Rainbird will still require both the redemption and expiry date for the rule to work.

Next, remove the isSameDate expression and replace isBeforeDate with isAfterDate:

Figure 6: Changing the duplicated rule for the ‘No’ outcome

Rainbird will check whether the %REDEMPTIONDATE is after the %EXPIRYDATE, and will return ‘No’ if the %REDEMPTIONDATE is after the %EXPIRYDATE.

Now, as Rainbird knows when a voucher is valid or not valid, the query can be run.

Depending on the dates entered on runtime, either the ‘Yes’ or ‘No’ rule will be triggered. When running the query on the ‘is valid’ relationship, if we were to enter 2021-05-04 as the expiry date, and 2021-05-03, Rainbird would return ‘yes’ as the answer to the query:

Figure 7: Query result

Click on the ‘Export.rbird’ button to download the ‘isBefore’ map used in this example. The knowledge map can then be imported into your Rainbird Studio.

Query and Results

To see isBeforeDate, isAfterDate, and isSameDate expressions in action, run the query on the ‘is valid’ relationship in the knowledge map.

Article Feedback form
Did you find this article useful?

Version 1.02 – Last Update: 10/03/2021