Skip to contents

new_period() is a constructor for <grates_period> objects aimed at developers.

Usage

new_period(x = integer(), n = 1L, offset = 0L)

is_period(xx)

Arguments

x

[integer]

Vector representing the number of periods since the Unix Epoch (1970-01-01) and a specified offset.

double vectors will be converted via as.integer(floor(x)).

n

[integer]

Number of days that are being grouped by.

offset

[integer]

Value you wish to start counting groups from relative to the Unix Epoch.

xx

R object.

Value

A <grates_period> object.

Details

grates_period objects are stored as the integer number, starting at 0L, of periods since the Unix Epoch (1970-01-01) and a specified offset. Here periods are taken to mean groupings of n consecutive days.

For storage and calculation purposes, offset is scaled relative to n. I.e. offset <- offset %% n and values of x stored relative to this scaled offset.

Examples

new_period(1:10)
#> <grates_period[10]>
#>  [1] "1970-01-02" "1970-01-03" "1970-01-04" "1970-01-05" "1970-01-06"
#>  [6] "1970-01-07" "1970-01-08" "1970-01-09" "1970-01-10" "1970-01-11"