Data.Time.Format.Internal

time-1.12.2: A time library

Safe Haskell | Safe
Language | Haskell2010

Data.Time.Format.Internal

Contents

- ISO8601 formatting

Description

The contents of this module is liable to change, or disappear entirely. Please let me know if you depend on anything here.

Synopsis

- data Format t = MkFormat {
  - formatShowM :: t -> Maybe String
  - formatReadP :: ReadP t
  }
- formatString :: (TimeLocale -> t -> String) -> FormatOptions -> t -> String
- data PadOption
- class FormatTime t where
  - formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> t -> String)
- formatTime :: FormatTime t => TimeLocale -> String -> t -> String
- type FormatNumericPadding = Maybe Char
- data FormatOptions = MkFormatOptions {
  - foLocale :: TimeLocale
  - foPadding :: Maybe FormatNumericPadding
  - foWidth :: Maybe Int
  }
- class (Num t, Ord t, Show t) => ShowPadded t
- formatGeneral :: Bool -> Bool -> Int -> Char -> (TimeLocale -> PadOption -> t -> String) -> FormatOptions -> t -> String
- formatNumber :: ShowPadded i => Bool -> Int -> Char -> (t -> i) -> FormatOptions -> t -> String
- formatNumberStd :: Int -> (t -> Integer) -> FormatOptions -> t -> String
- showPaddedFixed :: HasResolution a => PadOption -> PadOption -> Fixed a -> String
- showPaddedFixedFraction :: HasResolution a => PadOption -> Fixed a -> String
- quotBy :: (Real a, Integral b) => a -> a -> b
- remBy :: Real a => a -> a -> a
- class ParseTime t where
  - substituteTimeSpecifier :: Proxy t -> TimeLocale -> Char -> Maybe String
  - parseTimeSpecifier :: Proxy t -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String
  - buildTime :: TimeLocale -> [(Char, String)] -> Maybe t
- data ParseNumericPadding
  - = NoPadding
  - | SpacePadding
  - | ZeroPadding
- parseSpecifiers :: ParseTime t => Proxy t -> TimeLocale -> String -> ReadP [(Char, String)]
- timeSubstituteTimeSpecifier :: TimeLocale -> Char -> Maybe String
- timeParseTimeSpecifier :: TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String
- durationParseTimeSpecifier :: TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String

# ISO8601 formatting

data Format t Source #

A text format for a type

Constructors

MkFormat |
Fields formatShowM :: t -> Maybe String Show a value in the format, if representable formatReadP :: ReadP t Read a value in the format

formatString :: (TimeLocale -> t -> String) -> FormatOptions -> t -> String Source #

data PadOption Source #

class FormatTime t where Source #

Methods

formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> t -> String) Source #

Since: time-1.9.1

#### Instances

Instances details

FormatTime CalendarDiffDays Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> CalendarDiffDays -> String) Source #
FormatTime Day Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> Day -> String) Source #
FormatTime Month Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> Month -> String) Source #
FormatTime DayOfWeek Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> DayOfWeek -> String) Source #
FormatTime DiffTime Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> DiffTime -> String) Source #
FormatTime NominalDiffTime Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> NominalDiffTime -> String) Source #
FormatTime UTCTime Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> UTCTime -> String) Source #
FormatTime UniversalTime Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> UniversalTime -> String) Source #
FormatTime CalendarDiffTime Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> CalendarDiffTime -> String) Source #
FormatTime LocalTime Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> LocalTime -> String) Source #
FormatTime TimeOfDay Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> TimeOfDay -> String) Source #
FormatTime TimeZone Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> TimeZone -> String) Source #
FormatTime ZonedTime Source # |
Instance details Defined in Data.Time.Format.Format.Instances Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> ZonedTime -> String) Source #

formatTime :: FormatTime t => TimeLocale -> String -> t -> String Source #

Substitute various time-related information for each %-code in the string, as per `formatCharacter`.

The general form is `%<modifier><width><alternate><specifier>`, where `<modifier>`, `<width>`, and `<alternate>` are optional.

## `<modifier>`

glibc-style modifiers can be used before the specifier (here marked as `z`):

`%-z`
  no padding
`%_z`
  pad with spaces
`%0z`
  pad with zeros
`%^z`
  convert to upper case
`%#z`
  convert to lower case (consistently, unlike glibc)

## `<width>`

Width digits can also be used after any modifiers and before the specifier (here marked as `z`), for example:

`%4z`
  pad to 4 characters (with default padding character)
`%_12z`
  pad with spaces to 12 characters

## `<alternate>`

An optional `E` character indicates an alternate formatting. Currently this only affects `%Z` and `%z`.

