Introduction to busdater

Working with business dates can be cumbersome and error prone. busdater aims to make it easier, by providing functionality, to get financial year, calendar year and month calculations. It returns start and end of the business periods.

Jurisditions and organisations observe different start and end of financial year. optFYstart parameter is string in the format of “MM-DD” representing the start of financial year, e.g. “01-01” for 1st of January or “07-01” for 1st of July. The default is taken from options and is “07-01” if not present.

This package caters for financial years that have a fixed start date. It does not cater for moving dates e.g. last Friday of September.

The package has 2 functions:

Enjoy!

Examples and explanations

FY function

Given the current date:

Sys.Date()
#> [1] "2019-01-11"
getOption("busdaterFYstart", default = "07-01")
#> [1] "07-01"

Return the current financial year as integer

FY()
#> [1] 2019

Return financial year for given dates

dt <- as.Date(c("01-01-2018", "15-12-2017"), "%d-%m-%Y")
FY(date = dt[1])
#> [1] 2018
FY(date = dt)
#> [1] 2018 2018

Return the next financial year as integer

FY(offset_period = 1) # current financial year + 1
#> [1] 2020
FY(date = dt[1], offset_period = 1)
#> [1] 2019
FY(date = dt, offset_period = 1)
#> [1] 2019 2019

Return the previous financial year as integer

FY(offset_period=-1) ## return the previous financial year as integer
#> [1] 2018
FY(date = dt[1], offset_period = -1)
#> [1] 2017
FY(date = dt, offset_period = -1)
#> [1] 2017 2017

period_boundaries function

Given the current date:

Sys.Date()
#> [1] "2019-01-11"
getOption("busdaterFYstart", default = "07-01")
#> [1] "07-01"

What is the 1st day of the current financial year

period_boundaries()
#> [1] "2018-07-01"
period_boundaries(optFYstart = "07-01")
#> [1] "2018-07-01"
period_boundaries(optFYstart = "01-03")
#> [1] "2019-01-03"

The last day of the current financial year

period_boundaries(boundary = "last day")
#> [1] "2019-06-30"

The last day of the last calendar year

period_boundaries(offset_period = -1, bus_period = "CY", boundary = "last day")
#> [1] "2018-12-31"

The last day of month 14 months from now

period_boundaries(offset_period = 14, offset_type = "month",
                  bus_period = "M", boundary = "last day")
#> [1] "2020-03-31"

The first day of finacial years for dates 3 months before the given dates

period_boundaries(as.Date(c("02/27/1992", "09/28/2022"), "%m/%d/%Y"),
                  offset_period = -3, offset_type = "month",
                  bus_period = "FY", boundary = "1st day")
#> [1] "1991-07-01" "2021-07-01"