Add isIsoLeapYear variable and fix iyl documentation

This commit is contained in:
Joscha 2021-12-19 15:17:59 +01:00
parent 35ed5804f3
commit af9dd0819d
5 changed files with 10 additions and 2 deletions

View file

@ -43,6 +43,7 @@ pub enum Var {
IsWeekday,
IsWeekend,
IsLeapYear,
IsIsoLeapYear,
}
impl Var {
@ -97,6 +98,7 @@ impl Var {
b2i(wd.is_weekend())
}
Var::IsLeapYear => b2i(util::is_leap_year(date.year())),
Var::IsIsoLeapYear => b2i(util::is_iso_leap_year(date.year())),
})
}
}
@ -162,6 +164,7 @@ impl From<&Spanned<commands::Expr>> for Expr {
commands::Var::IsWeekday => Self::Var(Var::IsWeekday),
commands::Var::IsWeekend => Self::Var(Var::IsWeekend),
commands::Var::IsLeapYear => Self::Var(Var::IsLeapYear),
commands::Var::IsIsoLeapYear => Self::Var(Var::IsIsoLeapYear),
},
commands::Expr::Paren(i) => i.as_ref().into(),
commands::Expr::Neg(i) => Self::Neg(conv(i)),

View file

@ -19,6 +19,7 @@ pub fn month_length(year: i32, month: u32) -> u32 {
.day()
}
// Length of an ISO week year in days.
pub fn iso_year_length(year: i32) -> u32 {
if is_iso_leap_year(year) {
53 * 7