`%Ez`
  alternate formatting

## `<specifier>`

For all types (note these three are done by `formatTime`, not by `formatCharacter`):

`%%`
  `%`
`%t`
  tab
`%n`
  newline

### `TimeZone`

For `TimeZone` (and `ZonedTime` and `UTCTime`):

`%z`
  timezone offset in the format `±HHMM`
`%Ez`
  timezone offset in the format `±HH:MM`
`%Z`
  timezone name (or else offset in the format `±HHMM`)
`%EZ`
  timezone name (or else offset in the format `±HH:MM`)

### `LocalTime`

For `LocalTime` (and `ZonedTime` and `UTCTime` and `UniversalTime`):

`%c`
  as `dateTimeFmt` `locale` (e.g. `%a %b %e %H:%M:%S %Z %Y`)

### `TimeOfDay`

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

`%R`
  same as `%H:%M`
`%T`
  same as `%H:%M:%S`
`%X`
  as `timeFmt` `locale` (e.g. `%H:%M:%S`)
`%r`
  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`.
`%Q`
  decimal point and fraction of second, up to 12 second decimals, without trailing zeros. For a whole number of seconds, `%Q` omits the decimal point unless padding is specified.

### `UTCTime` and `ZonedTime`

For `UTCTime` and `ZonedTime`:

`%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`.

### `DayOfWeek`

For `DayOfWeek` (and `Day` and `LocalTime` and `ZonedTime` and `UTCTime` and `UniversalTime`):

`%u`
  day of week number for Week Date format, `1` (= Monday) - `7` (= Sunday)
`%w`
  day of week number, `0` (= Sunday) - `6` (= Saturday)
`%a`
  day of week, short form (`snd` from `wDays` `locale`), `Sun` - `Sat`
`%A`
  day of week, long form (`fst` from `wDays` `locale`), `Sunday` - `Saturday`

### `Month`

For `Month` (and `Day` and `LocalTime` and `ZonedTime` and `UTCTime` and `UniversalTime`):

`%Y`
  year, no padding. Note `%0Y` and `%_Y` pad to four chars
`%y`
  year of century, 0-padded to two chars, `00` - `99`
`%C`
  century, no padding. Note `%0C` and `%_C` pad to two chars
`%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`

### `Day`

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`)
`%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`
`%f`
  century for Week Date format, no padding. Note `%0f` and `%_f` pad to two chars
`%V`
  week of year for Week Date format, 0-padded to two chars, `01` - `53`
`%U`
  week of year where weeks start on Sunday (as `sundayStartWeek`), 0-padded to two chars, `00` - `53`
`%W`
  week of year where weeks start on Monday (as `mondayStartWeek`), 0-padded to two chars, `00` - `53`

## Duration types

The specifiers for `DiffTime`, `NominalDiffTime`, `CalendarDiffDays`, and `CalendarDiffTime` are semantically separate from the other types. Specifiers on negative time differences will generally be negative (think `rem` rather than `mod`).

### `NominalDiffTime` and `DiffTime`

Note that a "minute" of `DiffTime` is simply 60 SI seconds, rather than a minute of civil time. Use `NominalDiffTime` to work with civil time, ignoring any leap seconds.

For `NominalDiffTime` and `DiffTime`:

`%w`
  total whole weeks
`%d`
  total whole days
`%D`
  whole days of week
`%h`
  total whole hours
`%H`
  whole hours of day
`%m`
  total whole minutes
`%M`
  whole minutes of hour
`%s`
  total whole seconds
`%Es`
  total seconds, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds, `%Es` omits the decimal point unless padding is specified.
`%0Es`
  total seconds, with decimal point and <width> (default 12) decimal places.
`%S`
  whole seconds of minute
`%ES`
  seconds of minute, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds, `%ES` omits the decimal point unless padding is specified.
`%0ES`
  seconds of minute as two digits, with decimal point and <width> (default 12) decimal places.

### `CalendarDiffDays`

For `CalendarDiffDays` (and `CalendarDiffTime`):

`%y`
  total years
`%b`
  total months
`%B`
  months of year
`%w`
  total weeks, not including months
`%d`
  total days, not including months
`%D`
  days of week

### `CalendarDiffTime`

For `CalendarDiffTime`:

`%h`
  total hours, not including months
`%H`
  hours of day
`%m`
  total minutes, not including months
`%M`
  minutes of hour
`%s`
  total whole seconds, not including months
`%Es`
  total seconds, not including months, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds, `%Es` omits the decimal point unless padding is specified.
`%0Es`
  total seconds, not including months, with decimal point and <width> (default 12) decimal places.
