calendar_widen {clock} | R Documentation |
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:
calendar_widen(x, precision)
x |
A calendar vector. |
precision |
A precision. Allowed precisions are dependent on the calendar used. |
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.
x
widened to the supplied precision
.
# Month precision
x <- year_month_day(2019, 1)
x
# Widen to day precision
calendar_widen(x, "day")
# Or second precision
calendar_widen(x, "second")