diff --git a/hledger-lib/Hledger/Data/AutoTransaction.hs b/hledger-lib/Hledger/Data/AutoTransaction.hs index 4cc903005..87d5de4e1 100644 --- a/hledger-lib/Hledger/Data/AutoTransaction.hs +++ b/hledger-lib/Hledger/Data/AutoTransaction.hs @@ -147,7 +147,69 @@ renderPostingCommentDates p = p { pcomment = comment' } -- 2017/03/01 -- hi $1.00 -- --- >>> gen "every Nov 29th from 2017 to 2019" +-- >>> gen "monthly from 2017/1 to 2017/5" +-- 2017/01/01 +-- hi $1.00 +-- +-- 2017/02/01 +-- hi $1.00 +-- +-- 2017/03/01 +-- hi $1.00 +-- +-- 2017/04/01 +-- hi $1.00 +-- +-- >>> gen "every 2nd day of month from 2017/02 to 2017/04" +-- 2017/01/02 +-- hi $1.00 +-- +-- 2017/02/02 +-- hi $1.00 +-- +-- 2017/03/02 +-- hi $1.00 +-- +-- >>> gen "monthly from 2017/1 to 2017/4" +-- 2017/01/01 +-- hi $1.00 +-- +-- 2017/02/01 +-- hi $1.00 +-- +-- 2017/03/01 +-- hi $1.00 +-- +-- >>> gen "every 30th day of month from 2017/1 to 2017/5" +-- 2016/12/30 +-- hi $1.00 +-- +-- 2017/01/30 +-- hi $1.00 +-- +-- 2017/02/28 +-- hi $1.00 +-- +-- 2017/03/30 +-- hi $1.00 +-- +-- 2017/04/30 +-- hi $1.00 +-- +-- >>> gen "every 2nd Thursday of month from 2017/1 to 2017/4" +-- 2016/12/08 +-- hi $1.00 +-- +-- 2017/01/12 +-- hi $1.00 +-- +-- 2017/02/09 +-- hi $1.00 +-- +-- 2017/03/09 +-- hi $1.00 +-- +-- >>> gen "every nov 29th from 2017 to 2019" -- 2016/11/29 -- hi $1.00 -- diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 8e6c29d19..14500963a 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -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