Combines one or more format strings into a character vector for use as
the format argument of time_parse(). When multiple format strings are
given, time_parse() tries each in turn and keeps whichever parses the
most values, so parse_format() is the usual way to build up a set of
candidates to try (it's also how chronon_parse_linear()/
chronon_parse_cyclical() methods build theirs). It can optionally mark
its candidates as using regex syntax rather than literal text; see the
regex argument below.
Arguments
- ...
Format strings, as for the
formatargument oftime_parse().- regex
Whether the literal (non-token) text in
...should be matched as regular expression syntax rather than escaped literally (e.g."[/-]"to accept either/or-as a separator). This is a niche option for irregular text - most formats leave it at the default,FALSE. See theregexargument oftime_parse()for details.
Value
A character vector of format strings suitable for time_parse(),
with a "regex" attribute for the regex argument the parser.
See also
time_parse() for using the result as format,
chronon_parse_linear()/chronon_parse_cyclical() for calendar-specific
candidates built this way.
Examples
parse_format("{lin(year)}-{cyc(month, year)}-{cyc(day, month)}")
#> [1] "{lin(year)}-{cyc(month, year)}-{cyc(day, month)}"
#> attr(,"regex")
#> [1] FALSE
# Multiple candidates are tried in turn, keeping whichever parses most values
parse_format(
"{lin(year)}-{cyc(month, year)}-{cyc(day, month)}",
"{lin(year)}/{cyc(month, year)}/{cyc(day, month)}"
)
#> [1] "{lin(year)}-{cyc(month, year)}-{cyc(day, month)}"
#> [2] "{lin(year)}/{cyc(month, year)}/{cyc(day, month)}"
#> attr(,"regex")
#> [1] FALSE
# regex = TRUE treats the surrounding text as regular expression syntax
parse_format(
"{lin(year)}[/-]{cyc(month, year)}[/-]{cyc(day, month)}",
regex = TRUE
)
#> [1] "{lin(year)}[/-]{cyc(month, year)}[/-]{cyc(day, month)}"
#> attr(,"regex")
#> [1] TRUE