lib: spanStartYear, spanEndYear, spanYears DateSpan helpers

This commit is contained in:
Simon Michael 2020-07-09 12:52:40 -07:00
parent a89a4e1b42
commit 4b9a76068f

View File

@ -57,6 +57,9 @@ module Hledger.Data.Dates (
isDateSepChar,
spanStart,
spanEnd,
spanStartYear,
spanEndYear,
spanYears,
spansSpan,
spanIntersect,
spansIntersect,
@ -149,6 +152,16 @@ spanStart (DateSpan d _) = d
spanEnd :: DateSpan -> Maybe Day
spanEnd (DateSpan _ d) = d
spanStartYear :: DateSpan -> Maybe Year
spanStartYear (DateSpan d _) = fmap (first3 . toGregorian) d
spanEndYear :: DateSpan -> Maybe Year
spanEndYear (DateSpan d _) = fmap (first3 . toGregorian) d
-- | Get the 0-2 years mentioned explicitly in a DateSpan.
spanYears :: DateSpan -> [Year]
spanYears (DateSpan ma mb) = mapMaybe (fmap (first3 . toGregorian)) [ma,mb]
-- might be useful later: http://en.wikipedia.org/wiki/Allen%27s_interval_algebra
-- | Get overall span enclosing multiple sequentially ordered spans.