HORIZON HASKELLDocslts/ghc-9.14.x7a6c33e2026-10-12Search packagesCtrl K
Theme: |

GHC 9.14.1 · lts/ghc-9.14.x · 7a6c33e · 2026-10-12

Modulefmt-0.6.3.0Haskell2010

Fmt.Time

Formatters for various time types. This module copies the structure of Formatting.Time from the formatting package.

Most of the time you'll want to use one of these formatters (all of the examples below use "2018-02-14 16:20:45.5 CST"):

  • dateTimeF – full date and time:

    Example1 expression
    dateTimeF t"Wed Feb 14 16:20:45 CST 2018"
  • hmF – hours and minutes:

    Example1 expression
    hmF t"16:20"
  • hmsF – hours, minutes and seconds:

    Example1 expression
    hmsF t"16:20:45"
  • dateDashF – date in ISO 8601 format:

    Example1 expression
    dateDashF t"2018-02-14"
  • diffF – either a time period or a point in time, in a convenient for humans format:

    Example2 expressions
    diffF False 130    -- time period (130 seconds)"2 minutes"diffF True 130     -- point in time (130 seconds in the future)"in 2 minutes"

Note that two formatters from Formatting.Time are called differently here:

pico     -> picosecondF
decimals -> subsecondF
Contents
  1. Custom
  2. For TimeZone (and ZonedTime and UTCTime)
  3. For TimeOfDay (and LocalTime and ZonedTime and UTCTime)
  4. For UTCTime and ZonedTime
  5. For Day (and LocalTime and ZonedTime and UTCTime)
  6. Time spans, diffs, NominalDiffTime, DiffTime, etc.
Synopsis
  • Packagefmt-0.6.3.0
  • Exports48
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceTime.hs

Custom

For TimeZone (and ZonedTime and UTCTime)

valuetzF :: FormatTime a => a -> Builder

Timezone offset on the format -HHMM.

Example2 expressions
t2018-02-14 16:20:45.5 CSTtzF t"-0600"
valuehour24F :: FormatTime a => a -> Builder

Hour, 24-hour, leading 0 as needed, 00 - 23.

Example2 expressions
hour24F t"16"hour24F midnight"00"
valuehour12F :: FormatTime a => a -> Builder

Hour, 12-hour, leading 0 as needed, 01 - 12.

Example2 expressions
hour12F t"04"hour12F midnight"12"
valuehour24SF :: FormatTime a => a -> Builder

Hour, 24-hour, leading space as needed, 0 - 23.

Example2 expressions
hour24SF t"16"hour24SF midnight" 0"
valuehour12SF :: FormatTime a => a -> Builder

Hour, 12-hour, leading space as needed, 1 - 12.

Example2 expressions
hour12SF t" 4"hour12SF midnight"12"
valuepicosecondF :: FormatTime a => a -> Builder

Picosecond, including trailing zeros, 000000000000 - 999999999999.

Example1 expression
picosecondF t"500000000000"
valuesubsecondF :: FormatTime a => a -> Builder

Decimal point of the second. Up to 12 digits, without trailing zeros. For a whole number of seconds, this produces an empty string.

Example1 expression
subsecondF t".5"
valueepochF :: FormatTime a => a -> Builder

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.

Example1 expression
epochF t"1518646845"

For Day (and LocalTime and ZonedTime and UTCTime)

Time spans, diffs, NominalDiffTime, DiffTime, etc.

valuediffF
  1. :: RealFrac n
  2. => Bool

    Whether to display the in/ago prefix or not

  3. -> n

    Example: 3 seconds ago, in 2 days

  4. -> Builder

Display a time span as one time relative to another. Input is assumed to be seconds. Typical inputs are NominalDiffTime and DiffTime.

Example2 expressions
diffF False 100"a minute"diffF True 100"in a minute"
valueyearsF
  1. :: RealFrac n
  2. => Int

    Decimal places.

  3. -> n
  4. -> Builder

Display the absolute value time span in years.

Example2 expressions
epochF t    -- time passed since Jan 1, 1970"1518646845"yearsF 3 1518646845"48.156"
valuedaysF
  1. :: RealFrac n
  2. => Int

    Decimal places.

  3. -> n
  4. -> Builder

Display the absolute value time span in days.

Example1 expression
daysF 3 1518646845"17576.931"
valuehoursF
  1. :: RealFrac n
  2. => Int

    Decimal places.

  3. -> n
  4. -> Builder

Display the absolute value time span in hours.

Example1 expression
hoursF 3 3600"1.000"
valueminutesF
  1. :: RealFrac n
  2. => Int

    Decimal places.

  3. -> n
  4. -> Builder

Display the absolute value time span in minutes.

Example1 expression
minutesF 3 150"2.500"
valuesecondsF
  1. :: RealFrac n
  2. => Int

    Decimal places.

  3. -> n
  4. -> Builder

Display the absolute value time span in seconds.

Example1 expression
secondsF 3 100"100.000"