Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-time/src/windows/calendar.rs
6939 views
1
pub(crate) const DAYS_PER_MONTH: [[i64; 12]; 2] = [
2
//J F M A M J J A S O N D
3
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], // non-leap year
4
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], // leap year
5
];
6
7
pub(crate) const fn is_leap_year(year: i32) -> bool {
8
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
9
}
10
11
/// Get the number of days in the given month of the given year
12
pub(crate) const fn days_in_month(year: i32, month: u8) -> u8 {
13
DAYS_PER_MONTH[is_leap_year(year) as usize][(month - 1) as usize] as u8
14
}
15
16
/// nanoseconds per unit
17
pub const NS_MICROSECOND: i64 = 1_000;
18
pub const NS_MILLISECOND: i64 = 1_000_000;
19
pub const NS_SECOND: i64 = 1_000_000_000;
20
pub const NS_MINUTE: i64 = 60 * NS_SECOND;
21
pub const NS_HOUR: i64 = 60 * NS_MINUTE;
22
pub const NS_DAY: i64 = 24 * NS_HOUR;
23
pub const NS_WEEK: i64 = 7 * NS_DAY;
24
25