devela/phys/time/calendar/mod.rs
1// devela::phys::time::calendar
2//
3//! Month and Weekday types.
4//
5
6mod month;
7mod weekday;
8
9pub use month::Month;
10pub use weekday::Weekday;
11
12/// Returns `true` if the provided `year` is a leap year.
13///
14/// A leap year occurs every four years to help synchronize the calendar year
15/// with the solar year or the length of time it takes the Earth to complete
16/// its orbit around the Sun, which is about 365.25 days. A year is
17/// considered a leap year if it is divisible by 4 but not by 100, or if it
18/// is divisible by 400.
19pub const fn is_leap_year(year: i32) -> bool {
20 // (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 // naive
21 let d = crate::iif![year % 100 != 0; 4; 16];
22 (year & (d - 1)) == 0
23}