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 YYYY-MM-DD (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.
The expressions discussed in this article are used by Rainbird to add or subtract a value to or from a date instance that has been created at runtime by the end-user or that exists as a fact in a knowledge map.
The expressions discussed in the article are:
- addDays: adds a specific amount of days to a date,
- addWeeks: adds a specific amount of weeks (7 days) to a date
- addMonths: adds a specific amount of months to a date
- addYears: adds a specific amount of years to a date
The above expressions are unlikely to be used in isolation. They can be used with other date expressions, for example, the ‘today’s date’ expression
Click on an expression below for instructions on how to build a rule that uses that expression:
addDays(): Rainbird uses the addDays() function to add or subtract a number of days to or from a date entered at runtime or a date that exists as an instance within the knowledge map the function is being used in.
The next couple of tabs will demonstrate how to create a map that will use an addDays function to deduct two days from a date entered at runtime.
Figure 1: Example rule using the addDay expression that would subtract 2 days from the %DAYS value
Create a string concept, ‘Start Point ‘and a date concept, ‘Date Concept’, connected with a relationship, ‘start date’:
Figure 2: Date concept ‘date concept’ linked to ‘start point’ string concept with the relationship ‘start date’
Next, create a second relationship between the ‘start point’ and ‘date concept’ concepts, called ‘day before yesterday’. The main rule for the calculation will sit on the ‘day before yesterday’ relationship
The rule is made up of two components: one condition, and one expression.
The condition, ‘%S start date %DAYS’ assigns the start date the end-user inputs to the variable %DAYS. The %DAYS value will be the value used in the expression.
Now, we can create the ‘addDays’ expression. As the expression will subtract two days (-2) from the %DAYS value (the start date entered by the user), the expression will be ‘addDays(%DAYS, -2)‘. You will need to assign the variable of the expression to %O, so that Rainbird will display the sum of the expression as the outcome of the query.
Figure 3: Building the addDays(%DAYS, -2) rule
Note: When writing an expression, you will need to leave a space between the apostrophe in the brackets and the number that will be added/subtracted to/from the variable
Now we can run the query. If we enter, for example, 4th January, 2007 (2007-01-04), the addDays(%DAYS -2) function would return the result ‘2nd January, 2007’:
Figure 4: Outcome of addDays(%DAYS, -2) query when 4th January 2007 is the input date
When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the addDays function, please run the query on the ‘day before yesterday’ relationship.
addWeeks(): Rainbird uses the addWeeks() function to add or subtract a number of weeks to or from a date entered at runtime or a date that exists as an instance within the knowledge map the function is being used in.
The next couple of tabs will demonstrate how to create a map that will use an addWeeks function to add two weeks to a date entered at runtime.
Figure 5: Example of an addWeeks expression that would add 2 weeks to a value, %WEEKS
Create a string concept, ‘Start Point ‘and a date concept, ‘Date Concept’, connected with a relationship, ‘start date’:
Figure 6: Date concept ‘date concept’ linked to ‘start point’ string concept with the relationship ‘start date’
Next, create a second relationship between the ‘start point’ and ‘date concept’ concepts, called ‘add two weeks’. The main rule for the calculation will sit on the ‘day before yesterday’ relationship
The rule is made up of two components: one condition, and one expression.
The condition, ‘%S start date %WEEKS’ assigns the start date the end-user inputs to the variable %WEEKS. The %WEEKS value will be the value used in the expression.
Now, we can create the ‘addWeeks’ expression. As the expression will add two weeks to the %WEEKS value (the start date entered by the user), the expression will be ‘addWeeks(%WEEKS, 2)‘. You will need to assign the variable of the expression to %O, so that Rainbird will display the sum of the expression as the outcome of the query.
Figure 7: Building the addWeeks(%WEEKS, 2) rule.
Note: When writing an expression, you will need to leave a space between the apostrophe in the brackets and the number that will be added/subtracted to/from the variable
Now we can run the query. If we enter, for example, 4th January, 2007 (2007-01-04), the addWeek(%WEEKS 2) function would return the result ’18th January, 2007′:
Figure 8: Outcome of addWeeks(%WEEKS, 2) query when 4th January 2007 is the input date
When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the addWeeks function, please run the query on the ‘add two weeks’ relationship.
addMonths(): Rainbird uses the addMonths() function to add or subtract a number of months to or from a date entered at runtime or a date that exists as an instance within the knowledge map the function is being used in.
Note: Rainbird will not create an impossible date. For example. if we add one month to the 31st of January, the result would be the last possible date in February (the 28th/29th of February).
The next couple of tabs will demonstrate how to create a map that will use an addMonths function to add nine months to a date entered at runtime.
Figure 9: Example addMonths expression
Create a string concept, ‘Start Point ‘and a date concept, ‘Date Concept’, connected with a relationship, ‘start date’:
Figure 10: Date concept ‘date concept’ linked to ‘start point’ string concept with the relationship ‘start date’
Next, create a second relationship between the ‘start point’ and ‘date concept’ concepts, called ‘add nine months’. The main rule for the calculation will sit on the ‘day before yesterday’ relationship
The rule is made up of two components: one condition, and one expression.
The condition, ‘%S start date %MONTHS’ assigns the start date the end-user inputs to the variable %MONTHS. The %MONTHS value will be the value used in the expression.
Now, we can create the ‘addWeeks’ expression. As the expression will add nine months to the %MONTHS value (the start date entered by the user), the expression will be ‘addMonths(%MONTHS, 9)‘. You will need to assign the variable of the expression to %O, so that Rainbird will display the sum of the expression as the outcome of the query.
Figure 12: Building the addMonths(%MONTHS, 9) rule.
Note: When writing an expression, you will need to leave a space between the apostrophe in the brackets and the number that will be added/subtracted to/from the variable
Now we can run the query. If we enter, for example, 4th January, 2007 (2007-01-04), the addMonths(%MONTHS, 9) function would return the result ‘4th October, 2007’:
Figure 13: Outcome of addMonths(%MONTHS, 9) query when 4th January 2007 is the input date
When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the addMonths function, please run the query on the ‘add 9 months’ relationship.
addYears(): Rainbird uses the addYears() function to add or subtract a number of years to or from a date entered at runtime or a date that exists as an instance within the knowledge map the function is being used in.
The next couple of tabs will demonstrate how to create a map that will use an addYears function to add ten years to a date entered at runtime.
Figure 14: Example of an addYears expression that would add 10 years to a value, %YEARS
Create a string concept, ‘Start Point ‘and a date concept, ‘Date Concept’, connected with a relationship, ‘start date’:
Figure 15: Date concept ‘date concept’ linked to ‘start point’ string concept with the relationship ‘start date’
Next, create a second relationship between the ‘start point’ and ‘date concept’ concepts, called ‘add 10 weeks’. The main rule for the calculation will sit on the ‘day before yesterday’ relationship
The rule is made up of two components: one condition, and one expression.
The condition, ‘%S start date %YEARS’ assigns the start date the end-user inputs to the variable %YEARS. The %YEARS value will be the value used in the expression.
Now, we can create the ‘addYEARS’ expression. As the expression will add two weeks to the %YEARS value (the start date entered by the user), the expression will be ‘addYEARS(%YEARS, 10)‘. You will need to assign the variable of the expression to %O, so that Rainbird will display the sum of the expression as the outcome of the query.
Figure 16: Building the addYEARS(%YEARS, 10) rule
Note: When writing an expression, you will need to leave a space between the apostrophe in the brackets and the number that will be added/subtracted to/from the variable
Now we can run the query. If we enter, for example, 4th January, 2007 (2007-01-04), the addYears(%YEARS 10) function would return the result ‘4th January, 2017’:
Figure 17: Outcome of addYears(%YEARS, 10) query when 4th January 2007 is the input date
When viewing the map generated by the RBLang at the bottom of the article, for a demonstration of the addYears function, please run the query on the ‘add 10 years‘ relationship.
IMPORTANT: Date instances should be formatted as ‘YYYY-MM-DD’.
The RBLang below will generate the a map that uses the different expressions mentioned in the article. Click on ‘Export .rbird’ to download the knowledge map, or ‘copy RBLang’ and paste the code directly into Rainbird.
Query and Results
Each function used in the article has a separate relationship between the ‘start point’ and ‘date concept’ concepts that needs to be run to get an example of the function in action.