thyme-0.4: A faster time library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Thyme.Format

Description

Formatting and parsing for dates and times.

Synopsis

Formatting Date/Time to String

class FormatTime t where Source #

All instances of this class may be formatted by formatTime.

Methods

showsTime :: TimeLocale -> t -> (Char -> ShowS) -> Char -> ShowS Source #

Instances

Instances details
FormatTime Day Source # 
Instance details

Defined in Data.Thyme.Format

Methods

showsTime :: TimeLocale -> Day -> (Char -> ShowS) -> Char -> ShowS Source #

FormatTime MondayWeek Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime MonthDay Source # 
Instance details

Defined in Data.Thyme.Format

Methods

showsTime :: TimeLocale -> MonthDay -> (Char -> ShowS) -> Char -> ShowS Source #

FormatTime OrdinalDate Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime SundayWeek Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime WeekDate Source # 
Instance details

Defined in Data.Thyme.Format

Methods

showsTime :: TimeLocale -> WeekDate -> (Char -> ShowS) -> Char -> ShowS Source #

FormatTime YearMonthDay Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime UTCTime Source # 
Instance details

Defined in Data.Thyme.Format

Methods

showsTime :: TimeLocale -> UTCTime -> (Char -> ShowS) -> Char -> ShowS Source #

FormatTime UniversalTime Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime AbsoluteTime Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime DotNetTime Source # 
Instance details

Defined in Data.Thyme.Format.Aeson

FormatTime LocalTime Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime TimeOfDay Source # 
Instance details

Defined in Data.Thyme.Format

FormatTime TimeZone Source # 
Instance details

Defined in Data.Thyme.Format

Methods

showsTime :: TimeLocale -> TimeZone -> (Char -> ShowS) -> Char -> ShowS Source #

FormatTime ZonedTime Source # 
Instance details

Defined in Data.Thyme.Format

formatTime Source #

Arguments

:: FormatTime t 
=> TimeLocale

Locale for formatting.

-> String

Template spec string.

-> t

FormatTime instance value to be formatted.

-> String 

Format a FormatTime instance value according to a template string.

These formatting template codes are intended to be compatible with glibc strftime() function, following Data.Time.Format, which follows formatCalendarTime from the old-time package. Codes which differ from strftime() are marked as EXTENSION.

Show/Parse template string spec

For all types

%%
literal "%"

For TimeZone (and ZonedTime and UTCTime):

%z
RFC 822/ISO 8601:1988 style numeric time zone (e.g., "-0600" or "+0100")
%N
ISO 8601 style numeric time zone (e.g., "-06:00" or "+01:00") EXTENSION
%Z
timezone name

For LocalTime (and ZonedTime and UTCTime and UniversalTime)

%c
The preferred calendar time representation for the current locale. As dateTimeFmt locale (e.g. %a %b %e %H:%M:%S %Z %Y)

For TimeOfDay (and LocalTime and ZonedTime and UTCTime and UniversalTime)

%R
same as %H:%M
%T
same as %H:%M:%S
%X
The preferred time of day representation for the current locale. As timeFmt locale (e.g. %H:%M:%S)
%r
The complete calendar time using the AM/PM format of the current locale. As time12Fmt locale (e.g. %I:%M:%S %p)
%P
day-half of day from (amPm locale), converted to lowercase, "am", "pm"
%p
day-half of day from (amPm locale), "AM", "PM"
%H
hour of day (24-hour), 0-padded to two chars, "00""23"
%k
hour of day (24-hour), space-padded to two chars, " 0""23"
%I
hour of day-half (12-hour), 0-padded to two chars, "01""12"
%l
hour of day-half (12-hour), space-padded to two chars, " 1""12"
%M
minute of hour, 0-padded to two chars, "00""59"
%S
second of minute (without decimal part), 0-padded to two chars, "00""60"
%q
picosecond of second, 0-padded to twelve chars, "000000000000""999999999999". EXTENSION
%v
microsecond of second, 0-padded to six chars, "000000""999999". EXTENSION
%Q
decimal point and fraction of second, up to 6 second decimals, without trailing zeros. For a whole number of seconds, %Q produces the empty string. EXTENSION

For UTCTime

%s
number of whole seconds since the Unix epoch. For times before the Unix epoch, this is a negative number. Note that in %s.%q and %s%Q the decimals are positive, not negative. For example, 0.9 seconds before the Unix epoch is formatted as "-1.1" with %s%Q.

For Day (and LocalTime and ZonedTime and UTCTime and UniversalTime)

