hodatime
Copyright(C) 2016 Jason Johnson
LicenseBSD-style (see the file LICENSE)
MaintainerJason Johnson <jason.johnson.081@gmail.com>
Stabilityexperimental
PortabilityPOSIX, Windows
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.HodaTime.Pattern

Description

A Pattern is used to parse and format types in this library.

Cookbook

Format and parse with a standard pattern

A Pattern both formats and parses. pR is the ISO-8601 round-trip date pattern.

>>> format pR <$> calendarDate 23 April 2024
Just "2024-04-23"
>>> parse pR "2024-04-23" :: Maybe (CalendarDate Gregorian)
Just (fromJust (Gregorian.calendarDate 23 April 2024))

Build a custom pattern

Patterns compose: field patterns are joined with <> and literals inserted with <%. This builds a custom "23 Apr 2024" layout (day, abbreviated month, year):

>>> format (pdd <% char ' ' <> pMMM <% char ' ' <> pyyyy) <$> calendarDate 23 April 2024
Just "23 Apr 2024"
Synopsis

Types

data Pattern a b r Source #

Pattern for the data type which is used by the parse, format and 'parse'' functions

Constructors

Pattern 

Fields

Instances

Instances details
Semigroup (Pattern (a -> a) (b -> r) r) Source # 
Instance details

Defined in Data.HodaTime.Pattern.Internal

Methods

(<>) :: Pattern (a -> a) (b -> r) r -> Pattern (a -> a) (b -> r) r -> Pattern (a -> a) (b -> r) r #

sconcat :: NonEmpty (Pattern (a -> a) (b -> r) r) -> Pattern (a -> a) (b -> r) r #

stimes :: Integral b0 => b0 -> Pattern (a -> a) (b -> r) r -> Pattern (a -> a) (b -> r) r #

Parsing / Formatting

parse :: (MonadThrow m, DefaultForParse a) => Pattern (a -> a) b String -> SourceName -> m a Source #

Parse a String given by Pattern for the data type a. Will call throwM on failure. NOTE: A default a will be used to determine what happens for fields which do not appear in the parse

parse' :: MonadThrow m => Pattern (a -> a) b String -> SourceName -> a -> m a Source #

Like parse above but lets the user provide an a as the default to use

format :: Pattern a r String -> r Source #

Use the given Pattern to format the data type a into a String

Standard Patterns

Custom Patterns

Used to create specialized patterns

(<%) :: Pattern a b r -> Pattern c r r -> Pattern a b r Source #

Merge a pattern that operates on a data type with a static pattern

Exceptions