Align a 'timeDate' object to regular date/time stamps
calendar-align.RdAligns a "timeDate" object to regular date/time stamps.
Usage
# S4 method for class 'timeDate'
align(x, by = "1d", offset = "0s")
alignDaily(x, include.weekends=FALSE)
alignMonthly(x, include.weekends=FALSE)
alignQuarterly(x, include.weekends=FALSE)Arguments
- x
an object of class
"timeDate".- by
a character string formed from an integer length and a period identifier. Valid values are "w", "d", "h", "m", "s", for weeks, days, hours, minutes and seconds. For example a bi-weekly period is expressed as
"2w".- offset
a character string to set an offset formed from an integer length and a period identifier in the same way as for argument
by.- include.weekends
logical value indicating whether weekends should be included.
Details
The functions alignDaily, alignMonthly,
alignMonthly are simple to use functions which
generate end-of-day, end-of-month, and end-of quarter
"timeDate" objects. Weekends are excluded by
default. Optionally they can be added setting the
argument include.weekends = TRUE.
Examples
## align
# align bi-weekly with a 3 days offset
(tC <- timeCalendar())
#> GMT
#> [1] [2026-01-01] [2026-02-01] [2026-03-01] [2026-04-01] [2026-05-01]
#> [6] [2026-06-01] [2026-07-01] [2026-08-01] [2026-09-01] [2026-10-01]
#> [11] [2026-11-01] [2026-12-01]
align(tC, by = "2w", offset = "3d")
#> GMT
#> [1] [2026-01-04] [2026-01-18] [2026-02-01] [2026-02-15] [2026-03-01]
#> [6] [2026-03-15] [2026-03-29] [2026-04-12] [2026-04-26] [2026-05-10]
#> [11] [2026-05-24] [2026-06-07] [2026-06-21] [2026-07-05] [2026-07-19]
#> [16] [2026-08-02] [2026-08-16] [2026-08-30] [2026-09-13] [2026-09-27]
#> [21] [2026-10-11] [2026-10-25] [2026-11-08] [2026-11-22]
## alignDaily
# simple to use functions
alignDaily(tC)
#> GMT
#> [1] [2026-01-01] [2026-01-02] [2026-01-05] [2026-01-06] [2026-01-07]
#> [6] [2026-01-08] [2026-01-09] [2026-01-12] [2026-01-13] [2026-01-14]
#> [11] [2026-01-15] [2026-01-16] [2026-01-19] [2026-01-20] [2026-01-21]
#> [16] [2026-01-22] [2026-01-23] [2026-01-26] [2026-01-27] [2026-01-28]
#> [21] [2026-01-29] [2026-01-30] [2026-02-02] [2026-02-03] [2026-02-04]
#> [26] [2026-02-05] [2026-02-06] [2026-02-09] [2026-02-10] [2026-02-11]
#> [31] [2026-02-12] [2026-02-13] [2026-02-16] [2026-02-17] [2026-02-18]
#> [36] [2026-02-19] [2026-02-20] [2026-02-23] [2026-02-24] [2026-02-25]
#> [41] [2026-02-26] [2026-02-27] [2026-03-02] [2026-03-03] [2026-03-04]
#> [46] [2026-03-05] [2026-03-06] [2026-03-09] [2026-03-10] [2026-03-11]
#> [51] [2026-03-12] [2026-03-13] [2026-03-16] [2026-03-17] [2026-03-18]
#> [56] [2026-03-19] [2026-03-20] [2026-03-23] [2026-03-24] [2026-03-25]
#> [61] [2026-03-26] [2026-03-27] [2026-03-30] [2026-03-31] [2026-04-01]
#> [66] [2026-04-02] [2026-04-03] [2026-04-06] [2026-04-07] [2026-04-08]
#> [71] [2026-04-09] [2026-04-10] [2026-04-13] [2026-04-14] [2026-04-15]
#> [76] [2026-04-16] [2026-04-17] [2026-04-20] [2026-04-21] [2026-04-22]
#> [81] [2026-04-23] [2026-04-24] [2026-04-27] [2026-04-28] [2026-04-29]
#> [86] [2026-04-30] [2026-05-01] [2026-05-04] [2026-05-05] [2026-05-06]
#> [91] [2026-05-07] [2026-05-08] [2026-05-11] [2026-05-12] [2026-05-13]
#> [96] [2026-05-14] [2026-05-15] [2026-05-18] [2026-05-19] [2026-05-20]
#> ...
#> [ reached getRmetricsOptions('max.print') | getOption('max.print') -- omitted 139 rows ]]
alignDaily(tC, include.weekends = TRUE)
#> GMT
#> [1] [2026-01-01] [2026-01-02] [2026-01-03] [2026-01-04] [2026-01-05]
#> [6] [2026-01-06] [2026-01-07] [2026-01-08] [2026-01-09] [2026-01-10]
#> [11] [2026-01-11] [2026-01-12] [2026-01-13] [2026-01-14] [2026-01-15]
#> [16] [2026-01-16] [2026-01-17] [2026-01-18] [2026-01-19] [2026-01-20]
#> [21] [2026-01-21] [2026-01-22] [2026-01-23] [2026-01-24] [2026-01-25]
#> [26] [2026-01-26] [2026-01-27] [2026-01-28] [2026-01-29] [2026-01-30]
#> [31] [2026-01-31] [2026-02-01] [2026-02-02] [2026-02-03] [2026-02-04]
#> [36] [2026-02-05] [2026-02-06] [2026-02-07] [2026-02-08] [2026-02-09]
#> [41] [2026-02-10] [2026-02-11] [2026-02-12] [2026-02-13] [2026-02-14]
#> [46] [2026-02-15] [2026-02-16] [2026-02-17] [2026-02-18] [2026-02-19]
#> [51] [2026-02-20] [2026-02-21] [2026-02-22] [2026-02-23] [2026-02-24]
#> [56] [2026-02-25] [2026-02-26] [2026-02-27] [2026-02-28] [2026-03-01]
#> [61] [2026-03-02] [2026-03-03] [2026-03-04] [2026-03-05] [2026-03-06]
#> [66] [2026-03-07] [2026-03-08] [2026-03-09] [2026-03-10] [2026-03-11]
#> [71] [2026-03-12] [2026-03-13] [2026-03-14] [2026-03-15] [2026-03-16]
#> [76] [2026-03-17] [2026-03-18] [2026-03-19] [2026-03-20] [2026-03-21]
#> [81] [2026-03-22] [2026-03-23] [2026-03-24] [2026-03-25] [2026-03-26]
#> [86] [2026-03-27] [2026-03-28] [2026-03-29] [2026-03-30] [2026-03-31]
#> [91] [2026-04-01] [2026-04-02] [2026-04-03] [2026-04-04] [2026-04-05]
#> [96] [2026-04-06] [2026-04-07] [2026-04-08] [2026-04-09] [2026-04-10]
#> ...
#> [ reached getRmetricsOptions('max.print') | getOption('max.print') -- omitted 235 rows ]]
# align to end-of-month dates
alignMonthly(tC)
#> GMT
#> [1] [2026-01-30] [2026-02-27] [2026-03-31] [2026-04-30] [2026-05-30]
#> [6] [2026-06-30] [2026-07-31] [2026-08-31] [2026-09-30] [2026-10-30]
#> [11] [2026-11-30] [2026-12-31]