Module

Data.Formatter.DateTime

Package
purescript-formatters
Repository
purescript-contrib/purescript-formatters

This is a subset of common format/parse strings currently supported.

  • YYYY - Full Year (1999)
  • YY - 2 digit year (99)
  • MMMM - Full Month (January)
  • MMM - Short Month (Jan)
  • M - Unpadded Month (1)
  • DD - Padded Day (02)
  • D - Day of month (2)
  • X - Unix Timestamp (1506875681)
  • d - Day of Week (2, Monday = 1, Sunday = 7)
  • dddd - DOW Name (Monday)
  • ddd - DOW Name Short (Mon)
  • HH - 24 Hour (13)
  • hh - 12 Hour (1)
  • a - Meridiem (am/pm)
  • A - Meridiem (AM/PM)
  • mm - Minutes Padded (02)
  • m - Minutes (2)
  • ss - Seconds Padded (02)
  • s - Seconds (2)
  • S - MilliSeconds (4)
  • SS - MilliSeconds (04)
  • SSS - MilliSeconds (004)

Full list is defined here

#Formatter Source

type Formatter = List FormatterCommand

A description of a string format for dates and times. Functions such as format and unformat use a Formatter such as (YearFull : MonthTwoDigits : DayOfMonthTwoDigits : Nil) in place of a format string such as "YYYYMMDD".

#Meridiem Source

data Meridiem

Before or after noon (AM/PM)

Instances

#printFormatter Source

printFormatter :: Formatter -> String

The format string representation of a Formatter.

show (Hours24 : MinutesTwoDigits : Nil) = "(Hours24 : MinutesTwoDigits : Nil)"

while printFormatter (Hours24 : MinutesTwoDigits : Nil) = "HHmm".

#parseFormatString Source

parseFormatString :: String -> Either String Formatter

Attempt to parse a String as a Formatter.

#format Source

format :: Formatter -> DateTime -> String

Format a DateTime according to the format defined in the given Formatter.

#formatDateTime Source

formatDateTime :: String -> DateTime -> Either String String

Format a DateTime according to the format defined in the given format string. If the format string is empty or contains a reserved character such as a single "H", will return a Left value. Note that any non-reserved Char is treated as a placeholder, so while "yyyy-MM-dd" might not produce the format you want (since "yyyy" isn't a recognized format), it will still return a Right value.

#unformat Source

unformat :: Formatter -> String -> Either String DateTime

Attempt to parse a String as a DateTime according to the format defined in the given Formatter.

#unformatDateTime Source

unformatDateTime :: String -> String -> Either String DateTime

Attempt to parse a String as a DateTime according to the format defined in the given format string. Returns a Left value if the given format string was empty, or if the date string fails to parse according to the format.

#unformatParser Source

unformatParser :: forall m. Monad m => Formatter -> ParserT String m DateTime

A ParserT for Strings that parses a DateTime according to the format defined in the given Formatter.