-
-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
date:-5/1 not including forecasted transaction on last day of April #1538
Comments
Specifying the period using
|
Thanks for the report. It does look a bit odd. More info:
Related code: hledger:Hledger.Cli.Utils.journalAddForecast |
Thanks for the pointers. In case it helps, here's the diff of that debug output between using --- with-date.debug 2021-04-22 12:36:31.319139142 -0700
+++ with-forecast.debug 2021-04-22 12:36:16.002403999 -0700
@@ -1,15 +1,14 @@
-requestedspan: DateSpan .. 2021 - 04 - 30
-forecastspan flag: Just DateSpan ..
+requestedspan: DateSpan ..
+forecastspan flag: Just DateSpan .. 2021 - 04 - 30
journalEndDate: Nothing
forecastbeginDefault: 2021 - 04 - 22
-specifieddates: Just 2021 - 04 - 30
-forecastendDefault: 2021 - 04 - 30
-forecastspan: DateSpan 2021 - 04 - 22. . 2021 - 04 - 29
+forecastspan: DateSpan 2021 - 04 - 22. . 2021 - 04 - 30
alltxnspans:
[ DateSpan 2021 - 04 - 16. . 2021 - 04 - 22
, DateSpan 2021 - 04 - 23. . 2021 - 04 - 29
+ , DateSpan 2021 - 04 - 30. . 2021 - 05 - 06
]
-journalspan: DateSpan 2021 - 04 - 23
+journalspan: DateSpan 2021 - 04 - 23. . 2021 - 04 - 30
pricespan: DateSpan ..
requestedspan': DateSpan 2021 - 04 - 23. . 2021 - 04 - 30
intervalspans: [ DateSpan 2021 - 04 - 23. . 2021 - 04 - 30 ] |
I can't seem to find the reason for that |
Or not.. |
reportPeriodLastDay = fmap (addDays (-1)) . queryEndDate False . rsQuery
I can't seem to find the reason for that -1
From what I can remember, it was an intentional slight deviation from the usual "exclusive end date" rule, that seemed necessary for intuitive behaviour / display in this case.
|
Sounds like 2 different end-exclusivity mechanisms adding up on each other. One is the one I quoted and the other I guess is a general treatment of Since other code might be counting on diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs
index 404898a9e..95989f13f 100644
--- a/hledger/Hledger/Cli/Utils.hs
+++ b/hledger/Hledger/Cli/Utils.hs
@@ -59,6 +59,7 @@ import Hledger.Data
import Hledger.Read
import Hledger.Reports
import Hledger.Utils
+import Hledger.Query (queryEndDate)
import Control.Monad (when)
-- | Standard error message for a bad output format specified with -O/-o.
@@ -133,7 +134,7 @@ journalAddForecast CliOpts{inputopts_=iopts, reportspec_=rspec} j =
forecastbeginDefault = dbg2 "forecastbeginDefault" $ fromMaybe today mjournalend
-- "They end on or before the specified report end date, or 180 days from today if unspecified."
- mspecifiedend = dbg2 "specifieddates" $ reportPeriodLastDay rspec
+ mspecifiedend = dbg2 "specifieddates" $ queryEndDate False $ rsQuery rspec
forecastendDefault = dbg2 "forecastendDefault" $ fromMaybe (addDays 180 today) mspecifiedend
forecastspan = dbg2 "forecastspan" $ I don't know if this would be an acceptable fix for you. If it is, would you like me to submit this as a PR? |
@jolmg thanks! I'd like to understand the problem and the larger impact of such a change in detail. It will take me a while to make time for it unfortunately. If you want to experiment and run tests, you are welcome to. |
The ‘shift the end day back by one’ requirement is very error-prone. My inclination would be to change the way |
Just to clarify my proposal with the diff above first, the bug can be seen almost completely with this excerpt: mspecifiedend = dbg2 "specifieddates" $ reportPeriodLastDay rspec
forecastendDefault = dbg2 "forecastendDefault" $ fromMaybe (addDays 180 today) mspecifiedend
forecastspan = dbg2 "forecastspan" $
spanDefaultsFrom
(fromMaybe nulldatespan $ dbg2 "forecastspan flag" $ forecast_ ropts)
(DateSpan (Just forecastbeginDefault) (Just forecastendDefault))
Given that Also, neither Getting back to sharing thoughts on your proposal, correct me if I'm wrong, but I'm understanding you're proposing creating something like this: mkDateSpan :: Maybe Day -> Maybe Day -> DateSpan
mkDateSpan b e = DateSpan b $ addDays (-1) <$> e , replacing all uses of the I don't think that would eliminate the need to sometimes shift end-dates. Some code will want to work with inclusive end-dates and other code with exclusive end-dates. This example has an inclusive end-date (that it's turning into an exclusive one): DateSpan (Just $ minimum dates) (Just $ addDays 1 $ maximum dates) DateSpan (minimumMay dates) (addDays 1 <$> maximumMay dates) This one has an exclusive end-date: beforestartq = dbg3 "beforestartq" $ dateqtype $ DateSpan Nothing mstart valuedStart = avalue (DateSpan Nothing historicalDate) startingBalance
...
historicalDate = minimumMay $ mapMaybe spanStart colspans
At most, you shift the decision from either using or not using Also, between having the |
I've realized that making a written test for this is easier than I initially thought: diff --git a/hledger/test/forecast.test b/hledger/test/forecast.test
index cf2e3c071..635b9a907 100644
--- a/hledger/test/forecast.test
+++ b/hledger/test/forecast.test
@@ -218,3 +218,18 @@ commodity 1,000.00 USD
2020-01-28 (a) 1,000.00 USD 2,000.00 USD
>>>2
>>>=0
+
+# 11. End-date provided to date: includes the day before it like with --forecast=
+hledger -f - reg --forecast date:-20200103
+<<<
+2020-01-01
+ (a) 1.00 USD
+
+~ every day
+ (a) 1.00 USD
+
+>>>
+2020-01-01 (a) 1.00 USD 1.00 USD
+2020-01-02 (a) 1.00 USD 2.00 USD
+>>>2
+>>>=0 The test fails on master right now and succeeds after applying the provided patch. No other test fails. |
You might also have thoughts on #1648. |
Yes, I believe we can close this. |
How to reproduce
Expected
The 2021-04-30 entry to appear when querying
date:-5/1
.Further notes
balance
.every 30th day
.Platform
hledger: 1.21
OS: Archlinux
The text was updated successfully, but these errors were encountered: