Formats date(time)s as strings according to the specified format
s and locale
, applying some typographic tweaks. A convenience wrapper around
stringi::stri_datetime_format()
.
Usage
phrase_datetime(x, format = "date_long", locale = funky::config_val("locale"))
Arguments
- x
Date(s) or datetime(s) to format. A date, datetime, factor or character vector.
- format
Format string(s) defining how to phrase
x
. Possible values include"date_short"
,"date_medium"
,"date_long"
,"date_full"
,"time_short"
,"time_medium"
,"time_long"
and"time_full"
. Seestringi::stri_datetime_format()
for details.- locale
NULL
or''
for the default locale, or a single string with locale identifier; a non-Gregorian calendar may be specified by setting the@calendar=name
keyword
See also
Other spoken language functions:
add_definite_article_de()
,
decline_noun_de()
,
definite_article_de()
,
definite_article_de_declined()
,
n_ify()
,
rank_nr()
,
write_out_n()
Examples
salim::phrase_datetime("2020-02-20")
#> [1] "February 20, 2020"
salim::phrase_datetime(x = as.POSIXct(0L),
format = c("date_full",
"time_full"),
locale = "de-CH")
#> [1] "Donnerstag, 1. Januar 1970" "01:00:00 Mitteleuropäische Normalzeit"
# note that character input is internally converted to a datetime using `as.POSIXct()` with the
# default `format` which ignores possible time components:
salim::phrase_datetime(x = "2020-02-20T13:13:13Z",
format = c("date_full",
"time_full"))
#> [1] "Thursday, February 20, 2020" "12:00:00 AM Central European Standard Time"
# hence it's recommended to directly provide input as datetimes:
salim::phrase_datetime(x = clock::date_time_parse_RFC_3339("2020-02-20T13:13:13Z"),
format = c("date_full",
"time_full"))
#> [1] "Thursday, February 20, 2020" "2:13:13 PM Central European Standard Time"