time_add: Add/subtract timespans to dates and date-times

View source: R/time_arithmetic.R

time_addR Documentation

Add/subtract timespans to dates and date-times

Description

A very fast method of adding time units to dates and date-times.

Usage

time_add(
  x,
  timespan,
  roll_month = getOption("timeplyr.roll_month", "xlast"),
  roll_dst = getOption("timeplyr.roll_dst", c("NA", "xfirst"))
)

time_subtract(
  x,
  timespan,
  roll_month = getOption("timeplyr.roll_month", "xlast"),
  roll_dst = getOption("timeplyr.roll_dst", c("NA", "xfirst"))
)

time_floor(x, timespan, week_start = getOption("lubridate.week.start", 1))

time_ceiling(
  x,
  timespan,
  week_start = getOption("lubridate.week.start", 1),
  change_on_boundary = is_date(x)
)

Arguments

x

Time vector.
E.g. a Date, POSIXt, numeric or any time-based vector.

timespan

timespan.

roll_month

See ?timechange::time_add. Additional choices include xlast (default) and xfirst. These work conceptually similar to skipped DST intervals.

roll_dst

See ?timechange::time_add.

week_start

day on which week starts following ISO conventions - 1 means Monday, 7 means Sunday (default). When label = TRUE, this will be the first level of the returned factor. You can set lubridate.week.start option to control this parameter globally.

change_on_boundary

?timechange::time_floor

Details

The methods are continuously being improved over time. Date arithmetic should be very fast regardless of the timespan supplied. Date-time arithmetic, specifically when supplied days, weeks, months and years, is being improved.

Value

A date, date-time, or other time-based vector.


timeplyr documentation built on April 3, 2025, 6:15 p.m.