Learn R Programming

clock (version 0.7.1)

year-quarter-day-arithmetic: Arithmetic: year-quarter-day

Description

These are year-quarter-day methods for the arithmetic generics.

  • add_years()

  • add_quarters()

Notably, you cannot add days to a year-quarter-day. For day-based arithmetic, first convert to a time point with as_naive_time() or as_sys_time().

Usage

# S3 method for clock_year_quarter_day
add_years(x, n, ...)

# S3 method for clock_year_quarter_day add_quarters(x, n, ...)

Value

x after performing the arithmetic.

Arguments

x

[clock_year_quarter_day]

A year-quarter-day vector.

n

[integer / clock_duration]

An integer vector to be converted to a duration, or a duration corresponding to the arithmetic function being used. This corresponds to the number of duration units to add. n may be negative to subtract units of duration.

...

These dots are for future extensions and must be empty.

Details

x and n are recycled against each other using tidyverse recycling rules.

Examples

Run this code
x <- year_quarter_day(2019, 1:3)
x

add_quarters(x, 2)

# Make the fiscal year start in March
y <- year_quarter_day(2019, 1:2, 1, start = 3)
y

add_quarters(y, 1)

# What year-month-day does this correspond to?
# Note that the fiscal year doesn't necessarily align with the Gregorian
# year!
as_year_month_day(add_quarters(y, 1))

Run the code above in your browser using DataLab