as_yearquarter()
is a generic for coercing input in to <grates_yearquarter>
.
Character input is first parsed using as.Date()
. POSIXct and POSIXlt are
all converted, with the timezone respected.
Usage
as_yearquarter(x, ...)
# Default S3 method
as_yearquarter(x, ...)
# S3 method for class 'Date'
as_yearquarter(x, ...)
# S3 method for class 'POSIXt'
as_yearquarter(x, ...)
# S3 method for class 'character'
as_yearquarter(x, ...)
# S3 method for class 'factor'
as_yearquarter(x, ...)
Arguments
- x
R object
- ...
Only used For character input where additional arguments are passed through to
as.Date()
.
Note
Internally <grates_yearquarter>
objects are stored as the number of
quarters (starting at 0) since the Unix Epoch (1970-01-01).
Examples
as_yearquarter(Sys.Date())
#> <grates_yearquarter[1]>
#> [1] "2024-Q4"
as_yearquarter(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"), interval = 2)
#> <grates_yearquarter[1]>
#> [1] "2019-Q1"
as_yearquarter("2019-05-03")
#> <grates_yearquarter[1]>
#> [1] "2019-Q2"