|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Date and Time Calculation > DTO. - Date Time Operations > Date & Time Calculations |
MiniRobotLanguage (MRL)
DTO.IsLeapYear Command
Check if a Year is a Leap Year
Intention
The DTO.IsLeapYear command provides a simple way to determine if a given year is a leap year. A leap year occurs every four years to keep the calendar year synchronized with the astronomical year and has 366 days, with the extra day being February 29th.
This command returns a boolean result (1 for true, 0 for false), which is ideal for use in conditional logic, for example, to validate dates or perform calculations that depend on the number of days in a year.
Syntax
DTO.IsLeapYear|date|[format]|[$$RES]
Parameter Explanation
date - The date string to check. The year from this date will be evaluated. This can be a variable or a literal string.
format - (Optional) A string that specifies the format of the input `date` (e.g., "YYYY-MM-DD"). If omitted, the default format ("DD.MM.YYYY") is assumed.
$$RES - (Optional) The variable to store the result. Receives `1` if it is a leap year, and `0` otherwise.
Example
'**********************************************
' DTO.IsLeapYear - Sample
'**********************************************
'
' Define a date in a known leap year (2024).
$$DAA = "15.08.2024"
' Check if the year in $$DAA is a leap year.
DTO.IsLeapYear|$$DAA||$$RSL
' Check if the result in $$RSL is 1.
IFV.$$RSL|= |1
MBX.The year 2024 is a leap year.
EIF.
'
' Define a date in a non-leap year (2023) with a custom format.
$$DAB = "2023/03/10"
$$FMT = "YYYY/MM/DD"
' Check again, providing the custom format mask.
DTO.IsLeapYear|$$DAB|$$FMT|$$RSL
' Check if the result is 0.
IFV.$$RSL|= |0
MBX.The year 2023 is not a leap year.
EIF.
ENR.
Remarks
The command correctly identifies leap years based on the standard algorithm (a year is a leap year if it is divisible by 4, except for end-of-century years, which must be divisible by 400).
Limitations:
The command relies on a valid date string. Providing an invalid date may lead to a parameter error or an unpredictable result.
See also:
• DAT. - Date and Time Information (System independent)
• DTC. - Date and Time Calculation