FIX actually throw error when folding periods/days
This commit is contained in:
parent
092d771f30
commit
1555e9071f
|
@ -1,6 +1,7 @@
|
||||||
module Internal.Budget (insertBudget) where
|
module Internal.Budget (insertBudget) where
|
||||||
|
|
||||||
import Control.Monad.Except
|
import Control.Monad.Except
|
||||||
|
import Data.Foldable
|
||||||
import Database.Persist.Monad
|
import Database.Persist.Monad
|
||||||
import Internal.Database.Ops
|
import Internal.Database.Ops
|
||||||
import Internal.Types.Main
|
import Internal.Types.Main
|
||||||
|
@ -235,16 +236,20 @@ workingDays wds start end = fromIntegral $ daysFull + daysTail
|
||||||
wds' = L.sort $ (\x -> diff (fromWeekday x) startDay) <$> L.nub wds
|
wds' = L.sort $ (\x -> diff (fromWeekday x) startDay) <$> L.nub wds
|
||||||
diff a b = fromIntegral $ mod (fromEnum a - fromEnum b) 7
|
diff a b = fromIntegral $ mod (fromEnum a - fromEnum b) 7
|
||||||
|
|
||||||
|
-- ASSUME days is a sorted list
|
||||||
foldDays
|
foldDays
|
||||||
:: MonadInsertError m
|
:: MonadInsertError m
|
||||||
=> (Day -> Day -> m a)
|
=> (Day -> Day -> m a)
|
||||||
-> Day
|
-> Day
|
||||||
-> [Day]
|
-> [Day]
|
||||||
-> m [a]
|
-> m [a]
|
||||||
foldDays f start days
|
foldDays f start days = case NE.nonEmpty days of
|
||||||
-- TODO throw real error here
|
Nothing -> return []
|
||||||
| any (start >) days = throwError undefined
|
Just ds
|
||||||
| otherwise =
|
| any (start >) ds ->
|
||||||
|
throwError $
|
||||||
|
InsertException [PeriodError start $ minimum ds]
|
||||||
|
| otherwise ->
|
||||||
combineErrors $
|
combineErrors $
|
||||||
snd $
|
snd $
|
||||||
L.mapAccumL (\prevDay day -> (day, f prevDay day)) start days
|
L.mapAccumL (\prevDay day -> (day, f prevDay day)) start days
|
||||||
|
|
Loading…
Reference in New Issue