standard_date {bigD}R Documentation

Obtain a standard date format that works across locales

Description

The standard_date() function can be invoked in the format argument of the fdt() function to help generate a locale-specific formatting string of a certain 'type' of formatted date. The type value is a keyword that represents precision and verbosity; the available keywords are "short" (the default), "medium", "long", and "full".

Usage

standard_date(type = c("short", "medium", "long", "full"))

Arguments

type

One of four standardized types for the resulting date that range in precision and verbosity. These are "short" (the default), "medium", "long", and "full".

Value

A vector of class date_time_pattern.

Examples

With an input datetime of "2018-07-04 22:05(America/Vancouver)", we can format as a date in a standardized way with standard_date() providing the correct formatting string. This function is invoked in the format argument of fdt():

fdt(
  input = "2018-07-04 22:05(America/Vancouver)",
  format = standard_date(type = "full")
)
#> [1] "Wednesday, July 4, 2018"

The locale can be changed and we don't have to worry about the particulars of the formatting string (they are standardized across locales).

fdt(
  input = "2018-07-04 22:05(America/Vancouver)",
  format = standard_date(type = "full"),
  locale = fdt_locales_lst$nl
)
#> [1] "woensdag 4 juli 2018"

We can use different type values to control the output date string. The default is "short".

fdt(
  input = "2018-07-04 22:05(America/Vancouver)",
  format = standard_date()
)
#> [1] "7/4/18"

After that, it's "medium":

fdt(
  input = "2018-07-04 22:05(America/Vancouver)",
  format = standard_date(type = "medium")
)
#> [1] "Jul 4, 2018"

Then, "long":

fdt(
  input = "2018-07-04 22:05(America/Vancouver)",
  format = standard_date(type = "long")
)
#> [1] "July 4, 2018"

And finally up to "full", which was demonstrated in the first example.


[Package bigD version 0.2.0 Index]