| Title: | Simple Definition Of Time Intervals |
|---|---|
| Description: | Simple definition of time intervals for the current, previous, and next week, month, quarter and year. |
| Authors: | Alexey Seleznev [aut, cre] |
| Maintainer: | Alexey Seleznev <[email protected]> |
| License: | GPL-2 |
| Version: | 0.7.6 |
| Built: | 2026-05-12 09:07:35 UTC |
| Source: | https://github.com/selesnow/timeperiodsr |
Simple definition of time intervals for the current, previous, and next week, month, quarter and year.
The DESCRIPTION file:
| Package: | timeperiodsR |
| Type: | Package |
| Title: | Simple Definition Of Time Intervals |
| Version: | 0.7.6 |
| License: | GPL-2 |
| Authors@R: | c(person(given = "Alexey", family = "Seleznev", role = c("aut", "cre"), email = "[email protected]")) |
| Author: | Alexey Seleznev [aut, cre] |
| Maintainer: | Alexey Seleznev <[email protected]> |
| Description: | Simple definition of time intervals for the current, previous, and next week, month, quarter and year. |
| BugReports: | https://github.com/selesnow/timeperiodsR/issues |
| URL: | https://selesnow.github.io/timeperiodsR/, https://t.me/R4marketing, https://www.youtube.com/playlist?list=PLD2LDq8edf4qed2KVKfXmKdh0OQcdj9gw |
| Imports: | lubridate |
| VignetteBuilder: | knitr |
| Suggests: | knitr, rmarkdown, httr |
| Encoding: | UTF-8 |
| Language: | en, ru |
| RoxygenNote: | 7.3.2 |
| Repository: | https://selesnow.r-universe.dev |
| Date/Publication: | 2026-05-12 08:45:42 UTC |
| RemoteUrl: | https://github.com/selesnow/timeperiodsr |
| RemoteRef: | HEAD |
| RemoteSha: | eb2ae0d4732b56a981ea3ecac2645e88ec95307d |
Index of help topics:
as_timeperiod Convert date or string vector to timeperiod. check_dayoffs Check if the day is an official day off custom_period Custopm period first_weekend Get first weekend day in period. first_workday Get first workday day in period. last_n_days Start and end of last n days last_n_months Start and end of last n months last_n_quarters Start and end of last n quarters last_n_weeks Start and end of last n weeks last_n_years Start and end of last n years last_weekend Get last weekend day in period. last_workday Get last workday day in period. next_month Start and end of next month next_n_days Start and end of next n days next_n_months Start and end of next n months next_n_quarters Start and end of next n quarters next_n_weeks Start and end of next n weeks next_n_years Start and end of next n weeks next_quarter Start and end of next quarter next_week Start and end of next week next_year Start and end of next year previous_month Start and end of previous month previous_quarter Start and end of previous quarter previous_week Start and end of previous week previous_year Start and end of previous year this_month Start and end of month this_quarter Start and end of quarter this_week Start and end of week this_year Start and end of year timeperiodsR-package Simple Definition Of Time Intervals weekends Get vector with weekends. weekends_length Number of weekdends days in the period. workdays Get vector with workdays. workdays_length Number of workdays in the period.
Alexey Seleznev [aut, cre]
Maintainer: Alexey Seleznev <[email protected]>
Convert any date or string vector to tpr class.
as_timeperiod(x)as_timeperiod(x)
x |
Date or string vector |
Object of tpr class
Alexey Seleznev
See custom_period()
dates <- as.Date(c("2019-09-11", "2019-09-02", "2019-10-11", "2019-08-30")) dates_tpr <- as_timeperiod(dates)dates <- as.Date(c("2019-09-11", "2019-09-02", "2019-10-11", "2019-08-30")) dates_tpr <- as_timeperiod(dates)
Check any date or date vector for is an official day off or not.
check_dayoffs(date = NULL, year = NULL, month = NULL, day = NULL, cc = getOption("timeperiodsR.official_day_offs_country"), pre = getOption("timeperiodsR.official_day_offs_pre"), include_custom_day_offs = TRUE)check_dayoffs(date = NULL, year = NULL, month = NULL, day = NULL, cc = getOption("timeperiodsR.official_day_offs_country"), pre = getOption("timeperiodsR.official_day_offs_pre"), include_custom_day_offs = TRUE)
year |
Year for check |
month |
Month for check |
day |
Month for check. |
date |
Date, or date vector for checking |
cc |
Country, one of ru, ua, kz, by |
pre |
Including shorter working days, 0 or 1 |
include_custom_day_offs |
Including custom dayoffs from options or global variables |
Function use 'isDayOff() API'.
For get official day offs for your country you must install httr package and switch options timeperiodsR.official_day_offs to TRUE or set system variable TPR_DAY_OFFS=TRUE.
Now allow next country:
Russia
Ukraine
Kazakhstan
Belarus
Also you can set default country by options or systen envarible:
timeperiodsR.official_day_offs_country
TPR_COUNTRY
And you can include or exclude shorter working days. Using option timeperiodsR.official_day_offs_pre:
Exclude shorter work days
Include shorter work days
Day marks:
Workday
Day off
Shorten day off
Custom day off
You can set your custom day offs, for example it can be your vacation. Using option timeperiodsR.custom_day_offs or system variable TPR_CUSTOM_DAY_OFFS. In TPR_CUSTOM_DAY_OFFS you can set custom day offs like comma or semicolon list of dates in format YYYY-MM-DD.
Named vector with date and marks
Alexey Seleznev
Official documentation for isDayOff API
ld <- next_n_weeks(n = 2) check_dayoffs(date = ld)ld <- next_n_weeks(n = 2) check_dayoffs(date = ld)
Create tpr object between start and end dates
custom_period( start, end, part = getOption("timeperiodsR.parts"))custom_period( start, end, part = getOption("timeperiodsR.parts"))
start |
Start date in YYYY-MM-DD format |
end |
End date in YYYY-MM-DD format |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length", "workdays", "weekends", "first_workday", "last_workday", "first_weekend", "last_weekend", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
## To create tpr object between two dates customper <- custom_period(start = "2019-09-01", end = "2019-09-05") ## To get vector of date sequences seq(customper) ## Get number of days of previous months length(customper) ## To get start of end dates start(customper) end(customper)## To create tpr object between two dates customper <- custom_period(start = "2019-09-01", end = "2019-09-05") ## To get vector of date sequences seq(customper) ## Get number of days of previous months length(customper) ## To get start of end dates start(customper) end(customper)
Method for get first weekend in timeperiod.
first_weekend(x)first_weekend(x)
x |
tpr object or date vector |
Vector of dates
Alexey Seleznev
pm <- previous_month() # get first weekend pm_first_weekend <- first_weekend(pm)pm <- previous_month() # get first weekend pm_first_weekend <- first_weekend(pm)
Method for get first workday in timeperiod.
first_workday(x)first_workday(x)
x |
tpr object or date vector |
Vector of dates
Alexey Seleznev
pm <- previous_month() # get first workday pm_first_workday <- first_workday(pm)pm <- previous_month() # get first workday pm_first_workday <- first_workday(pm)
Defines first and last date in previous period
last_n_days(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)last_n_days(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see last_n_quarters(), last_n_months(), last_n_years(), last_n_weeks()
## To get start, end and sequence of last 10 days, ## exclude today last10days <- last_n_days(n = 10) ## include today last10days_2 <- last_n_days(n = 10, include_current = TRUE) ## To get vector of date sequences last_n_days(n = 10, part = "sequence") last_n_days(n = 10)$sequence seq(last10days)## To get start, end and sequence of last 10 days, ## exclude today last10days <- last_n_days(n = 10) ## include today last10days_2 <- last_n_days(n = 10, include_current = TRUE) ## To get vector of date sequences last_n_days(n = 10, part = "sequence") last_n_days(n = 10)$sequence seq(last10days)
Defines first and last date in previous period
last_n_months(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)last_n_months(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see last_n_quarters(), last_n_days(), last_n_years(), last_n_weeks()
## To get start, end and sequence of last 2 months, ## exclude current month last2month <- last_n_months(n = 2) ## include current month last2month_2 <- last_n_months(n = 2, include_current = TRUE) ## To get vector of date sequences last_n_months(n = 2, part = "sequence") last_n_months(n = 2)$sequence seq(last2month) ## Get number of days of last 2 months day_nums <- last_n_months(n = 2, part = "length") last_n_months()$length length(last2month)## To get start, end and sequence of last 2 months, ## exclude current month last2month <- last_n_months(n = 2) ## include current month last2month_2 <- last_n_months(n = 2, include_current = TRUE) ## To get vector of date sequences last_n_months(n = 2, part = "sequence") last_n_months(n = 2)$sequence seq(last2month) ## Get number of days of last 2 months day_nums <- last_n_months(n = 2, part = "length") last_n_months()$length length(last2month)
Defines first and last date in previous period
last_n_quarters(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)last_n_quarters(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see last_n_months(), last_n_days(), last_n_years(), last_n_weeks()
## To get start, end and sequence of last 2 quarters, ## exclude current quarter last2quarters <- last_n_quarters(n = 2) ## include current quarter last2quarters_2 <- last_n_quarters(n = 2, include_current = TRUE) ## To get vector of date sequences last_n_quarters(n = 2, part = "sequence") last_n_quarters(n = 2)$sequence seq(last2quarters) ## Get number of days of last 2 quarters day_nums <- last_n_quarters(n = 2, part = "length") last_n_quarters()$length length(last2quarters)## To get start, end and sequence of last 2 quarters, ## exclude current quarter last2quarters <- last_n_quarters(n = 2) ## include current quarter last2quarters_2 <- last_n_quarters(n = 2, include_current = TRUE) ## To get vector of date sequences last_n_quarters(n = 2, part = "sequence") last_n_quarters(n = 2)$sequence seq(last2quarters) ## Get number of days of last 2 quarters day_nums <- last_n_quarters(n = 2, part = "length") last_n_quarters()$length length(last2quarters)
Defines first and last date in previous period
last_n_weeks(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1, include_current = F)last_n_weeks(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1, include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
week_start |
Start of week, default = 1 is Monday, 7 is Sunday |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see last_n_months(), last_n_days(), last_n_years(), last_n_quarters()
## To get start, end and sequence of last 2 weeks, ## exclude current week last2weeks <- last_n_weeks(n = 2) ## include current week last2weeks_2 <- last_n_weeks(n = 2, include_current = TRUE) ## Get last 2 week with start on Sunday lastWeek <- last_n_weeks(n = 2, week_start = 7) ## To get vector of date sequences last_n_weeks(n = 2, part = "sequence") last_n_weeks(n = 2)$sequence seq(last2weeks) ## Get number of days of last 2 weeks day_nums <- last_n_weeks(n = 2, part = "length") last_n_weeks()$length length(last2weeks)## To get start, end and sequence of last 2 weeks, ## exclude current week last2weeks <- last_n_weeks(n = 2) ## include current week last2weeks_2 <- last_n_weeks(n = 2, include_current = TRUE) ## Get last 2 week with start on Sunday lastWeek <- last_n_weeks(n = 2, week_start = 7) ## To get vector of date sequences last_n_weeks(n = 2, part = "sequence") last_n_weeks(n = 2)$sequence seq(last2weeks) ## Get number of days of last 2 weeks day_nums <- last_n_weeks(n = 2, part = "length") last_n_weeks()$length length(last2weeks)
Defines first and last date in previous period
last_n_years(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)last_n_years(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see last_n_months(), last_n_days(), last_n_weeks(), last_n_quarters()
## To get start, end and sequence of last 2 years, ## exclude current year last2years <- last_n_years(n = 2) ## include current year last2years_2 <- last_n_years(n = 2, include_current = TRUE) ## To get vector of date sequences last_n_years(n = 2, part = "sequence") last_n_years(n = 2)$sequence seq(last2years) ## Get number of days of last 2 years day_nums <- last_n_years(n = 2, part = "length") last_n_years()$length length(last2years)## To get start, end and sequence of last 2 years, ## exclude current year last2years <- last_n_years(n = 2) ## include current year last2years_2 <- last_n_years(n = 2, include_current = TRUE) ## To get vector of date sequences last_n_years(n = 2, part = "sequence") last_n_years(n = 2)$sequence seq(last2years) ## Get number of days of last 2 years day_nums <- last_n_years(n = 2, part = "length") last_n_years()$length length(last2years)
Method for get last weekend in timeperiod.
last_weekend(x)last_weekend(x)
x |
tpr object or date vector |
Vector of dates
Alexey Seleznev
pm <- previous_month() # get last weekend pm_last_weekend <- last_weekend(pm)pm <- previous_month() # get last weekend pm_last_weekend <- last_weekend(pm)
Method for get last workday in timeperiod.
last_workday(x)last_workday(x)
x |
tpr object or date vector |
Vector of dates
Alexey Seleznev
pm <- previous_month() # get last workday pm_last_workday <- last_workday(pm)pm <- previous_month() # get last workday pm_last_workday <- last_workday(pm)
Defines first and last date in next month and all dates in month
next_month(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))next_month(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_week(), next_quarter(), next_year()
## To get start, end and sequence of next month nextmonth <- next_month() ## To get vector of date sequences next_month(part = "sequence") next_month()$sequence seq(nextmonth) ## Get number of days of next months day_nums <- next_month(part = "length") next_month()$length length(nextmonth)## To get start, end and sequence of next month nextmonth <- next_month() ## To get vector of date sequences next_month(part = "sequence") next_month()$sequence seq(nextmonth) ## Get number of days of next months day_nums <- next_month(part = "length") next_month()$length length(nextmonth)
Defines first and last date in next period
next_n_days(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)next_n_days(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_n_quarters(), next_n_months(), next_n_years(), next_n_weeks()
## To get start, end and sequence of next 10 days, ## exclude today next10days <- next_n_days(n = 10) ## include today next10days_2 <- next_n_days(n = 10, include_current = TRUE) ## To get vector of date sequences next_n_days(n = 10, part = "sequence") next_n_days(n = 10)$sequence seq(next10days)## To get start, end and sequence of next 10 days, ## exclude today next10days <- next_n_days(n = 10) ## include today next10days_2 <- next_n_days(n = 10, include_current = TRUE) ## To get vector of date sequences next_n_days(n = 10, part = "sequence") next_n_days(n = 10)$sequence seq(next10days)
Defines first and last date in next period
next_n_months(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)next_n_months(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_n_quarters(), next_n_days(), next_n_years(), next_n_weeks()
## To get start, end and sequence of next 2 months, ## exclude current month next2month <- next_n_months(n = 2) ## include current month next2month_2 <- next_n_months(n = 2, include_current = TRUE) ## To get vector of date sequences next_n_months(n = 2, part = "sequence") next_n_months(n = 2)$sequence seq(next2month) ## Get number of days of next 2 months day_nums <- next_n_months(part = "length") next_n_months()$length length(next2month)## To get start, end and sequence of next 2 months, ## exclude current month next2month <- next_n_months(n = 2) ## include current month next2month_2 <- next_n_months(n = 2, include_current = TRUE) ## To get vector of date sequences next_n_months(n = 2, part = "sequence") next_n_months(n = 2)$sequence seq(next2month) ## Get number of days of next 2 months day_nums <- next_n_months(part = "length") next_n_months()$length length(next2month)
Defines first and last date in next period
next_n_quarters(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)next_n_quarters(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_n_months(), next_n_days(), next_n_years(), next_n_weeks()
## To get start, end and sequence of next 2 quarters, ## exclude current quarter next2quarters <- next_n_quarters(n = 2) ## include current quarter next2quarters_2 <- next_n_quarters(n = 2, include_current = TRUE) ## To get vector of date sequences next_n_quarters(n = 2, part = "sequence") next_n_quarters(n = 2)$sequence seq(next2quarters) ## Get number of days of next 2 quarters day_nums <- next_n_quarters(part = "length") next_n_quarters()$length length(next2quarters)## To get start, end and sequence of next 2 quarters, ## exclude current quarter next2quarters <- next_n_quarters(n = 2) ## include current quarter next2quarters_2 <- next_n_quarters(n = 2, include_current = TRUE) ## To get vector of date sequences next_n_quarters(n = 2, part = "sequence") next_n_quarters(n = 2)$sequence seq(next2quarters) ## Get number of days of next 2 quarters day_nums <- next_n_quarters(part = "length") next_n_quarters()$length length(next2quarters)
Defines first and last date in next period
next_n_weeks(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1, include_current = F)next_n_weeks(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1, include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
week_start |
Start of week, default = 1 is Monday, 7 is Sunday |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see last_n_months(), last_n_days(), last_n_years(), last_n_quarters()
## To get start, end and sequence of next 2 weeks, ## exclude current week next2weeks <- next_n_weeks(n = 2) ## include current week next2weeks_2 <- next_n_weeks(n = 2, include_current = TRUE) ## Get next 2 week with start on Sunday nextWeek <- next_n_weeks(n = 2, week_start = 7) ## To get vector of date sequences next_n_weeks(n = 2, part = "sequence") next_n_weeks(n = 2)$sequence seq(next2weeks) ## Get number of days of next 2 weeks day_nums <- next_n_weeks(part = "length") next_n_weeks()$length length(next2weeks)## To get start, end and sequence of next 2 weeks, ## exclude current week next2weeks <- next_n_weeks(n = 2) ## include current week next2weeks_2 <- next_n_weeks(n = 2, include_current = TRUE) ## Get next 2 week with start on Sunday nextWeek <- next_n_weeks(n = 2, week_start = 7) ## To get vector of date sequences next_n_weeks(n = 2, part = "sequence") next_n_weeks(n = 2)$sequence seq(next2weeks) ## Get number of days of next 2 weeks day_nums <- next_n_weeks(part = "length") next_n_weeks()$length length(next2weeks)
Defines first and last date in next period
next_n_years(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)next_n_years(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), include_current = F)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
include_current |
If TRUE incliding current period in sequence |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_n_months(), next_n_days(), next_n_quarters(), next_n_weeks()
## To get start, end and sequence of next 2 years, ## exclude current year next2years <- next_n_years(n = 2) ## include current year next2years_2 <- next_n_years(n = 2, include_current = TRUE) ## To get vector of date sequences next_n_years(n = 2, part = "sequence") next_n_years(n = 2)$sequence seq(next2years) ## Get number of days of next 2 years day_nums <- next_n_years(part = "length") next_n_years()$length length(next2years)## To get start, end and sequence of next 2 years, ## exclude current year next2years <- next_n_years(n = 2) ## include current year next2years_2 <- next_n_years(n = 2, include_current = TRUE) ## To get vector of date sequences next_n_years(n = 2, part = "sequence") next_n_years(n = 2)$sequence seq(next2years) ## Get number of days of next 2 years day_nums <- next_n_years(part = "length") next_n_years()$length length(next2years)
Defines first and last date in n next quarter
next_quarter(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))next_quarter(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_week(), next_month(), next_year()
## To get start, end and sequence of next quarter nextquarter <- next_quarter() ## To get vector of date sequences next_quarter(part = "sequence") next_quarter()$sequence seq(nextquarter) ## Get number of days of next quarter day_nums <- next_quarter(part = "length") next_quarter()$length length(nextquarter)## To get start, end and sequence of next quarter nextquarter <- next_quarter() ## To get vector of date sequences next_quarter(part = "sequence") next_quarter()$sequence seq(nextquarter) ## Get number of days of next quarter day_nums <- next_quarter(part = "length") next_quarter()$length length(nextquarter)
Defines first and next date in n next week
next_week(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1)next_week(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
week_start |
Start of week, default = 1 is Monday, 7 is Sunday |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only next date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_month(), next_quarter(), next_year()
## To get start, end and sequence of next weeks nextweek <- next_week() ## Get next week with start on Sunday nextweeksun <- next_week(week_start = 7) ## To get vector of date sequences next_week(part = "sequence") next_week()$sequence seq(nextweek) ## Get number of days of next 2 weeks day_nums <- next_week(part = "length") next_week()$length length(nextweek)## To get start, end and sequence of next weeks nextweek <- next_week() ## Get next week with start on Sunday nextweeksun <- next_week(week_start = 7) ## To get vector of date sequences next_week(part = "sequence") next_week()$sequence seq(nextweek) ## Get number of days of next 2 weeks day_nums <- next_week(part = "length") next_week()$length length(nextweek)
Defines first and last date in n next year
next_year(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))next_year(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see next_month(), next_quarter(), next_week()
## To get start, end and sequence of next year nextyear <- next_year() ## To get vector of date sequences next_year(part = "sequence") next_year()$sequence seq(nextyear) ## Get number of days of next year day_nums <- next_year(part = "length") next_year()$length length(nextyear)## To get start, end and sequence of next year nextyear <- next_year() ## To get vector of date sequences next_year(part = "sequence") next_year()$sequence seq(nextyear) ## Get number of days of next year day_nums <- next_year(part = "length") next_year()$length length(nextyear)
Defines first and last date in n previous month
previous_month(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))previous_month(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see previous_week(), previous_quarter(), previous_year()
## To get start, end and sequence of previous month previousmonth <- previous_month() ## To get vector of date sequences previous_month(part = "sequence") previous_month()$sequence seq(previousmonth) ## Get number of days of previous months day_nums <- previous_month(part = "length") previous_month()$length length(previousmonth)## To get start, end and sequence of previous month previousmonth <- previous_month() ## To get vector of date sequences previous_month(part = "sequence") previous_month()$sequence seq(previousmonth) ## Get number of days of previous months day_nums <- previous_month(part = "length") previous_month()$length length(previousmonth)
Defines first and last date in n previous quarter
previous_quarter(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))previous_quarter(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see previous_week(), previous_month(), previous_year()
## To get start, end and sequence of previous quarter previousquarter <- previous_quarter() ## To get vector of date sequences previous_quarter(part = "sequence") previous_quarter()$sequence seq(previousquarter) ## Get number of days of previous quarter day_nums <- previous_quarter(part = "length") previous_quarter()$length length(previousquarter)## To get start, end and sequence of previous quarter previousquarter <- previous_quarter() ## To get vector of date sequences previous_quarter(part = "sequence") previous_quarter()$sequence seq(previousquarter) ## Get number of days of previous quarter day_nums <- previous_quarter(part = "length") previous_quarter()$length length(previousquarter)
Defines first and last date in n previous week
previous_week(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1)previous_week(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"), week_start = 1)
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
week_start |
Start of week, default = 1 is Monday, 7 is Sunday |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see previous_quarter(), previous_month(), previous_year()
## To get start, end and sequence of previous weeks previousweek <- previous_week() ## Get previous week with start on Sunday previousweeksun <- previous_week(week_start = 7) ## To get vector of date sequences previous_week(part = "sequence") previous_week()$sequence seq(previousweek) ## Get number of days of previous 2 weeks day_nums <- previous_week(part = "length") previous_week()$length length(previousweek)## To get start, end and sequence of previous weeks previousweek <- previous_week() ## Get previous week with start on Sunday previousweeksun <- previous_week(week_start = 7) ## To get vector of date sequences previous_week(part = "sequence") previous_week()$sequence seq(previousweek) ## Get number of days of previous 2 weeks day_nums <- previous_week(part = "length") previous_week()$length length(previousweek)
Defines first and last date in n previous year
previous_year(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))previous_year(x = Sys.Date(), n = 1, part = getOption("timeperiodsR.parts"))
x |
Date object |
n |
Number of periods for offset |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see previous_week(), previous_month(), previous_quarter()
## To get start, end and sequence of previous year previousyear <- previous_year() ## To get vector of date sequences previous_year(part = "sequence") previous_year()$sequence seq(previousyear) ## Get number of days of previous year day_nums <- previous_year(part = "length") previous_year()$length length(previousyear)## To get start, end and sequence of previous year previousyear <- previous_year() ## To get vector of date sequences previous_year(part = "sequence") previous_year()$sequence seq(previousyear) ## Get number of days of previous year day_nums <- previous_year(part = "length") previous_year()$length length(previousyear)
Defines first and last date in month
this_month(x = Sys.Date(), part = getOption("timeperiodsR.parts"))this_month(x = Sys.Date(), part = getOption("timeperiodsR.parts"))
x |
Date object |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see this_week(), this_quarter(), this_year()
## To get start, end and sequence of this month thismonth <- this_month() ## To get vector of date sequences this_month(part = "sequence") this_month()$sequence seq(thismonth) ## Get number of days of this months day_nums <- this_month(part = "length") this_month()$length length(thismonth)## To get start, end and sequence of this month thismonth <- this_month() ## To get vector of date sequences this_month(part = "sequence") this_month()$sequence seq(thismonth) ## Get number of days of this months day_nums <- this_month(part = "length") this_month()$length length(thismonth)
Defines first and last date in quarter
this_quarter(x = Sys.Date(), part = getOption("timeperiodsR.parts"))this_quarter(x = Sys.Date(), part = getOption("timeperiodsR.parts"))
x |
Date object |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see this_week(), this_month(), this_year()
## To get start, end and sequence of this quarter thisquarter <- this_quarter() ## To get vector of date sequences this_quarter(part = "sequence") this_quarter()$sequence seq(thisquarter) ## Get number of days of this quarter day_nums <- this_quarter(part = "length") this_quarter()$length length(thisquarter)## To get start, end and sequence of this quarter thisquarter <- this_quarter() ## To get vector of date sequences this_quarter(part = "sequence") this_quarter()$sequence seq(thisquarter) ## Get number of days of this quarter day_nums <- this_quarter(part = "length") this_quarter()$length length(thisquarter)
Defines first and last date in week
this_week(x = Sys.Date(), part = getOption("timeperiodsR.parts"), week_start = 1)this_week(x = Sys.Date(), part = getOption("timeperiodsR.parts"), week_start = 1)
x |
Date object |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
week_start |
Start of week, default = 1 is Monday, 7 is Sunday |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see this_quarter(), this_month(), this_year()
## To get start, end and sequence of this weeks thisweek <- this_week() ## Get this week with start on Sunday thisweeksun <- this_week(week_start = 7) ## To get vector of date sequences this_week(part = "sequence") this_week()$sequence seq(thisweek) ## Get number of days of this 2 weeks day_nums <- this_week(part = "length") this_week()$length length(thisweek)## To get start, end and sequence of this weeks thisweek <- this_week() ## Get this week with start on Sunday thisweeksun <- this_week(week_start = 7) ## To get vector of date sequences this_week(part = "sequence") this_week()$sequence seq(thisweek) ## Get number of days of this 2 weeks day_nums <- this_week(part = "length") this_week()$length length(thisweek)
Defines first and last date in year
this_year(x = Sys.Date(), part = getOption("timeperiodsR.parts"))this_year(x = Sys.Date(), part = getOption("timeperiodsR.parts"))
x |
Date object |
part |
Part of period you need to receive, one of "all", "start", "end","sequence", "length". See details. |
You can get object of tpr class with all components or specify which component you need, use part for manage this option:
all - get all components
start - get only first date of period
end - get only last date of period
start - get vector of all dates in period
length - get number of dates in period
Object of tpr class
Alexey Seleznev
For get next other periods see this_week(), this_month(), this_year()
## To get start, end and sequence of this year thisyear <- this_year() ## To get vector of date sequences this_year(part = "sequence") this_year()$sequence seq(thisyear) ## Get number of days of this year day_nums <- this_year(part = "length") this_year()$length length(thisyear)## To get start, end and sequence of this year thisyear <- this_year() ## To get vector of date sequences this_year(part = "sequence") this_year()$sequence seq(thisyear) ## Get number of days of this year day_nums <- this_year(part = "length") this_year()$length length(thisyear)
Filtring timeperiods operators.
x %.in% y x %left_in% y x %left_out% y x %right_in% y x %right_out% yx %.in% y x %left_in% y x %left_out% y x %right_in% y x %right_out% y
x |
left Date or tpr object |
y |
Right tpr object. |
Date sequence or logical vector
Alexey Seleznev
For get more examples see vignette: vignette("tpr_intro", package = "timeperiodsR")
period1 <- this_month("2019-11-07") period2 <- previous_week("2019-11-07") period1 period1 period1 period1period1 <- this_month("2019-11-07") period2 <- previous_week("2019-11-07") period1 period1 period1 period1
Method for get vector of weekends from timeperiod.
weekends(x)weekends(x)
x |
tpr object or date vector |
Vector of dates
Alexey Seleznev
pm <- previous_month() # get weekends pm_weekends <- weekends(pm)pm <- previous_month() # get weekends pm_weekends <- weekends(pm)
Method for get number of weekdays days in period. Weekends is suturday and sunday.
weekends_length(x)weekends_length(x)
x |
tpr object or date vector |
Integer
Alexey Seleznev
pm <- previous_month() # weekends day number pm_wd_len <- weekends_length(pm)pm <- previous_month() # weekends day number pm_wd_len <- weekends_length(pm)
Method for get vector of workdays from timeperiod.
workdays(x)workdays(x)
x |
tpr object or date vector |
Vector of dates
Alexey Seleznev
pm <- previous_month() # get workdays pm_workdays <- workdays(pm)pm <- previous_month() # get workdays pm_workdays <- workdays(pm)
Method for get number of workdays in period. workdays is monday - friday.
workdays_length(x)workdays_length(x)
x |
tpr object or date vector |
Integer
Alexey Seleznev
pm <- previous_month() # workdays number pm_wd_len <- workdays_length(pm)pm <- previous_month() # workdays number pm_wd_len <- workdays_length(pm)