<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > Date & Time Calculations |
MiniRobotLanguage (MRL)
IDC. Conditional Statement
If Date Condition
Intention
Conditional Statement. Test multiple conditions about the current date or time.
You can test:
• if the current date is before or after a specified date.
• if the current time is before or after a specified time.
• if we have a specified date or time.
• if a specified year is a leap year
Let us start with this:
' Get Leap Years between 1997 and 2012
FOR.$$CNT|1997|2012
' This will do the magic
IDC.is_lj|$$CNT
DBP.$$CNT is a leap year!
EIF.
NEX.
ENR.
You can test if we have a given date:
: $$HRR=23.2.2012
IDC.date_equal|$$HRR
DBV.Yes, we have the $$HRR
ELS.
DBV.No, its not the $$HRR
EIF.
ENR.
You can test if a given number is the current year:
: $$CNT=2012
IDC.is_year|$$CNT
DBP.$$CNT is the current year!
EIF.
In the same way you can check the month, day, hour, minute, second.
If you need to check if the current date is before or after a given date, its as easy as before:
' This is the date, we check
: $$CNT=26.02.2012
' and this will do the magic
IDC.date_after|$$CNT
DBP.$$CNT is after current time!
EIF.
IDC.date_before|$$CNT
DBP.$$CNT is before current time!
EIF.
Note that you need to give a complete date with all parts, in the order DD-MM-YYYY for this to work. This is not the case when we do the same with times. With time we have more options. You can find out, if a given time is before or after the actual time (now).
When you specify a time, you can choose, what time you want to specify:
• the hour
• the hour and the Minute
• the hour and the minute and seconds
• the hour and the minute, seconds and milliseconds
This way you can check if its before or after 12 o'clock or you can check if its before or after 12:37:29. Just specify what you want to have. Generally the command looks like this:
: $$CNT=08:36
' check if time is yet to come
IDC.time_after|$$CNT
' Check for past time
IDC.time_before|$$CNT
' Check if time is now
IDC.time_equal|$$CNT
Here is an complete running example .
' Change the time (next line) to any time you want
: $$CNT=17:36:59
IDC.time_after|$$CNT
DBP.$$CNT is after current time!
EIF.
IDC.time_equal|$$CNT
DBP.$$CNT is current time!
EIF.
IDC.time_before|$$CNT
DBP.$$CNT is before current time!
EIF.
ENR.
IDC. can also be used to directly test components of date and time.
Let us start with the date. We want to know if its currently 2012.
: $$YEA=2012
IDC.is_year|$$YEA
DBV.Yes, we have $$YEA
ELS.
DBV.No, its not $$YEA
EIF.
ENR.
You can test in the same way the actual month or day, see examples below.
' Test the month
: $$MON=3
IDC.is_month|$$MON
DBV.Yes, we have $$MON
ELS.
DBV.No, its not $$MON
EIF.
ENR.
' Test the actual day, if its the 24 th
: $$DAY=24
IDC.is_day|$$DAY
DBV.Yes, we have $$DAY
ELS.
DBV.No, its not $$DAY
EIF.
ENR.
Also the same will work with time. You can test the hour or minutes or even the seconds.
In just the same way. Here is an example:
' Test if we have 19:xx o'clock
: $$HRR=19
IDC.is_hour|$$HRR
DBV.Yes, we have $$HRR
ELS.
DBV.No, its not $$HRR
EIF.
ENR.
Hint:
IDC. will internally verify the date- and the time format when you use the date_after,date_before,time_after,time_after
options. However the order of the parameters will not be touched. You need to specify all dates like this:DD-MM-YYYY and all times like this: HH:MM:SS or HH:MM:SS:MS .
Syntax
IDC.P1[|P2][,P3] … ELS. … EIF.
Parameter Explanation
P1 - prototype
Prototype can be omitted or any of:
- "is_leap_year" - test if the actual/specified year is a leap year or not.
- "is_year" - test if the given year matches the actual date (now).
- "is_month" - test if the given year matches the actual date (today).
- "is_day" - test if the given year matches the actual date (today).
- "is_hour" - test if the given number matches the actual time (now).
- "is_minute" - test if the number matches the actual time (now).
- "is_second" - test if the given number matches the actual time (now).
- "time_after" - test if specified time is after actual time.
- "time_before" - check if specified time is in the past
- "time_equal" - check if specified time is right now
- "date_after" - test if specified date is after actual date
- "date_before" - check if specified date is in the past
- "date_equal" - check if specified date is today
P2 - (optional) - The usage of P2 and P3 depends
on the prototype P1
Important:: If you specify a Year below 100, for example 23.02.12, the time-logic
will add 2000 to it. Therefore the 30.03.12 will be internally treated like
the 30.03.2012. We have made this addition, because we believe that the
chances that somebody wants to make calculations with the Year 0 are lower,
then the chance that somebody will forget the first two number for the
actual date. Here is an example:
' this date will be treated as 24.02.2012
: $$HRR=24.2.12
IDC.date_after|$$HRR
DBV.Yes, the $$HRR is in the future
ELS.
DBV.No, the $$HRR is not after today
EIF.
ENR.
Example
'***********************************
' IDC.-Sample (Leap Year)
'***********************************
'
' Get Leap Years between 1997 and 2012
FOR.$$CNT|1997|2012
IDC.is_lj|$$CNT
DBP.$$CNT is a leap year!
EIF.
NEX.
ENR.
'***********************************
' IDC.-Sample (time)
'***********************************
' Use a time from now in 30 seconds
: $$CNT=08:36:00
FOR.$$LOP|1|1000
IDC.time_after|$$CNT
DBP.$$CNT is after current time!
EIF.
IDC.time_before|$$CNT
DBP.$$CNT is before current time!
EIF.
PAU.0.5
NEX.
ENR.
'***********************************
' IDC.-Sample (Year)
'***********************************
: $$YEA=2012
IDC.is_year|$$YEA
DBV.Yes, we have $$YEA
ELS.
DBV.No, its not $$YEA
EIF.
ENR.
'***********************************
' IDC.-Sample (Month)
'***********************************
' Test the month
: $$MON=3
IDC.is_month|$$MON
DBV.Yes, we have $$MON
ELS.
DBV.No, its not $$MON
EIF.
ENR.
'***********************************
' IDC.-Sample (date is)
'***********************************
'
: $$HRR=23.2.2012
IDC.date_equal|$$HRR
DBV.Yes, we have the $$HRR
ELS.
DBV.No, its not the $$HRR
EIF.
ENR.
Remarks
-
Limitations:
-
See also:
• DTC. - Date and Time Calculation
• IDC. / NDC. - If Date Command
• CAL. - mathematical CALculation