hledger-lib-1.3.2: Core data types, parsers and functionality for the hledger accounting tools

Hledger.Data.Period

Description

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

Synopsis

# Documentation

Convert Periods to DateSpans.

>>> periodAsDateSpan (MonthPeriod 2000 1) == DateSpan (Just $fromGregorian 2000 1 1) (Just$ fromGregorian 2000 2 1)
True


Convert DateSpans to Periods.

>>> dateSpanAsPeriod $DateSpan (Just$ fromGregorian 2000 1 1) (Just $fromGregorian 2000 2 1) MonthPeriod 2000 1  Convert PeriodBetweens to a more abstract period where possible. >>> simplifyPeriod$ PeriodBetween (fromGregorian 1 1 1) (fromGregorian 2 1 1)
YearPeriod 1
>>> simplifyPeriod $PeriodBetween (fromGregorian 2000 10 1) (fromGregorian 2001 1 1) QuarterPeriod 2000 4 >>> simplifyPeriod$ PeriodBetween (fromGregorian 2000 2 1) (fromGregorian 2000 3 1)
MonthPeriod 2000 2
>>> simplifyPeriod $PeriodBetween (fromGregorian 2016 7 25) (fromGregorian 2016 8 1) WeekPeriod 2016-07-25 >>> simplifyPeriod$ PeriodBetween (fromGregorian 2000 1 1) (fromGregorian 2000 1 2)
DayPeriod 2000-01-01
>>> simplifyPeriod $PeriodBetween (fromGregorian 2000 2 28) (fromGregorian 2000 3 1) PeriodBetween 2000-02-28 2000-03-01 >>> simplifyPeriod$ PeriodBetween (fromGregorian 2000 2 29) (fromGregorian 2000 3 1)
DayPeriod 2000-02-29
>>> simplifyPeriod \$ PeriodBetween (fromGregorian 2000 12 31) (fromGregorian 2001 1 1)
DayPeriod 2000-12-31


isLastDayOfMonth :: (Num a, Num a1, Eq a, Eq a1) => Integer -> a1 -> a -> Bool Source #

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.

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

>>> showPeriod (WeekPeriod (fromGregorian 2016 7 25))
"2016/07/25w30"


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

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

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.

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

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.

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.