From 1056bd626c62a51983c7c28ae330e39cb7796414 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 19 Dec 2021 03:40:16 +0100 Subject: [PATCH] Fix calculation of some formula variables --- example.today | 2 +- src/eval/command/formula.rs | 6 +++--- src/files/commands.rs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example.today b/example.today index bbd88d4..94da218 100644 --- a/example.today +++ b/example.today @@ -18,7 +18,7 @@ NOTE last of each month DATE (m = 1) -d NOTE Second sunday of each month -DATE (m = 1) +2sun +DATE (d = 1) +2sun DATE (wd = sun & mw = 2) NOTE Easter diff --git a/src/eval/command/formula.rs b/src/eval/command/formula.rs index 3eab921..7c68802 100644 --- a/src/eval/command/formula.rs +++ b/src/eval/command/formula.rs @@ -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(), diff --git a/src/files/commands.rs b/src/files/commands.rs index 0669877..2604171 100644 --- a/src/files/commands.rs +++ b/src/files/commands.rs @@ -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,