/
busdates-introduction-vignette.Rmd
executable file
·113 lines (93 loc) · 2.99 KB
/
busdates-introduction-vignette.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
title: "Business dates calculations"
author: "Mick Mioduszewski"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Business dates calculations}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(busdater)
```
## 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.
Jurisdictions and organisations observe different start and end of financial year.
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 4 functions (2 deprecated):
* `get_fy` to return the financial (fiscal) year as integers
* `get_boundary` to return start and end of a month and start and end of financial years
* `FY` deprecated and same as `get_fy`
* `period_boundaries` deprecated and same as `get_boundary`
Enjoy!
## Examples and explanations
## `get_fy` function
Given the current date:
```{r}
Sys.Date()
getOption("busdaterFYstart", default = "07-01")
```
Return the current financial year as integer
```{r}
get_fy()
```
Return financial year for given dates
```{r}
dt <- as.Date(c("01-01-2018", "15-12-2017"), "%d-%m-%Y")
get_fy(date = dt[1])
get_fy(date = dt)
```
Return the next financial year as integer
```{r}
get_fy(offset_period = 1) # current financial year + 1
get_fy(date = dt[1], offset_period = 1)
get_fy(date = dt, offset_period = 1)
```
Return the previous financial year as integer
```{r}
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)
```
## `get_boundary` function
Given the current date:
```{r}
Sys.Date()
getOption("busdaterFYstart", default = "07-01")
```
What is the 1st day of the current financial year
```{r}
get_boundary()
get_boundary(opt_fy_start = "07-01")
get_boundary(opt_fy_start = "01-03")
```
The last day of the current financial year
```{r}
get_boundary(boundary = "last day")
```
The last day of the last calendar year
```{r}
get_boundary(offset_period = -1, bus_period = "CY", boundary = "last day")
```
The last day of month 14 months from now
```{r}
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
```{r}
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")
```