fmt-0.6.3.0: A new formatting library
Safe HaskellNone
LanguageHaskell2010

Fmt.Time

Description

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:

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

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

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

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

    >>> 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
Synopsis

Custom

timeF :: FormatTime a => Text -> a -> Builder Source #

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

For TimeZone (and ZonedTime and UTCTime)

tzF :: FormatTime a => a -> Builder Source #

Timezone offset on the format -HHMM.

>>> t
2018-02-14 16:20:45.5 CST
>>> tzF t
"-0600"

tzNameF :: FormatTime a => a -> Builder Source #

Timezone name.

>>> tzNameF t
"CST"

dateTimeF :: FormatTime a => a -> Builder Source #

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

>>> dateTimeF t
"Wed Feb 14 16:20:45 CST 2018"

For TimeOfDay (and LocalTime and ZonedTime and UTCTime)

hmF :: FormatTime a => a -> Builder Source #

Same as %H:%M.

>>> hmF t
"16:20"

hmsF :: FormatTime a => a -> Builder Source #

Same as %H:%M:%S.

>>> hmsF t
"16:20:45"

hmsLF :: FormatTime a => a -> Builder Source #

As timeFmt locale (e.g. %H:%M:%S).

>>> hmsLF t
"16:20:45"

hmsPLF :: FormatTime a => a -> Builder Source #

As time12Fmt locale (e.g. %I:%M:%S %p).

>>> hmsPLF t
"04:20:45 PM"

dayHalfF :: FormatTime a => a -> Builder Source #

Day half from (amPm locale), converted to lowercase, am, pm.

>>> dayHalfF t
"pm"

dayHalfUF :: FormatTime a => a -> Builder Source #

Day half from (amPm locale), AM, PM.

>>> dayHalfUF t
"PM"

hour24F :: FormatTime a => a -> Builder Source #

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

>>> hour24F t
"16"
>>> hour24F midnight
"00"

hour12F :: FormatTime a => a -> Builder Source #

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

>>> hour12F t
"04"
>>> hour12F midnight
"12"

hour24SF :: FormatTime a => a -> Builder Source #

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

>>> hour24SF t
"16"
>>> hour24SF midnight
" 0"

hour12SF :: FormatTime a => a -> Builder Source #

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

>>> hour12SF t
" 4"
>>> hour12SF midnight
"12"

minuteF :: FormatTime a => a -> Builder Source #

Minute, 00 - 59.

>>> minuteF t
"20"

secondF :: FormatTime a => a -> Builder Source #

Second, without decimal part, 00 - 60.

>>> secondF t
"45"

picosecondF :: FormatTime a => a -> Builder Source #

Picosecond, including trailing zeros, 000000000000 - 999999999999.

>>> picosecondF t
"500000000000"

subsecondF :: FormatTime a => a -> Builder Source #

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

>>> subsecondF t
".5"

For UTCTime and ZonedTime

epochF :: FormatTime a => a -> Builder Source #

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.

>>> epochF t
"1518646845"

For Day (and LocalTime and ZonedTime and UTCTime)

dateSlashF :: FormatTime a => a -> Builder Source #

Same as %m/%d/%y.

>>> dateSlashF t
"02/14/18"

dateDashF :: FormatTime a => a -> Builder Source #

Same as %Y-%m-%d.

>>> dateDashF t
"2018-02-14"

dateSlashLF :: FormatTime a => a -> Builder Source #

As dateFmt locale (e.g. %m/%d/%y).

>>> dateSlashLF t
"02/14/18"

yearF :: FormatTime a => a -> Builder Source #

Year.

>>> yearF t
"2018"

yyF :: FormatTime a => a -> Builder Source #

Last two digits of year, 00 - 99.

>>> yyF t
"18"

centuryF :: FormatTime a => a -> Builder Source #

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

>>> centuryF t
"20"

monthNameF :: FormatTime a => a -> Builder Source #

Month name, long form (fst from months locale), January - December.

>>> monthNameF t
"February"

monthNameShortF :: FormatTime a => a -> Builder Source #

Month name, short form (snd from months locale), Jan - Dec.

>>> monthNameShortF t
"Feb"

monthF :: FormatTime a => a -> Builder Source #

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

>>> monthF t
"02"

dayOfMonthF :: FormatTime a => a -> Builder Source #

Day of month, leading 0 as needed, 01 - 31.

>>> dayOfMonthF t
"14"

dayOfMonthOrdF :: FormatTime a => a -> Builder Source #

Day of month, 1st, 2nd, 25th, etc.

>>> dayOfMonthOrdF t
"14th"

dayOfMonthSF :: FormatTime a => a -> Builder Source #

Day of month, leading space as needed, 1 - 31.

dayF :: FormatTime a => a -> Builder Source #

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

>>> dayF t
"045"

weekYearF :: FormatTime a => a -> Builder Source #

Year for Week Date format e.g. 2013.

>>> weekYearF t
"2018"

weekYYF :: FormatTime a => a -> Builder Source #

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

>>> weekYYF t
"18"

weekCenturyF :: FormatTime a => a -> Builder Source #

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

>>> weekCenturyF t
"20"

weekF :: FormatTime a => a -> Builder Source #

Week for Week Date format, 01 - 53.

>>> weekF t
"07"

dayOfWeekF :: FormatTime a => a -> Builder Source #

Day for Week Date format, 1 - 7.

>>> dayOfWeekF t
"3"

dayNameShortF :: FormatTime a => a -> Builder Source #

Day of week, short form (snd from wDays locale), Sun - Sat.

>>> dayNameShortF t
"Wed"

dayNameF :: FormatTime a => a -> Builder Source #

Day of week, long form (fst from wDays locale), Sunday - Saturday.

>>> dayNameF t
"Wednesday"

weekFromZeroF :: FormatTime a => a -> Builder Source #

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

>>> weekFromZeroF t
"06"

dayOfWeekFromZeroF :: FormatTime a => a -> Builder Source #

Day of week number, 0 (= Sunday) - 6 (= Saturday).

>>> dayOfWeekFromZeroF t
"3"

weekOfYearMonF :: FormatTime a => a -> Builder Source #

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

>>> weekOfYearMonF t
"07"

Time spans, diffs, NominalDiffTime, DiffTime, etc.

diffF Source #

Arguments

:: forall n. RealFrac n 
=> Bool

Whether to display the in/ago prefix or not

-> n

Example: 3 seconds ago, in 2 days

-> Builder 

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

>>> diffF False 100
"a minute"
>>> diffF True 100
"in a minute"

yearsF Source #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in years.

>>> epochF t    -- time passed since Jan 1, 1970
"1518646845"
>>> yearsF 3 1518646845
"48.156"

daysF Source #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in days.

>>> daysF 3 1518646845
"17576.931"

hoursF Source #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in hours.

>>> hoursF 3 3600
"1.000"

minutesF Source #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in minutes.

>>> minutesF 3 150
"2.500"

secondsF Source #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in seconds.

>>> secondsF 3 100
"100.000"