diff --git a/hledger/Hledger/Cli/Commands/Run.hs b/hledger/Hledger/Cli/Commands/Run.hs index f36d342b7..4fe780a13 100644 --- a/hledger/Hledger/Cli/Commands/Run.hs +++ b/hledger/Hledger/Cli/Commands/Run.hs @@ -43,7 +43,6 @@ import Hledger.Cli.DocFiles (runTldrForPage, runInfoForTopic, runManForTopic) import Hledger.Cli.Utils (journalTransform) import Text.Printf (printf) import System.Process (system) -import Data.Maybe (isJust) -- | Command line options for this command. runmode = hledgerCommandMode @@ -245,10 +244,19 @@ withJournalCached defaultJournalOverride cliopts cmd = do journal <- runExceptT $ if snd (splitReaderPrefix fp) == "-" then readStdin else readJournalFile iopts fp either error' (\j -> return (Map.insert (ioptsWithoutReportSpan,fp) j cache, j)) journal where - -- InputOptions contain reportspan_ that is used to calculare forecast period, + -- InputOptions contain reportspan_ that is used to calculate forecast period, -- that is used by journalFinalise to insert forecast transactions. - -- For the purposes of caching, we want to ignore this when --forecast is not given. - ioptsWithoutReportSpan = if isJust (forecast_ iopts) then iopts else iopts { reportspan_ = emptydatespan } + -- For the purposes of caching, we want to ignore it whenever + -- --forecast is not used, or when explicit dates are requested. + ioptsWithoutReportSpan = iopts{ reportspan_ = forecastreportspan } + where + forecastreportspan = case forecast_ iopts of + Nothing -> emptydatespan + -- This could be better if we had access to the journal (as we + -- could use 'forecastPeriod') or to the journal end date (as + -- forecast transactions are never generated before journal end + -- unless specifically requested). + Just forecastspan -> forecastspan `spanDefaultsFrom` reportspan_ iopts -- Read stdin, or if we read it alread, use a cache -- readStdin :: InputOpts -> ExceptT String IO Journal readStdin = do