hledger-lib-0.16: Core data types, parsers and utilities for the hledger accounting tool.

Hledger.Data.Dates

Description

Date parsing and utilities for hledger.

For date and time values, we use the standard Day and UTCTime types.

A SmartDate is a date which may be partially-specified or relative. Eg 2008/12/31, but also 2008/12, 12/31, tomorrow, last week, next year. We represent these as a triple of strings like ("2008","12",""), ("","","tomorrow"), ("","last","week").

A DateSpan is the span of time between two specific calendar dates, or an open-ended span where one or both dates are unspecified. (A date span with both ends unspecified matches all dates.)

An Interval is ledger's "reporting interval" - weekly, monthly, quarterly, etc.

Synopsis

Documentation

getCurrentDay :: IO DaySource

Get the current local date.

getCurrentMonth :: IO IntSource

Get the current local month number.

getCurrentYear :: IO IntegerSource

Get the current local year.

splitSpan :: Interval -> DateSpan -> [DateSpan]Source

Split a DateSpan into one or more consecutive spans at the specified interval.

splitspan :: (Day -> Day) -> (Day -> Day) -> DateSpan -> [DateSpan]Source

daysInSpan :: DateSpan -> Maybe IntegerSource

Count the days in a DateSpan, or if it is open-ended return Nothing.

spanContainsDate :: DateSpan -> Day -> BoolSource

Does the span include the given date ?

parsePeriodExpr :: Day -> String -> Either ParseError (Interval, DateSpan)Source

Combine two datespans, filling any unspecified dates in the first with dates from the second.

Calculate the intersection of two datespans.

Parse a period expression to an Interval and overall DateSpan using the provided reference date, or return a parse error.

dateSpanAsText :: DateSpan -> StringSource

Show a DateSpan as a human-readable pseudo-period-expression string.

spanFromSmartDateString :: Day -> String -> DateSpanSource

Convert a single smart date string to a date span using the provided reference date, or raise an error.

fixSmartDateStr :: Day -> String -> StringSource

Convert a smart date string to an explicit yyyy/mm/dd string using the provided reference date, or raise an error.

fixSmartDateStrEither :: Day -> String -> Either ParseError StringSource

A safe version of fixSmartDateStr.

fixSmartDate :: Day -> SmartDate -> DaySource

Convert a SmartDate to an absolute date using the provided reference date.

parsedatetimeM :: String -> Maybe LocalTimeSource

Parse a couple of date-time string formats to a time type.

parsedateM :: String -> Maybe DaySource

Parse a couple of date string formats to a time type.

parsedatetime :: String -> LocalTimeSource

Parse a date-time string to a time type, or raise an error.

parsedate :: String -> DaySource

Parse a date string to a time type, or raise an error.

parsetimewith :: ParseTime t => String -> String -> t -> tSource

Parse a time string to a time type using the provided pattern, or return the default.

smartdate :: GenParser Char st SmartDateSource

Parse a date in any of the formats allowed in ledger's period expressions, and maybe some others:

 2004
 2004/10
 2004/10/1
 10/1
 21
 october, oct
 yesterday, today, tomorrow
 this/next/last week/day/month/quarter/year

Returns a SmartDate, to be converted to a full date later (see fixSmartDate). Assumes any text in the parse stream has been lowercased.

smartdateonly :: GenParser Char st SmartDateSource

Like smartdate, but there must be nothing other than whitespace after the date.

mkdatespan :: String -> String -> DateSpanSource

Make a datespan from two valid date strings parseable by parsedate (or raise an error). Eg: mkdatespan "201111" "20111231".