Is Leap Year
Checks whether the year in a given date is a leap year. This node is useful for date validation, calendar calculations, and handling February 29th date operations in automation workflows.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Input
- Time - The date/time value to check. Must be formatted according to the Layout option. Only the year component is used for the leap year determination.
Output
- Is Leap - Boolean value indicating whether the year is a leap year:
true- The year is a leap year (366 days, includes February 29)false- The year is not a leap year (365 days)
Options
- Layout - The date/time format of the input time. Options include:
- ANSIC -
Mon Jan 2 15:04:05 2006 - UnixDate -
Mon Jan 2 15:04:05 MST 2006 - RubyDate -
Mon Jan 02 15:04:05 -0700 2006 - RFC822 -
02 Jan 06 15:04 MST - RFC822Z -
02 Jan 06 15:04 -0700 - RFC850 -
Monday, 02-Jan-06 15:04:05 MST - RFC1123 -
Mon, 02 Jan 2006 15:04:05 MST - RFC1123Z -
Mon, 02 Jan 2006 15:04:05 -0700 - RFC3339 -
2006-01-02T15:04:05-07:00(default, ISO 8601) - RFC3339Nano -
2006-01-02T15:04:05.000000000-07:00 - Custom - Define a custom format
- ANSIC -
How It Works
The Is Leap Year node determines if a year is a leap year using the standard calendar rules:
A year is a leap year if:
- It is divisible by 4, AND
- Either:
- It is NOT divisible by 100, OR
- It IS divisible by 400
Examples:
- 2024 is a leap year (divisible by 4, not by 100)
- 2000 is a leap year (divisible by 400)
- 1900 is NOT a leap year (divisible by 100 but not by 400)
- 2023 is NOT a leap year (not divisible by 4)
Leap Year Rules
Why do we have leap years?
- A solar year is approximately 365.24219 days
- Without leap years, calendars would drift out of sync with seasons
- Adding a day every 4 years corrects most of the drift
- The 100/400 year exception fine-tunes the correction
Century years:
- Most century years (1700, 1800, 1900) are NOT leap years
- Exception: Century years divisible by 400 (1600, 2000, 2400) ARE leap years
- This rule keeps the calendar accurate over long periods
Use Cases
Date Validation
- Validate February 29 dates
- Ensure date ranges don't include invalid dates
- Check if a specific date is valid
Calendar Operations
- Calculate the correct number of days in February
- Determine total days in a year
- Generate accurate date sequences
Anniversary Calculations
- Handle birthdays on February 29
- Calculate recurring dates
- Determine age accurately
Data Processing
- Filter leap year records
- Group data by leap/non-leap years
- Validate imported date data
Examples
Example 1: Check 2024 (Leap Year)
Time: 2024-01-15T10:00:00Z
Layout: RFC3339
Output: true
2024 is divisible by 4 and not by 100, so it's a leap year.
Example 2: Check 2023 (Not a Leap Year)
Time: 2023-06-20T10:00:00Z
Layout: RFC3339
Output: false
2023 is not divisible by 4, so it's not a leap year.
Example 3: Check 2000 (Leap Year - Century Exception)
Time: 2000-12-31T23:59:59Z
Layout: RFC3339
Output: true
2000 is divisible by 400, so it's a leap year despite being a century year.
Example 4: Check 1900 (Not a Leap Year - Century Rule)
Time: 1900-03-15T10:00:00Z
Layout: RFC3339
Output: false
1900 is divisible by 100 but not by 400, so it's not a leap year.
Example 5: Any Date in a Year
Time: 2024-08-25T14:30:00Z
Layout: RFC3339
Output: true
Only the year (2024) is checked; the month and day don't matter.
Pattern of Leap Years
Recent and upcoming leap years:
- 2016 ✓
- 2020 ✓
- 2024 ✓
- 2028 ✓
- 2032 ✓
- 2100 ✗ (century year, not divisible by 400)
Century leap years:
- 1600 ✓
- 2000 ✓
- 2400 ✓
Workflow Examples
Example 1: Validate February 29 Date
- Get date input from user
- Use Split Date to extract month and day
- If month = 2 and day = 29:
- Use Is Leap Year node
- If false: Show error "Invalid date: February 29 doesn't exist in this year"
Example 2: Calculate Days in February
- Get year from date
- Use Is Leap Year node
- If true:
daysInFebruary = 29 - If false:
daysInFebruary = 28
Example 3: Handle Leap Day Birthdays
// User born on Feb 29
var birthdate = "2000-02-29";
// Get current year
// Check if current year is leap year
if (msg.leap) {
// Celebrate on Feb 29
msg.celebrationDate = currentYear + "-02-29";
} else {
// Celebrate on Feb 28 or Mar 1
msg.celebrationDate = currentYear + "-02-28";
}
Example 4: Calculate Total Days in Year
- Get date containing the year to check
- Use Is Leap Year node
- If true:
totalDays = 366 - If false:
totalDays = 365 - Use for year-based calculations
Example 5: Filter Leap Year Records
- Retrieve records with dates
- For each record:
- Use Is Leap Year node
- If true: Add to leap year collection
- Process leap year records separately
Using with Conditional Logic
JavaScript Example:
// After Is Leap Year node
if (msg.leap) {
msg.februaryDays = 29;
msg.yearDays = 366;
msg.message = "This is a leap year";
} else {
msg.februaryDays = 28;
msg.yearDays = 365;
msg.message = "This is not a leap year";
}
If Node Example:
Condition: msg.leap === true
Then: Route to leap year processing
Else: Route to regular year processing
Tips for Effective Use
- Any Date Works - You can provide any date from the year you want to check; only the year is examined
- Combine with Split Date - Use Split Date node to extract the year first, then check if it's a leap year
- February Validation - Always check for leap year when validating February dates
- Birthday Handling - For Feb 29 birthdays, decide whether to celebrate on Feb 28 or Mar 1 in non-leap years
- Data Validation - Use to validate imported data that includes February dates
- Year-Based Reports - Group or filter reports by leap/non-leap years for accurate day counts
- Future Planning - Check future years when scheduling multi-year operations
Common Errors and Solutions
Error: "failed to parse input time"
- Cause: Input time format doesn't match the Layout specification
- Solution: Ensure the input time is formatted according to the selected Layout
Error: "time is required"
- Cause: No value provided for the Time input
- Solution: Provide a valid date/time string in the Time input field
Incorrect result for century years
- Cause: Misunderstanding of century year rules
- Solution: Remember that years divisible by 100 are NOT leap years unless also divisible by 400
Date validation still failing
- Cause: Date validation logic incorrect for February 29
- Solution: Ensure you check both that the month is February AND that the year is a leap year
Important Notes
- The node only examines the year component; month, day, and time are ignored
- The leap year determination follows the Gregorian calendar rules
- The calculation is instant and deterministic for any year
- Historical dates before the Gregorian calendar adoption (1582) follow the same mathematical rules
- The node works correctly for years far in the past or future
- Leap seconds are NOT considered (this is about leap years, not leap seconds)
Fun Facts
- The Gregorian calendar is accurate to 1 day in 3,236 years
- February 29 occurs in approximately 97 of every 400 years
- People born on February 29 are called "leaplings" or "leapers"
- The chance of being born on February 29 is about 1 in 1,461
- Next non-leap century year will be 2100
Related Nodes
- Split Date - Extract the year from a date for checking
- Now - Get current date to check if current year is a leap year
- Add Time - Add years and handle leap year transitions
- Format Time - Parse dates in various formats before checking