HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulehledger-lib-1.52.4GHC2021

Hledger.Data.Period

Manipulate the time periods typically used for reports with Period, a richer abstraction than DateSpan. See also Types and Dates.

  • 23 values

Convert Periods to exact DateSpans.

Example1 expression
periodAsDateSpan (MonthPeriod 2000 1) == DateSpan (Just $ Flex $ fromGregorian 2000 1 1) (Just $ Flex $ fromGregorian 2000 2 1)True

Convert DateSpans to Periods.

Example1 expression
dateSpanAsPeriod $ DateSpan (Just $ Exact $ fromGregorian 2000 1 1) (Just $ Exact $ fromGregorian 2000 2 1)MonthPeriod 2000 1
valuesimplifyPeriod :: Period -> Period
#

Convert PeriodBetweens to a more abstract period where possible.

Example8 expressions
simplifyPeriod $ PeriodBetween (fromGregorian 1 1 1) (fromGregorian 2 1 1)YearPeriod 1simplifyPeriod $ PeriodBetween (fromGregorian 2000 10 1) (fromGregorian 2001 1 1)QuarterPeriod 2000 4simplifyPeriod $ PeriodBetween (fromGregorian 2000 2 1) (fromGregorian 2000 3 1)MonthPeriod 2000 2simplifyPeriod $ PeriodBetween (fromGregorian 2016 7 25) (fromGregorian 2016 8 1)WeekPeriod 2016-07-25simplifyPeriod $ PeriodBetween (fromGregorian 2000 1 1) (fromGregorian 2000 1 2)DayPeriod 2000-01-01simplifyPeriod $ PeriodBetween (fromGregorian 2000 2 28) (fromGregorian 2000 3 1)PeriodBetween 2000-02-28 2000-03-01simplifyPeriod $ PeriodBetween (fromGregorian 2000 2 29) (fromGregorian 2000 3 1)DayPeriod 2000-02-29simplifyPeriod $ PeriodBetween (fromGregorian 2000 12 31) (fromGregorian 2001 1 1)DayPeriod 2000-12-31
valueisStandardPeriod :: Period -> Bool
#

Is this period a "standard" period, referencing a particular day, week, month, quarter, or year ? Periods of other durations, or infinite duration, or not starting on a standard period boundary, are not.

valueshowPeriod :: Period -> Text
#

Render a period as a compact display string suitable for user output.

Example2 expressions
showPeriod (WeekPeriod (fromGregorian 2016 7 25))"2016-W30"showPeriod (WeekPeriod (fromGregorian 2024 12 30))"2025-W01"
valueshowPeriodAbbrev :: Period -> Text
#

Like showPeriod, but if it's a month or week period show an abbreviated form. >>> showPeriodAbbrev (WeekPeriod (fromGregorian 2016 7 25)) W30 >>> showPeriodAbbrev (WeekPeriod (fromGregorian 2024 12 30)) W01

valueperiodNext :: Period -> Period
#

Move a standard period to the following period of same duration. Non-standard periods are unaffected.

valueperiodPrevious :: Period -> Period
#

Move a standard period to the preceding period of same duration. Non-standard periods are unaffected.

valueperiodNextIn :: DateSpan -> Period -> Period
#

Move a standard period to the following period of same duration, staying within enclosing dates. Non-standard periods are unaffected.

Move a standard period to the preceding period of same duration, staying within enclosing dates. Non-standard periods are unaffected.

valueperiodMoveTo :: Day -> Period -> Period
#

Move a standard period stepwise so that it encloses the given date. Non-standard periods are unaffected.

valueperiodGrow :: Period -> Period
#

Enlarge a standard period to the next larger enclosing standard period, if there is one. Eg, a day becomes the enclosing week. A week becomes whichever month the week's thursday falls into. A year becomes all (unlimited). Non-standard periods (arbitrary dates, or open-ended) are unaffected.

valueperiodShrink :: Day -> Period -> Period
#

Shrink a period to the next smaller standard period inside it, choosing the subperiod which contains today's date if possible, otherwise the first subperiod. It goes like this: unbounded periods and nonstandard periods (between two arbitrary dates) -> current year -> current quarter if it's in selected year, otherwise first quarter of selected year -> current month if it's in selected quarter, otherwise first month of selected quarter -> current week if it's in selected month, otherwise first week of selected month -> today if it's in selected week, otherwise first day of selected week, unless that's in previous month, in which case first day of month containing selected week. Shrinking a day has no effect.