| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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:
>>>dateTimeFt -- full date and time "Sun May 14 16:16:47 MSK 2017" >>>hmFt -- hours and minutes "16:16" >>>hmsFt -- hours, minutes and seconds "16:16:47" >>>dateDashFt -- date in ISO 8601 format "2017-05-14" >>>diffFFalse t -- time period (convenient for humans) "3 seconds" >>>diffFTrue t -- point in time (convenient for humans) "3 seconds ago"
Note that two formatters from Formatting.Time have been renamed:
pico ->picosecondFdecimals ->subsecondF
- timeF :: FormatTime a => Text -> a -> Builder
- tzF :: FormatTime a => a -> Builder
- tzNameF :: FormatTime a => a -> Builder
- dateTimeF :: FormatTime a => a -> Builder
- hmF :: FormatTime a => a -> Builder
- hmsF :: FormatTime a => a -> Builder
- hmsLF :: FormatTime a => a -> Builder
- hmsPLF :: FormatTime a => a -> Builder
- dayHalfF :: FormatTime a => a -> Builder
- dayHalfUF :: FormatTime a => a -> Builder
- hour24F :: FormatTime a => a -> Builder
- hour12F :: FormatTime a => a -> Builder
- hour24SF :: FormatTime a => a -> Builder
- hour12SF :: FormatTime a => a -> Builder
- minuteF :: FormatTime a => a -> Builder
- secondF :: FormatTime a => a -> Builder
- picosecondF :: FormatTime a => a -> Builder
- subsecondF :: FormatTime a => a -> Builder
- epochF :: FormatTime a => a -> Builder
- dateSlashF :: FormatTime a => a -> Builder
- dateDashF :: FormatTime a => a -> Builder
- dateSlashLF :: FormatTime a => a -> Builder
- yearF :: FormatTime a => a -> Builder
- yyF :: FormatTime a => a -> Builder
- centuryF :: FormatTime a => a -> Builder
- monthNameF :: FormatTime a => a -> Builder
- monthNameShortF :: FormatTime a => a -> Builder
- monthF :: FormatTime a => a -> Builder
- dayOfMonthF :: FormatTime a => a -> Builder
- dayOfMonthOrdF :: FormatTime a => a -> Builder
- dayOfMonthSF :: FormatTime a => a -> Builder
- dayF :: FormatTime a => a -> Builder
- weekYearF :: FormatTime a => a -> Builder
- weekYYF :: FormatTime a => a -> Builder
- weekCenturyF :: FormatTime a => a -> Builder
- weekF :: FormatTime a => a -> Builder
- dayOfWeekF :: FormatTime a => a -> Builder
- dayNameShortF :: FormatTime a => a -> Builder
- dayNameF :: FormatTime a => a -> Builder
- weekFromZeroF :: FormatTime a => a -> Builder
- dayOfWeekFromZeroF :: FormatTime a => a -> Builder
- weekOfYearMonF :: FormatTime a => a -> Builder
- diffF :: forall n. RealFrac n => Bool -> n -> Builder
- yearsF :: RealFrac n => Int -> n -> Builder
- daysF :: RealFrac n => Int -> n -> Builder
- hoursF :: RealFrac n => Int -> n -> Builder
- minutesF :: RealFrac n => Int -> n -> Builder
- secondsF :: RealFrac n => Int -> n -> Builder
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>>>t2017-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>>>nightT2017-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.
>>>otherT2017-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 #
monthNameShortF :: FormatTime a => a -> Builder #
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 #
dayNameF :: FormatTime a => a -> Builder #
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.
Arguments
| :: RealFrac n | |
| => Bool | Whether to display the |
| -> n | Example: |
| -> 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"
Display the absolute value time span in years.
>>>epochF t"1494767807">>>yearsF 3 1494767807"47.399"
Display the absolute value time span in days.
>>>daysF 3 1494767807"17300.553"
Display the absolute value time span in hours.
>>>hoursF 3 3600"1.000"
Display the absolute value time span in minutes.
>>>minutesF 3 150"2.500"