lib: more periodic transaction tests

Some of these demonstrate that runPeriodicTransaction could generate
transactions ouside of requested DateSpan. This happens because
runPeriodicTransaction uses splitSpan internally, and splitSpan always
generates dateSpans that fully cover original DateSpan, extending
beyound left/right boundary if necessary. This is ok if transactions
are generated for budgeting purpose, but during forecasting care should
be taken to check that all generated transactions are happening past
the end of the real journal.
This commit is contained in:
Dmitry Astapov 2017-11-24 22:44:10 +00:00
parent 0dfffed52c
commit 597e9c47c9
2 changed files with 67 additions and 4 deletions

View File

@ -147,7 +147,69 @@ renderPostingCommentDates p = p { pcomment = comment' }
-- 2017/03/01
-- hi $1.00
-- <BLANKLINE>
-- >>> gen "every Nov 29th from 2017 to 2019"
-- >>> gen "monthly from 2017/1 to 2017/5"
-- 2017/01/01
-- hi $1.00
-- <BLANKLINE>
-- 2017/02/01
-- hi $1.00
-- <BLANKLINE>
-- 2017/03/01
-- hi $1.00
-- <BLANKLINE>
-- 2017/04/01
-- hi $1.00
-- <BLANKLINE>
-- >>> gen "every 2nd day of month from 2017/02 to 2017/04"
-- 2017/01/02
-- hi $1.00
-- <BLANKLINE>
-- 2017/02/02
-- hi $1.00
-- <BLANKLINE>
-- 2017/03/02
-- hi $1.00
-- <BLANKLINE>
-- >>> gen "monthly from 2017/1 to 2017/4"
-- 2017/01/01
-- hi $1.00
-- <BLANKLINE>
-- 2017/02/01
-- hi $1.00
-- <BLANKLINE>
-- 2017/03/01
-- hi $1.00
-- <BLANKLINE>
-- >>> gen "every 30th day of month from 2017/1 to 2017/5"
-- 2016/12/30
-- hi $1.00
-- <BLANKLINE>
-- 2017/01/30
-- hi $1.00
-- <BLANKLINE>
-- 2017/02/28
-- hi $1.00
-- <BLANKLINE>
-- 2017/03/30
-- hi $1.00
-- <BLANKLINE>
-- 2017/04/30
-- hi $1.00
-- <BLANKLINE>
-- >>> gen "every 2nd Thursday of month from 2017/1 to 2017/4"
-- 2016/12/08
-- hi $1.00
-- <BLANKLINE>
-- 2017/01/12
-- hi $1.00
-- <BLANKLINE>
-- 2017/02/09
-- hi $1.00
-- <BLANKLINE>
-- 2017/03/09
-- hi $1.00
-- <BLANKLINE>
-- >>> gen "every nov 29th from 2017 to 2019"
-- 2016/11/29
-- hi $1.00
-- <BLANKLINE>

View File

@ -184,7 +184,7 @@ splitSpan (Weeks n) s = splitspan startofweek (applyN n nextweek) s
splitSpan (Months n) s = splitspan startofmonth (applyN n nextmonth) s
splitSpan (Quarters n) s = splitspan startofquarter (applyN n nextquarter) s
splitSpan (Years n) s = splitspan startofyear (applyN n nextyear) s
splitSpan (DayOfMonth n) s = splitspan (nthdayofmonthcontaining n) (applyN (n-1) nextday . nextmonth) s
splitSpan (DayOfMonth n) s = splitspan (nthdayofmonthcontaining n) (nthdayofmonth n . nextmonth) s
splitSpan (WeekdayOfMonth n wd) s = splitspan (nthweekdayofmonthcontaining n wd) (advancetonthweekday n wd . nextmonth) s
splitSpan (DayOfWeek n) s = splitspan (nthdayofweekcontaining n) (applyN (n-1) nextday . nextweek) s
splitSpan (DayOfYear m n) s= splitspan (nthdayofyearcontaining m n) (applyN (n-1) nextday . applyN (m-1) nextmonth . nextyear) s
@ -456,6 +456,7 @@ thismonth = startofmonth
prevmonth = startofmonth . addGregorianMonthsClip (-1)
nextmonth = startofmonth . addGregorianMonthsClip 1
startofmonth day = fromGregorian y m 1 where (y,m,_) = toGregorian day
nthdayofmonth d day = fromGregorian y m d where (y,m,_) = toGregorian day
thisquarter = startofquarter
prevquarter = startofquarter . addGregorianMonthsClip (-3)
@ -514,8 +515,8 @@ nthdayofyearcontaining m n d | mmddOfSameYear <= d = mmddOfSameYear
-- 2017-10-30
nthdayofmonthcontaining n d | nthOfSameMonth <= d = nthOfSameMonth
| otherwise = nthOfPrevMonth
where nthOfSameMonth = addDays (fromIntegral n-1) s
nthOfPrevMonth = addDays (fromIntegral n-1) $ prevmonth s
where nthOfSameMonth = nthdayofmonth n s
nthOfPrevMonth = nthdayofmonth n $ prevmonth s
s = startofmonth d
-- | For given date d find week-long interval that starts on nth day of week