Fix calculation of some formula variables

This commit is contained in:
Joscha 2021-12-19 03:40:16 +01:00
parent 45a1b403e0
commit 1056bd626c
3 changed files with 7 additions and 7 deletions

View file

@ -61,16 +61,16 @@ impl Var {
}
Var::Month => date.month().into(),
Var::MonthLength => util::month_length(date.year(), date.month()).into(),
Var::MonthWeek => (date.month0().div_euclid(7) + 1).into(),
Var::MonthWeek => (date.day0().div_euclid(7) + 1).into(),
Var::MonthWeekReverse => {
#[allow(non_snake_case)]
let mD = util::month_length(date.year(), date.month()) - date.month0();
let mD = util::month_length(date.year(), date.month()) - date.day();
(mD.div_euclid(7) + 1).into()
}
Var::Day => date.day().into(),
Var::DayReverse => {
let ml = util::month_length(date.year(), date.month());
(ml - date.month0()).into()
(ml - date.day0()).into()
}
Var::IsoYear => date.iso_week().year().into(),
Var::IsoYearLength => util::iso_year_length(date.iso_week().year()).into(),

View file

@ -131,17 +131,17 @@ pub enum Var {
MonthLength,
/// `mw`, 1 during the first 7 days of the month, 2 during the next etc.
///
/// Equal to `((md - 1) / 7) + 1`
/// Equal to `((d - 1) / 7) + 1`
MonthWeek,
/// `mW`, 1 during the last 7 days of the month, 2 during the previous etc.
///
/// Equal to `((mD - 1) / 7) + 1`
/// Equal to `((D - 1) / 7) + 1`
MonthWeekReverse,
/// `d`, day of the month
Day,
/// `D`, day of the month starting from the end
///
/// Equal to `ml - md + 1`
/// Equal to `ml - d + 1`
DayReverse,
/// `iy`, ISO 8601 year
IsoYear,