format_date_human: Pretty-format a date

View source: R/date-format.R

format_date_humanR Documentation

Pretty-format a date

Description

Returns a string represenation of a date, with month names in the chosen locale and leading zeros removed. Month and date formats are customisable without having to remember format codes. Defaults are geared towards Czech-locale dates.

Usage

format_date_human(
  date = lubridate::now(),
  month_format = c("long", "short", "number"),
  year_format = c("long", "short"),
  locale = "cs_CZ.UTF-8",
  day_dot = TRUE
)

Arguments

date

a date, object of class POSIXct. Defaults to lubridate::now()

month_format

Month format. '"long"' for full month name (the default), '"short"' for month abbreviation, or '"number"' for numeric.

year_format

'"long"' for 4-digit (default), '"short"' for 2-digit.

locale

Locale string. Defaults to '"cs_CZ.UTF-8"'

day_dot

Whether to put a dot after the day. Defaults to TRUE.

Value

a string of same length as input

Examples

format_date_human()
format_date_human(month_format = "short")
format_date_human(month_format = "number")
format_date_human(year_format = "long")
format_date_human(month_format = "short", locale = "fr_FR")
format_date_human(month_format = "short", locale = "en_US", day_dot = FALSE)
format_date_human(date = c(lubridate::now(),
                           lubridate::now() - 100000),
                  month_format = "short", locale = "fr_FR", day_dot = FALSE)

petrbouchal/ptrr documentation built on Oct. 10, 2024, 7:21 a.m.