R: Widen a calendar to a more precise precision

calendar_widen {clock} | R Documentation

## Widen a calendar to a more precise precision

### Description

`calendar_widen()` widens `x` to the specified `precision`. It does so by setting new components to their smallest value.

Each calendar has its own help page describing the precisions that you can widen to:

- year-month-day

- year-month-weekday

- iso-year-week-day

- year-quarter-day

- year-day

### Usage

    calendar_widen(x, precision)

### Arguments

`x` | `[calendar]` A calendar vector.
`precision` | `[character(1)]` A precision. Allowed precisions are dependent on the calendar used.

### Details

A subsecond precision `x` cannot be widened. You cannot widen from, say, `"millisecond"` to `"nanosecond"` precision. clock operates under the philosophy that once you have set the subsecond precision of a calendar, it is "locked in" at that precision. If you expected this to multiply the milliseconds by 1e6 to get to nanosecond precision, you probably want to convert to a time point first, and use `time_point_cast()`.

Generally, clock treats calendars at a specific precision as a range of values. For example, a month precision year-month-day is treated as a range over `[yyyy-mm-01, yyyy-mm-last]`, with no assumption about the day of the month. However, occasionally it is useful to quickly widen a calendar, assuming that you want the beginning of this range to be used for each component. This is where `calendar_widen()` can come in handy.

### Value

`x` widened to the supplied `precision`.

### Examples

    # Month precision
    x <- year_month_day(2019, 1)
    x

    # Widen to day precision
    calendar_widen(x, "day")

    # Or second precision
    calendar_widen(x, "second")

[Package clock version 0.6.0 Index]