fmt-0.5.0.0: A new formatting library

Safe HaskellNone
LanguageHaskell2010

Fmt.Time

Contents

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:

>>> dateTimeF t                  -- full date and time
"Sun May 14 16:16:47 MSK 2017"

>>> hmF t                        -- hours and minutes
"16:16"

>>> hmsF t                       -- hours, minutes and seconds
"16:16:47"

>>> dateDashF t                  -- date in ISO 8601 format
"2017-05-14"

>>> diffF False t                -- time period (convenient for humans)
"3 seconds"

>>> diffF True t                 -- point in time (convenient for humans)
"3 seconds ago"

Note that two formatters from Formatting.Time have been renamed:

pico     -> picosecondF
decimals -> subsecondF

Synopsis

Custom

timeF :: 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)

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

Timezone offset on the format -HHMM.

>>> t <- getZonedTime
>>> t
2017-05-14 16:16:47.62135 MSK
>>> tzF t
"+0300"

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

Timezone name.

>>> tzNameF t
"MSK"

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

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

>>> dateTimeF t
"Sun May 14 16:16:47 MSK 2017"

For TimeOfDay (and LocalTime and ZonedTime and UTCTime)

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

Same as %H:%M.

>>> hmF t
"16:16"

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

Same as %H:%M:%S.

>>> hmsF t
"16:16:47"

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

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

>>> hmsLF t
"16:16:47"

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

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

>>> hmsPLF t
"04:16:47 PM"

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

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

>>> dayHalfF t
"pm"

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

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

>>> dayHalfUF t
"PM"

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

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

>>> hour24F t
"16"
>>> let nightT = read "2017-05-14 00:21:32.714083 UTC" :: UTCTime
>>> nightT
2017-05-14 00:21:32.714083 UTC
>>> hour24F nightT
"00"

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

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

>>> hour12F t
"04"
>>> hour12F nightT
"12"

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

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

>>> hour24SF nightT
" 0"

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

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

>>> hour12SF nightT
"12"

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

Minute, 00 - 59.

>>> otherT
2017-05-14 17:12:47.897343 MSK
>>> minuteF otherT
"12"

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

Second, without decimal part, 00 - 60.

>>> secondF t
"47"

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

Picosecond, including trailing zeros, 000000000000 - 999999999999.

>>> picosecondF t
"621350000000"

subsecondF :: 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.

>>> subsecondF t
".62135"

For UTCTime and ZonedTime

epochF :: 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.

>>> epochF t
"1494767807"

For Day (and LocalTime and ZonedTime and UTCTime)

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

Same as %m/%d/%y.

>>> dateSlashF t
"05/14/17"

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

Same as %Y-%m-%d.

>>> dateDashF t
"2017-05-14"

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

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

>>> dateSlashLF t
"05/14/17"

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

Year.

>>> yearF t
"2017"

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

Last two digits of year, 00 - 99.

>>> yyF t
"17"

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

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

>>> centuryF t
"20"

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

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

>>> let longMonthT = read "2017-01-12 00:21:32.714083 UTC" :: UTCTime
>>> monthNameF longMonthT
"January"

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

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

>>> monthNameShortF longMonthT
"Jan"

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

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

>>> monthF longMonthT
"01"

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

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

>>> dayOfMonthF t
"14"

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

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

>>> dayOfMonthOrdF t
"14th"

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

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

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

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

>>> dayF t
"134"

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

Year for Week Date format e.g. 2013.

>>> weekYearF t
"2017"

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

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

>>> weekYYF t
"17"

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

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

>>> weekCenturyF t
"20"

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

Week for Week Date format, 01 - 53.

>>> weekF t
"19"

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

Day for Week Date format, 1 - 7.

>>> dayOfWeekF t
"7"

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

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

>>> dayNameShortF t
"Sun"

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

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

>>> dayNameF t
"Sunday"

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

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

>>> weekFromZeroF t
"20"

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

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

>>> dayOfWeekFromZeroF t
"0"

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

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

>>> weekOfYearMonF t
"19"

Time spans, diffs, NominalDiffTime, DiffTime, etc.

diffF #

Arguments

:: 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 #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in years.

>>> epochF t
"1494767807"
>>> yearsF 3 1494767807
"47.399"

daysF #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in days.

>>> daysF 3 1494767807
"17300.553"

hoursF #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in hours.

>>> hoursF 3 3600
"1.000"

minutesF #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in minutes.

>>> minutesF 3 150
"2.500"

secondsF #

Arguments

:: RealFrac n 
=> Int

Decimal places.

-> n 
-> Builder 

Display the absolute value time span in seconds.

>>> secondsF 3 100
"100.000"