Add isIsoLeapYear variable and fix iyl documentation
This commit is contained in:
parent
35ed5804f3
commit
af9dd0819d
5 changed files with 10 additions and 2 deletions
|
|
@ -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)),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ pub enum Var {
|
|||
DayReverse,
|
||||
/// `iy`, ISO 8601 year
|
||||
IsoYear,
|
||||
/// `iyl`, length of current ISO 8601 year **in weeks**
|
||||
/// `iyl`, length of current ISO 8601 year in days
|
||||
IsoYearLength,
|
||||
/// `iw`, ISO 8601 week
|
||||
IsoWeek,
|
||||
|
|
@ -159,6 +159,8 @@ pub enum Var {
|
|||
IsWeekend,
|
||||
/// `isLeapYear`, whether the current year is a leap year
|
||||
IsLeapYear,
|
||||
/// `isIsoLeapYear`, whether the current year is a long year in the ISO week system
|
||||
IsIsoLeapYear,
|
||||
}
|
||||
|
||||
impl Var {
|
||||
|
|
@ -197,6 +199,7 @@ impl Var {
|
|||
Var::IsWeekday => "isWeekday",
|
||||
Var::IsWeekend => "isWeekend",
|
||||
Var::IsLeapYear => "isLeapYear",
|
||||
Var::IsIsoLeapYear => "isIsoLeapYear",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ delta = {
|
|||
boolean = { "true" | "false" }
|
||||
variable = {
|
||||
"mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun"
|
||||
| "isWeekday" | "isWeekend" | "isLeapYear"
|
||||
| "isWeekday" | "isWeekend" | "isLeapYear" | "isIsoLeapYear"
|
||||
| "j"
|
||||
| "yl" | "yd" | "yD" | "yw" | "yW" | "y"
|
||||
| "ml" | "mw" | "mW" | "m"
|
||||
|
|
|
|||
|
|
@ -348,6 +348,7 @@ fn parse_variable(p: Pair<'_, Rule>) -> Var {
|
|||
"isWeekday" => Var::IsWeekday,
|
||||
"isWeekend" => Var::IsWeekend,
|
||||
"isLeapYear" => Var::IsLeapYear,
|
||||
"isIsoLeapYear" => Var::IsIsoLeapYear,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue