Safe Haskell | None |
---|---|

Language | Haskell2010 |

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

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

`hmF`

– hours and minutes:`>>>`

"16:20"`hmF t`

`hmsF`

– hours, minutes and seconds:`>>>`

"16:20:45"`hmsF t`

`dateDashF`

– date in ISO 8601 format:`>>>`

"2018-02-14"`dateDashF t`

`diffF`

– either a time period or a point in time, in a convenient for humans format:`>>>`

"2 minutes"`diffF False 130 -- time period (130 seconds)`

`>>>`

"in 2 minutes"`diffF True 130 -- point in time (130 seconds in the future)`

Note that two formatters from `Formatting.Time`

are called differently here:

pico ->`picosecondF`

decimals ->`subsecondF`

## Synopsis

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

.

`>>>`

2018-02-14 16:20:45.5 CST`t`

`>>>`

"-0600"`tzF t`

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

Timezone name.

`>>>`

"CST"`tzNameF t`

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

As `dateTimeFmt`

`locale`

(e.g. `%a %b %e %H:%M:%S %Z %Y`

).

`>>>`

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

# For

`TimeOfDay`

(and `LocalTime`

and `ZonedTime`

and `UTCTime`

)

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

Same as `%H:%M`

.

`>>>`

"16:20"`hmF t`

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

Same as `%H:%M:%S`

.

`>>>`

"16:20:45"`hmsF t`

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

As `timeFmt`

`locale`

(e.g. `%H:%M:%S`

).

`>>>`

"16:20:45"`hmsLF t`

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

As `time12Fmt`

`locale`

(e.g. `%I:%M:%S %p`

).

`>>>`

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

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

Day half from (`amPm`

`locale`

), converted to lowercase, `am`

, `pm`

.

`>>>`

"pm"`dayHalfF t`

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

Day half from (`amPm`

`locale`

), `AM`

, `PM`

.

`>>>`

"PM"`dayHalfUF t`

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

Hour, 24-hour, leading 0 as needed, `00`

- `23`

.

`>>>`

"16"`hour24F t`

`>>>`

"00"`hour24F midnight`

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

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

- `12`

.

`>>>`

"04"`hour12F t`

`>>>`

"12"`hour12F midnight`

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

Hour, 24-hour, leading space as needed, ` 0`

- `23`

.

`>>>`

"16"`hour24SF t`

`>>>`

" 0"`hour24SF midnight`

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

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

- `12`

.

`>>>`

" 4"`hour12SF t`

`>>>`

"12"`hour12SF midnight`

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

Minute, `00`

- `59`

.

`>>>`

"20"`minuteF t`

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

Second, without decimal part, `00`

- `60`

.

`>>>`

"45"`secondF t`

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

Picosecond, including trailing zeros, `000000000000`

- `999999999999`

.

`>>>`

"500000000000"`picosecondF t`

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.

`>>>`

".5"`subsecondF t`

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

.

`>>>`

"1518646845"`epochF t`

# For

`Day`

(and `LocalTime`

and `ZonedTime`

and `UTCTime`

)

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

Same as `%m/%d/%y`

.

`>>>`

"02/14/18"`dateSlashF t`

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

Same as `%Y-%m-%d`

.

`>>>`

"2018-02-14"`dateDashF t`

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

As `dateFmt`

`locale`

(e.g. `%m/%d/%y`

).

`>>>`

"02/14/18"`dateSlashLF t`

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

Year.

`>>>`

"2018"`yearF t`

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

Last two digits of year, `00`

- `99`

.

`>>>`

"18"`yyF t`

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

Century (being the first two digits of the year), `00`

- `99`

.

`>>>`

"20"`centuryF t`

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

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

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

Month of year, leading 0 as needed, `01`

- `12`

.

`>>>`

"02"`monthF t`

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

Day of month, leading 0 as needed, `01`

- `31`

.

`>>>`

"14"`dayOfMonthF t`

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

Day of month, `1st`

, `2nd`

, `25th`

, etc.

`>>>`

"14th"`dayOfMonthOrdF t`

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`

.

`>>>`

"045"`dayF t`

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

Year for Week Date format e.g. `2013`

.

`>>>`

"2018"`weekYearF t`

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

Last two digits of year for Week Date format, `00`

- `99`

.

`>>>`

"18"`weekYYF t`

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

Century (first two digits of year) for Week Date format, `00`

- `99`

.

`>>>`

"20"`weekCenturyF t`

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

Week for Week Date format, `01`

- `53`

.

`>>>`

"07"`weekF t`

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

Day for Week Date format, `1`

- `7`

.

`>>>`

"3"`dayOfWeekF t`

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

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

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

Week number of year, where weeks start on Sunday (as
`sundayStartWeek`

), `00`

- `53`

.

`>>>`

"06"`weekFromZeroF t`

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

Day of week number, `0`

(= Sunday) - `6`

(= Saturday).

`>>>`

"3"`dayOfWeekFromZeroF t`

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

Week number of year, where weeks start on Monday (as
`mondayStartWeek`

), `00`

- `53`

.

`>>>`

"07"`weekOfYearMonF t`

# Time spans, diffs,

`NominalDiffTime`

, `DiffTime`

, etc.

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

.

`>>>`

"a minute"`diffF False 100`

`>>>`

"in a minute"`diffF True 100`

Display the absolute value time span in years.

`>>>`

"1518646845"`epochF t -- time passed since Jan 1, 1970`

`>>>`

"48.156"`yearsF 3 1518646845`

Display the absolute value time span in days.

`>>>`

"17576.931"`daysF 3 1518646845`

Display the absolute value time span in hours.

`>>>`

"1.000"`hoursF 3 3600`

Display the absolute value time span in minutes.

`>>>`

"2.500"`minutesF 3 150`