mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-09 21:22:26 +03:00
lib: type signatures
This commit is contained in:
parent
39aed387e9
commit
da8047d286
@ -545,6 +545,7 @@ startofyear day = fromGregorian y 1 1 where (y,_,_) = toGregorian day
|
||||
-- 2016-12-31
|
||||
-- >>> nthdayofyearcontaining 1 1 wed22nd
|
||||
-- 2017-01-01
|
||||
nthdayofyearcontaining :: Month -> MonthDay -> Day -> Day
|
||||
nthdayofyearcontaining m n d | mmddOfSameYear <= d = mmddOfSameYear
|
||||
| otherwise = mmddOfPrevYear
|
||||
where mmddOfSameYear = addDays (fromIntegral n-1) $ applyN (m-1) nextmonth s
|
||||
@ -568,6 +569,7 @@ nthdayofyearcontaining m n d | mmddOfSameYear <= d = mmddOfSameYear
|
||||
-- 2017-10-23
|
||||
-- >>> nthdayofmonthcontaining 30 wed22nd
|
||||
-- 2017-10-30
|
||||
nthdayofmonthcontaining :: MonthDay -> Day -> Day
|
||||
nthdayofmonthcontaining n d | nthOfSameMonth <= d = nthOfSameMonth
|
||||
| otherwise = nthOfPrevMonth
|
||||
where nthOfSameMonth = nthdayofmonth n s
|
||||
@ -591,6 +593,7 @@ nthdayofmonthcontaining n d | nthOfSameMonth <= d = nthOfSameMonth
|
||||
-- 2017-11-16
|
||||
-- >>> nthdayofweekcontaining 5 wed22nd
|
||||
-- 2017-11-17
|
||||
nthdayofweekcontaining :: WeekDay -> Day -> Day
|
||||
nthdayofweekcontaining n d | nthOfSameWeek <= d = nthOfSameWeek
|
||||
| otherwise = nthOfPrevWeek
|
||||
where nthOfSameWeek = addDays (fromIntegral n-1) s
|
||||
@ -614,12 +617,14 @@ nthdayofweekcontaining n d | nthOfSameWeek <= d = nthOfSameWeek
|
||||
-- 2017-10-26
|
||||
-- >>> nthweekdayofmonthcontaining 4 5 wed22nd
|
||||
-- 2017-10-27
|
||||
nthweekdayofmonthcontaining :: Int -> WeekDay -> Day -> Day
|
||||
nthweekdayofmonthcontaining n wd d | nthWeekdaySameMonth <= d = nthWeekdaySameMonth
|
||||
| otherwise = nthWeekdayPrevMonth
|
||||
where nthWeekdaySameMonth = advancetonthweekday n wd $ startofmonth d
|
||||
nthWeekdayPrevMonth = advancetonthweekday n wd $ prevmonth d
|
||||
|
||||
|
||||
-- | Advance to nth weekday wd after given start day s
|
||||
advancetonthweekday :: Int -> WeekDay -> Day -> Day
|
||||
advancetonthweekday n wd s = addWeeks (n-1) . firstMatch (>=s) . iterate (addWeeks 1) $ firstweekday s
|
||||
where
|
||||
addWeeks k = addDays (7 * fromIntegral k)
|
||||
|
Loading…
Reference in New Issue
Block a user