`%S`
  whole seconds of minute
`%ES`
  seconds of minute, with decimal point and up to <width> (default 12) decimal places, without trailing zeros. For a whole number of seconds, `%ES` omits the decimal point unless padding is specified.
`%0ES`
  seconds of minute as two digits, with decimal point and <width> (default 12) decimal places.

type FormatNumericPadding = Maybe Char Source #

data FormatOptions Source #

Constructors

MkFormatOptions |
Fields foLocale :: TimeLocale foPadding :: Maybe FormatNumericPadding foWidth :: Maybe Int

class (Num t, Ord t, Show t) => ShowPadded t Source #

Minimal complete definition

showPaddedNum

#### Instances

Instances details

ShowPadded Integer Source # |
Instance details Defined in Data.Time.Calendar.Private Methods showPaddedNum :: PadOption -> Integer -> String
ShowPadded Int Source # |
Instance details Defined in Data.Time.Calendar.Private Methods showPaddedNum :: PadOption -> Int -> String

formatGeneral :: Bool -> Bool -> Int -> Char -> (TimeLocale -> PadOption -> t -> String) -> FormatOptions -> t -> String Source #

formatNumber :: ShowPadded i => Bool -> Int -> Char -> (t -> i) -> FormatOptions -> t -> String Source #

formatNumberStd :: Int -> (t -> Integer) -> FormatOptions -> t -> String Source #

showPaddedFixed :: HasResolution a => PadOption -> PadOption -> Fixed a -> String Source #

showPaddedFixedFraction :: HasResolution a => PadOption -> Fixed a -> String Source #

quotBy :: (Real a, Integral b) => a -> a -> b Source #

remBy :: Real a => a -> a -> a Source #

class ParseTime t where Source #

The class of types which can be parsed given a UNIX-style time format string.

Minimal complete definition

parseTimeSpecifier, buildTime

Methods

substituteTimeSpecifier :: Proxy t -> TimeLocale -> Char -> Maybe String Source #

Since: time-1.9.1

parseTimeSpecifier :: Proxy t -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source #

Get the string corresponding to the given format specifier.

Since: time-1.9.1

buildTime Source #

Arguments

:: TimeLocale | The time locale.
-> [(Char, String)] | Pairs of format characters and the corresponding part of the input.
-> Maybe t |

Builds a time value from a parsed input string. If the input does not include all the information needed to construct a complete value, any missing parts should be taken from 1970-01-01 00:00:00 +0000 (which was a Thursday). In the absence of `%C` or `%Y`, century is 1969 - 2068.

Since: time-1.9.1

#### Instances

Instances details

ParseTime CalendarDiffDays Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy CalendarDiffDays -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy CalendarDiffDays -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe CalendarDiffDays Source #
ParseTime Day Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy Day -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy Day -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe Day Source #
ParseTime Month Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy Month -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy Month -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe Month Source #
ParseTime DiffTime Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy DiffTime -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy DiffTime -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe DiffTime Source #
ParseTime NominalDiffTime Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy NominalDiffTime -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy NominalDiffTime -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe NominalDiffTime Source #
ParseTime UTCTime Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy UTCTime -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy UTCTime -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe UTCTime Source #
ParseTime UniversalTime Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy UniversalTime -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy UniversalTime -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe UniversalTime Source #
ParseTime CalendarDiffTime Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy CalendarDiffTime -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy CalendarDiffTime -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe CalendarDiffTime Source #
ParseTime LocalTime Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy LocalTime -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy LocalTime -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe LocalTime Source #
ParseTime TimeOfDay Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy TimeOfDay -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy TimeOfDay -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe TimeOfDay Source #
ParseTime TimeZone Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy TimeZone -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy TimeZone -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe TimeZone Source #
ParseTime ZonedTime Source # |
Instance details Defined in Data.Time.Format.Parse.Instances Methods substituteTimeSpecifier :: Proxy ZonedTime -> TimeLocale -> Char -> Maybe String Source # parseTimeSpecifier :: Proxy ZonedTime -> TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source # buildTime :: TimeLocale -> [(Char, String)] -> Maybe ZonedTime Source #

data ParseNumericPadding Source #

Constructors

NoPadding |
SpacePadding |
ZeroPadding |

parseSpecifiers :: ParseTime t => Proxy t -> TimeLocale -> String -> ReadP [(Char, String)] Source #

timeSubstituteTimeSpecifier :: TimeLocale -> Char -> Maybe String Source #

timeParseTimeSpecifier :: TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source #

durationParseTimeSpecifier :: TimeLocale -> Maybe ParseNumericPadding -> Char -> ReadP String Source #