period-0.1.0.7: Parse and format date periods, collapse and expand their text representations.

Safe HaskellNone
LanguageHaskell2010

Text.Period

Synopsis

Documentation

type Period = (Day, Day) Source #

data PeriodFmt Source #

Constructors

PeriodFmt 

Fields

  • perFieldSep :: Text

    Separator between year, month and day

  • perDateSep :: Text

    Separator between dates in the range, e.g. comma in yyyy-mm-dd,yyyy-mm-dd

parsePeriod :: Text -> Period Source #

Parse period from text representation, which can be either simple date range (yyyy-mm-dd,yyyy-mm-dd) or something shorter like yyyy,yyyy, or even something like yyyy-01-23,03-21 which corresponds to yyyy-01-23,yyyy-03-21. The list of possible combinations can be found in test/Spec.hs.

parsePeriod understands dash as field separator (like yyyy-mm-dd), or accepts short date format (yyyymmdd). It understands comma and underscore as separators between dashed dates (yyyy-mm-dd) and dash as separator between short dates (yyyymmdd).

parsePeriod produces error on unparsable input.

parsePeriodMay :: Text -> Maybe Period Source #

Safe analogue of parsePeriod using Maybe

parsePeriodEither :: Text -> Either String Period Source #

Safe analogue of parsePeriod using Either

formatPeriod :: PeriodFmt -> Period -> Text Source #

Format a period as a simple date range, e.g. yyyy-mm-dd,yyyy-mm-dd

collapsePeriod :: PeriodFmt -> Period -> Text Source #

Format a period in the shortest fashion, e.g. collapse yyyy-01-01,yyyy-01-31 to yyyy-01