Logo

Programming-Idioms

  • Python
  • Rust
  • Ruby

Idiom #342 Leap year?

Determine if the current year is a leap year.

import calendar
import datetime
if calendar.isleap(datetime.date.today().year):
    print('This year is a leap year.')
y % 4 == 0 and (y % 100 != 0 or y % 400 == 0)
from datetime import date
from calendar import isleap
y = date.today().year
isleap(y)
let leap_year = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
require 'date'
Date.leap?( Date.today.year )
final thisYear = DateTime.now().year;
final isLeap = DateTime(year, 2, 29).month == 2;

2, 29 will become 3, 1 in non-leap years.

New implementation...
< >
steenslag