%D
same as %m/%d/%y
%F
same as %Y-%m-%d
%x
as dateFmt locale (e.g. %m/%d/%y)
%Y
year, no padding.
%y
year of century, 0-padded to two chars, "00""99"
%C
century, no padding.
%B
month name, long form (fst from months locale), "January""December"
%b, %h
month name, short form (snd from months locale), "Jan""Dec"
%m
month of year, 0-padded to two chars, "01""12"
%d
day of month, 0-padded to two chars, "01""31"
%e
day of month, space-padded to two chars, " 1""31"
%j
day of year, 0-padded to three chars, "001""366"
%G
year for Week Date format, no padding.
%g
year of century for Week Date format, 0-padded to two chars, "00""99"
%f
century for Week Date format, no padding. EXTENSION
%V
week of year for Week Date format, 0-padded to two chars, "01""53"
%u
day of week for Week Date format, "1""7"
%a
day of week, short form (snd from wDays locale), "Sun""Sat"
%A
day of week, long form (fst from wDays locale), "Sunday""Saturday"
%U
week of year where weeks start on Sunday (as sundayStartWeek), 0-padded to two chars, "00""53"
%w
day of week number, "0" (= Sunday) – "6" (= Saturday)
%W
week of year where weeks start on Monday (as mondayStartWeek), 0-padded to two chars, "00""53"

Examples

ISO 8601

> formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%N" $ mkUTCTime 2015 1 15  12 34 56.78
"2015-01-15T12:34:56+00:00"

RFC822

> formatTime defaultTimeLocale "%a, %_d %b %Y %H:%M:%S %Z" $ mkUTCTime 2015 1 15  12 34 56.78
"Thu, 15 Jan 2015 12:34:56 UTC"

YYYY-MM-DD hh:mm:ss.000000

> formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S.%v" $ mkUTCTime 2015 1 15  12 34 56.78
"2015-01-15 12:34:56.780000"

Parsing Date/Time from String

class ParseTime t where Source #

All instances of this class may be parsed by parseTime, readTime, and readsTime.

Methods

buildTime :: TimeParse -> t Source #

Instances

Instances details
ParseTime Day Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime MondayWeek Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime MonthDay Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime OrdinalDate Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime SundayWeek Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime WeekDate Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime YearMonthDay Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime UTCTime Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime UniversalTime Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime AbsoluteTime Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime LocalTime Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime TimeOfDay Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime TimeZone Source # 
Instance details

Defined in Data.Thyme.Format

ParseTime ZonedTime Source # 
Instance details

Defined in Data.Thyme.Format

parseTime Source #

Arguments

:: ParseTime t 
=> TimeLocale

Locale.

-> String

Parser template spec string. See formatTime for spec.

-> String

String value to be parsed as a ParseTime instance value.

-> Maybe t 

Parse a string as a ParseTime instance value.

Return Nothing if parsing fails.

Examples

ISO 8601

> parseTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%N" "2015-01-15T12:34:56+00:00" :: Maybe UTCTime
  Just 2015-01-15 12:34:56 UTC

> parseTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S%N" "2015-01-15T12:34:56-12:00" :: Maybe UTCTime
  Just 2015-01-16 00:34:56 UTC

YYYY-MM-DD hh:mm:ss.0

> parseTime defaultTimeLocale "%Y-%m-%d %H:%M:%S%Q" "2015-01-15 12:34:56.78" :: Maybe UTCTime
  Just 2015-01-15 12:34:56.78 UTC

readTime Source #

Arguments

:: ParseTime t 
=> TimeLocale

Locale.

-> String

Parser template spec string. See formatTime for spec.

-> String

String value to be parsed as a ParseTime instance value.

-> t 

Parse a string as a ParseTime instance value.

Call error if parsing fails.

readsTime Source #

Arguments

:: ParseTime t 
=> TimeLocale

Locale.

-> String

Parser template spec string. See formatTime for spec.

-> ReadS t 

Produce a ReadS to parse a string as a ParseTime instance value.

data TimeParse Source #

Unconstituted date-time for parsing.

Instances

Instances details
Show TimeParse Source # 
Instance details

Defined in Data.Thyme.Format

timeParser Source #

Arguments

:: TimeLocale

Locale.

-> String

Parser template spec string. See formatTime for spec.

-> Parser TimeParse 

Produce a Parser for UTF-8 encoded ByteStrings.

This function is used internally by parseTime, readTime, and readsTime; consider using one of those functions instead.

Attoparsec easily beats any String parser out there, but we do have to be careful to convert the input to UTF-8 ByteStrings.

Time Locale

data TimeLocale #

Constructors

TimeLocale 

Fields

defaultTimeLocale :: TimeLocale #

Locale representing American usage.

knownTimeZones contains only the ten time-zones mentioned in RFC 802 sec. 5: "UT", "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", "PDT". Note that the parsing functions will regardless parse "UTC", single-letter military time-zones, and +HHMM format.

Orphan instances