HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

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
  • 48 values
  • Packagefmt-0.6.3.0
  • Exports48
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceTime.hs

Custom

1 declaration
valuetimeF :: FormatTime a => Text -> a -> Builder
#

Format time with an arbitrary formatting string. Other formatters in this module are implemented using timeF.

For TimeZone (and ZonedTime and UTCTime)

3 declarations
valuetzF :: FormatTime a => a -> Builder
#

Timezone offset on the format -HHMM.

Example2 expressions
t2018-02-14 16:20:45.5 CSTtzF t"-0600"

For TimeOfDay (and LocalTime and ZonedTime and UTCTime)

14 declarations
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"

For UTCTime and ZonedTime

1 declaration
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)

23 declarations
valueyyF :: FormatTime a => a -> Builder
#

Last two digits of year, 00 - 99.

Example1 expression
yyF t"18"
valuecenturyF :: FormatTime a => a -> Builder
#

Century (being the first two digits of the year), 00 - 99.

Example1 expression
centuryF t"20"
valuemonthF :: FormatTime a => a -> Builder
#

Month of year, leading 0 as needed, 01 - 12.

Example1 expression
monthF t"02"
valuedayF :: FormatTime a => a -> Builder
#

Day of year for Ordinal Date format, 001 - 366.

Example1 expression
dayF t"045"
valueweekYYF :: FormatTime a => a -> Builder
#

Last two digits of year for Week Date format, 00 - 99.

Example1 expression
weekYYF t"18"
valueweekCenturyF :: FormatTime a => a -> Builder
#

Century (first two digits of year) for Week Date format, 00 - 99.

Example1 expression
weekCenturyF t"20"
valueweekF :: FormatTime a => a -> Builder
#

Week for Week Date format, 01 - 53.

Example1 expression
weekF t"07"
valueweekFromZeroF :: FormatTime a => a -> Builder
#

Week number of year, where weeks start on Sunday (as sundayStartWeek), 00 - 53.

Example1 expression
weekFromZeroF t"06"
valueweekOfYearMonF :: FormatTime a => a -> Builder
#

Week number of year, where weeks start on Monday (as mondayStartWeek), 00 - 53.

Example1 expression
weekOfYearMonF t"07"

Time spans, diffs, NominalDiffTime, DiffTime, etc.

6 declarations
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"