Title: | Standard Date Calculations for Business |
---|---|
Description: | Get a current financial year, start of current month, End of current month, start of financial year and end of it. Allow for offset from the date. |
Authors: | Mick Mioduszewski [aut, cre] |
Maintainer: | Mick Mioduszewski <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2024-11-11 03:59:17 UTC |
Source: | https://github.com/mickmioduszewski/busdater |
These functions still work but will be removed (defunct) in the next version.
FY()
is a deprecated function. It returns the current financial year.
It also returns financial year based on parameter dates, or financial year
based on a parameter dates and offset_period in years.
FY( date = Sys.Date(), offset_period = 0, optFYstart = getOption("busdaterFYstart", default = "07-01") )
FY( date = Sys.Date(), offset_period = 0, optFYstart = getOption("busdaterFYstart", default = "07-01") )
date |
A date vector for which financial year is required. Date must be POSIXct or POSIXlt or Date objects. |
offset_period |
A positive or negative number coercible to
integer to shift the year by,
e.g. in the case of |
optFYstart |
A 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. 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. |
An integer vector containing the current financial year if offset
offset_period
is 0, otherwise add the offset offset_period
in years.
Other business date functions:
get_boundary()
,
get_fy()
,
period_boundaries()
FY() # deprecated function returns the current financial year as integer dt <- as.Date(c("01-01-2018", "15-12-2017"), "%d-%m-%Y") FY(date = dt[1]) FY(date = dt) FY(offset_period = 1) ## return the next financial year as integer FY(date = dt[1], offset_period = 1) FY(date = dt, offset_period = 1) FY(offset_period=-1) ## return the previous financial year as integer FY(date = dt[1], offset_period = -1) FY(date = dt, offset_period = -1) ## Not run: FY("a") ## will fail because dates are expected. ## End(Not run)
FY() # deprecated function returns the current financial year as integer dt <- as.Date(c("01-01-2018", "15-12-2017"), "%d-%m-%Y") FY(date = dt[1]) FY(date = dt) FY(offset_period = 1) ## return the next financial year as integer FY(date = dt[1], offset_period = 1) FY(date = dt, offset_period = 1) FY(offset_period=-1) ## return the previous financial year as integer FY(date = dt[1], offset_period = -1) FY(date = dt, offset_period = -1) ## Not run: FY("a") ## will fail because dates are expected. ## End(Not run)
The get_boundary
will shift the input date
vector by
a number of months and years i.e. date + offset_period * offset_type
.
It will handle the typical business date arithmetic.
get_boundary( date = Sys.Date(), offset_period = 0, offset_type = "year", bus_period = "FY", boundary = "1st day", opt_fy_start = getOption("busdaterFYstart", default = "07-01") )
get_boundary( date = Sys.Date(), offset_period = 0, offset_type = "year", bus_period = "FY", boundary = "1st day", opt_fy_start = getOption("busdaterFYstart", default = "07-01") )
date |
A date vector for which financial year is required. Date must be POSIXct or POSIXlt or Date objects. |
offset_period |
A positive or negative number coercible to
integer to shift the year by,
e.g. in the case of |
offset_type |
It is either |
bus_period |
It is either |
boundary |
Either |
opt_fy_start |
A 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. 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. |
A vector of dates.
Other business date functions:
FY()
,
get_fy()
,
period_boundaries()
# the 1st day of the current financial year get_boundary() # the last day of the current financial year get_boundary(boundary = "last day") # the last day of the last calendar year get_boundary(offset_period = -1, bus_period = "CY", boundary = "last day") # the last day of month 14 months from now get_boundary(offset_period = 14, offset_type = "month", bus_period = "M", boundary = "last day") # The first day of financial years for dates 3 months before the given dates get_boundary(as.Date(c("02/27/1992", "09/28/2022"), "%m/%d/%Y"), offset_period = -3, offset_type = "month", bus_period = "FY", boundary = "1st day")
# the 1st day of the current financial year get_boundary() # the last day of the current financial year get_boundary(boundary = "last day") # the last day of the last calendar year get_boundary(offset_period = -1, bus_period = "CY", boundary = "last day") # the last day of month 14 months from now get_boundary(offset_period = 14, offset_type = "month", bus_period = "M", boundary = "last day") # The first day of financial years for dates 3 months before the given dates get_boundary(as.Date(c("02/27/1992", "09/28/2022"), "%m/%d/%Y"), offset_period = -3, offset_type = "month", bus_period = "FY", boundary = "1st day")
get_fy()
returns the current financial (fiscal) year.
It also returns financial year based on parameter dates, or financial year
based on a parameter dates and offset_period in years.
get_fy( date = Sys.Date(), offset_period = 0, opt_fy_start = getOption("busdaterFYstart", default = "07-01") )
get_fy( date = Sys.Date(), offset_period = 0, opt_fy_start = getOption("busdaterFYstart", default = "07-01") )
date |
A date vector for which financial year is required. Date must be POSIXct or POSIXlt or Date objects. |
offset_period |
A positive or negative number coercible to
integer to shift the year by,
e.g. in the case of |
opt_fy_start |
A 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. 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. |
An integer vector containing the current financial year if offset
offset_period
is 0, otherwise add the offset offset_period
in years.
Other business date functions:
FY()
,
get_boundary()
,
period_boundaries()
get_fy() ## return the current financial year as integer dt <- as.Date(c("01-01-2018", "15-12-2017"), "%d-%m-%Y") get_fy(date = dt[1]) get_fy(date = dt) get_fy(offset_period = 1) ## return the next financial year as integer get_fy(date = dt[1], offset_period = 1) get_fy(date = dt, offset_period = 1) get_fy(offset_period=-1) ## return the previous financial year as integer get_fy(date = dt[1], offset_period = -1) get_fy(date = dt, offset_period = -1) ## Not run: get_fy("a") ## will fail because dates are expected. ## End(Not run)
get_fy() ## return the current financial year as integer dt <- as.Date(c("01-01-2018", "15-12-2017"), "%d-%m-%Y") get_fy(date = dt[1]) get_fy(date = dt) get_fy(offset_period = 1) ## return the next financial year as integer get_fy(date = dt[1], offset_period = 1) get_fy(date = dt, offset_period = 1) get_fy(offset_period=-1) ## return the previous financial year as integer get_fy(date = dt[1], offset_period = -1) get_fy(date = dt, offset_period = -1) ## Not run: get_fy("a") ## will fail because dates are expected. ## End(Not run)
The period_boundaries
is a deprecated function.
It will shift the input date
vector by
a number of months and years i.e. date + offset_period * offset_type
.
It will handle the typical business date arithmetic.
period_boundaries( date = Sys.Date(), offset_period = 0, offset_type = "year", bus_period = "FY", boundary = "1st day", optFYstart = getOption("busdaterFYstart", default = "07-01") )
period_boundaries( date = Sys.Date(), offset_period = 0, offset_type = "year", bus_period = "FY", boundary = "1st day", optFYstart = getOption("busdaterFYstart", default = "07-01") )
date |
A date vector for which financial year is required. Date must be POSIXct or POSIXlt or Date objects. |
offset_period |
A positive or negative number coercible to
integer to shift the year by,
e.g. in the case of |
offset_type |
It is either |
bus_period |
It is either |
boundary |
Either |
optFYstart |
A 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. 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. |
A vector of dates.
Other business date functions:
FY()
,
get_boundary()
,
get_fy()
# the 1st day of the current financial year period_boundaries() # the last day of the current financial year period_boundaries(boundary = "last day") # the last day of the last calendar year period_boundaries(offset_period = -1, bus_period = "CY", boundary = "last day") # the last day of month 14 months from now period_boundaries(offset_period = 14, offset_type = "month", bus_period = "M", boundary = "last day") # The first day of financial 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")
# the 1st day of the current financial year period_boundaries() # the last day of the current financial year period_boundaries(boundary = "last day") # the last day of the last calendar year period_boundaries(offset_period = -1, bus_period = "CY", boundary = "last day") # the last day of month 14 months from now period_boundaries(offset_period = 14, offset_type = "month", bus_period = "M", boundary = "last day") # The first day of financial 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")