Provides candidate format strings for parsing text into a given chronon
(finest time granule), for use as the format argument of
time_parse(). Dispatches the same way as
chronon_format_linear()/chronon_format_cyclical(), but returns every
common format instead of a single default, so time_parse() can try each
in turn and keep whichever parses the most values. Methods should build
their return value with parse_format().
Usage
chronon_parse_linear(x, cal = time_calendar(x), ...)
chronon_parse_cyclical(x, y, ...)Value
A character vector of format templates, ordered from most to
least common, built with parse_format(). The first element typically
matches chronon_format_linear() (for chronon_parse_linear()) or
chronon_format_cyclical() (for chronon_parse_cyclical()) for the
same chronon.
See also
parse_format() for building candidate format strings (what
these methods are built from), time_parse() for using the result as
candidate formats, chronon_format_linear()/chronon_format_cyclical()
for the single default format these are based on.
Examples
chronon_parse_linear(cal_gregorian$year(1L))
#> [1] "{lin(year)}"
chronon_parse_linear(cal_gregorian$month(1L))
#> [1] "{lin(year)}[-/,\\s]+{cyc(month,year)}"
#> [2] "{cyc(month,year)}[-/,\\s]+{lin(year)}"
#> attr(,"regex")
#> [1] TRUE
chronon_parse_linear(cal_gregorian$day(1L))
#> [1] "{lin(year)}[-/,\\s]+{cyc(month,year)}[-/,\\s]+{cyc(day,month)}(?:st|nd|rd|th)?"
#> [2] "{cyc(day,month)}(?:st|nd|rd|th)?[-/,\\s]+{cyc(month,year)}[-/,\\s]+{lin(year)}"
#> [3] "{cyc(month,year)}[-/,\\s]+{cyc(day,month)}(?:st|nd|rd|th)?[-/,\\s]+{lin(year)}"
#> attr(,"regex")
#> [1] TRUE
chronon_parse_linear(cal_isoweek$day(1L))
#> [1] "{lin(year)}[-\\s]*[Ww]{cyc(week,year)}[-\\s]+{cyc(day,week)}"
#> [2] "{cyc(day,week)}[-\\s]+[Ww]{cyc(week,year)}[-\\s]+{lin(year)}"
#> attr(,"regex")
#> [1] TRUE
chronon_parse_cyclical(cal_gregorian$month(1L), cal_gregorian$year(1L))
#> [1] "{cyc(month,year)}"
#> attr(,"regex")
#> [1] FALSE
chronon_parse_cyclical(cal_isoweek$day(1L), cal_isoweek$week(1L))
#> [1] "{cyc(day,week)}"
#> attr(,"regex")
#> [1] FALSE