;dev: lookupDayPartition -> dayPartitionFind
This commit is contained in:
parent
2e78a53931
commit
70e9e7b060
@ -15,7 +15,7 @@ module Hledger.Data.DayPartition
|
|||||||
-- * operations
|
-- * operations
|
||||||
, unionDayPartitions
|
, unionDayPartitions
|
||||||
, dayPartitionStartEnd
|
, dayPartitionStartEnd
|
||||||
, lookupDayPartition
|
, dayPartitionFind
|
||||||
, splitSpan
|
, splitSpan
|
||||||
, intervalBoundaryBefore
|
, intervalBoundaryBefore
|
||||||
-- * tests
|
-- * tests
|
||||||
@ -130,12 +130,12 @@ dayPartitionStartEnd (DayPartition (PeriodData _ ds)) =
|
|||||||
-- Guaranteed not to error because the IntMap is non-empty.
|
-- Guaranteed not to error because the IntMap is non-empty.
|
||||||
(intToDay . fst $ IM.findMin ds, snd $ IM.findMax ds)
|
(intToDay . fst $ IM.findMin ds, snd $ IM.findMax ds)
|
||||||
|
|
||||||
lookupDayPartition :: Day -> DayPartition -> (Maybe Day, Day)
|
|
||||||
lookupDayPartition d (DayPartition xs) = lookupPeriodDataOrHistorical d xs
|
|
||||||
-- | Find the start and end dates of the period within a 'DayPartition' which contains a given day.
|
-- | Find the start and end dates of the period within a 'DayPartition' which contains a given day.
|
||||||
-- If the day is after the end of the last period, it is assumed to be within the last period.
|
-- If the day is after the end of the last period, it is assumed to be within the last period.
|
||||||
-- If the day is before the start of the first period (ie, in the historical period),
|
-- If the day is before the start of the first period (ie, in the historical period),
|
||||||
-- only the historical period's end date is returned.
|
-- only the historical period's end date is returned.
|
||||||
|
dayPartitionFind :: Day -> DayPartition -> (Maybe Day, Day)
|
||||||
|
dayPartitionFind d (DayPartition xs) = lookupPeriodDataOrHistorical d xs
|
||||||
|
|
||||||
-- | Split a 'DateSpan' into a 'DayPartition' consisting of consecutive exact
|
-- | Split a 'DateSpan' into a 'DayPartition' consisting of consecutive exact
|
||||||
-- spans of the specified Interval, or `Nothing` if the span is invalid.
|
-- spans of the specified Interval, or `Nothing` if the span is invalid.
|
||||||
|
|||||||
@ -295,7 +295,7 @@ calculateReportAccount rspec@ReportSpec{_rsReportOpts=ropts} j priceoracle (Just
|
|||||||
mapPeriodData (padPeriodData mempty (dayPartitionToPeriodData colspans)) $
|
mapPeriodData (padPeriodData mempty (dayPartitionToPeriodData colspans)) $
|
||||||
accountFromPostings getIntervalStartDate ps
|
accountFromPostings getIntervalStartDate ps
|
||||||
|
|
||||||
getIntervalStartDate p = fst $ lookupDayPartition (getPostingDate p) colspans
|
getIntervalStartDate p = fst $ dayPartitionFind (getPostingDate p) colspans
|
||||||
getPostingDate = postingDateOrDate2 (whichDate (_rsReportOpts rspec))
|
getPostingDate = postingDateOrDate2 (whichDate (_rsReportOpts rspec))
|
||||||
|
|
||||||
-- | The valuation function to use for the chosen report options.
|
-- | The valuation function to use for the chosen report options.
|
||||||
|
|||||||
@ -674,7 +674,7 @@ journalApplyValuationFromOptsWith rspec@ReportSpec{_rsReportOpts=ropts} j priceo
|
|||||||
where
|
where
|
||||||
postingPeriodEnd d = fromMaybe err $ case interval_ ropts of
|
postingPeriodEnd d = fromMaybe err $ case interval_ ropts of
|
||||||
NoInterval -> fmap (snd . dayPartitionStartEnd) . snd $ reportSpan j rspec
|
NoInterval -> fmap (snd . dayPartitionStartEnd) . snd $ reportSpan j rspec
|
||||||
_ -> fmap (snd . lookupDayPartition d) . snd $ reportSpanBothDates j rspec
|
_ -> fmap (snd . dayPartitionFind d) . snd $ reportSpanBothDates j rspec
|
||||||
-- Should never happen, because there are only invalid dayPartitions
|
-- Should never happen, because there are only invalid dayPartitions
|
||||||
-- when there are no transactions, in which case this function is never called
|
-- when there are no transactions, in which case this function is never called
|
||||||
err = error' "journalApplyValuationFromOpts: expected all spans to have an end date"
|
err = error' "journalApplyValuationFromOpts: expected all spans to have an end date"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user