Skip to content

Commit 33c67bb

Browse files
v0.1.2 (#11)
* Add lint tests * Add functions for `this_week`, `last_week`, and `next_week`
1 parent fcccb21 commit 33c67bb

27 files changed

+266
-184
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ cache: packages
66
latex: false
77
r_packages:
88
- covr
9+
r_github_packages:
10+
- jimhester/lintr
911

1012
env:
1113
global:

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ Imports:
1717
hms (>= 0.3)
1818
Suggests:
1919
knitr (>= 1.17),
20+
lintr (>= 1.0.1.9000),
2021
testthat (>= 1.0.2)
2122
Remotes:
22-
tidyverse/lubridate,
2323
tidyverse/hms,
2424
yihui/knitr,
25+
jimhester/lintr,
26+
tidyverse/lubridate,
2527
r-lib/testthat
2628
VignetteBuilder: knitr
2729
RoxygenNote: 6.0.1

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ export(hms)
66
export(is.weekday)
77
export(is.weekend)
88
export(last_month)
9+
export(last_week)
910
export(next_month)
11+
export(next_week)
1012
export(this_month)
13+
export(this_week)
1114
export(tomorrow)
1215
export(yesterday)
1316
import(lubridate)

R/instants.R

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
#'
33
#' @export yesterday
44
#' @param tzone a character vector specifying which time zone you would like to
5-
#' find the previous date of. tzone defaults to the system time zone set on your
6-
#' computer.
5+
#' find the previous date of. tzone defaults to the system time zone set on
6+
#' your computer.
77
#' @return the previous date as a Date object
88
#'
9+
#' @seealso \code{\link{tomorrow}}
10+
#'
911
#' @examples
1012
#' yesterday()
1113
#' yesterday("UTC")
@@ -17,10 +19,12 @@ yesterday <- function(tzone = "") {
1719
#'
1820
#' @export tomorrow
1921
#' @param tzone a character vector specifying which time zone you would like to
20-
#' find the previous date of. tzone defaults to the system time zone set on your
21-
#' computer.
22+
#' find the previous date of. tzone defaults to the system time zone set on
23+
#' your computer.
2224
#' @return the previous date as a Date object
2325
#'
26+
#' @seealso \code{\link{yesterday}}
27+
#'
2428
#' @examples
2529
#' tomorrow()
2630
#' tomorrow("UTC")
@@ -31,10 +35,11 @@ tomorrow <- function(tzone = "") {
3135
#' The date x days ago
3236
#'
3337
#' @export days_ago
34-
#' @param days an integer specifying the number of days to subtract from the current
38+
#' @param days an integer specifying the number of days to subtract from the
39+
#' current
3540
#' @param tzone a character vector specifying which time zone you would like to
36-
#' find the previous date of. tzone defaults to the system time zone set on your
37-
#' computer.
41+
#' find the previous date of. tzone defaults to the system time zone set on
42+
#' your computer.
3843
#' @return the date, x days ago
3944
#'
4045
#' @examples
@@ -49,8 +54,8 @@ days_ago <- function(days = 0, tzone = "") {
4954
#' @export days_hence
5055
#' @param days an integer specifying the number of days to add from the current
5156
#' @param tzone a character vector specifying which time zone you would like to
52-
#' find the previous date of. tzone defaults to the system time zone set on your
53-
#' computer.
57+
#' find the previous date of. tzone defaults to the system time zone set on
58+
#' your computer.
5459
#' @return the date, x days hence
5560
#'
5661
#' @examples
@@ -64,8 +69,8 @@ days_hence <- function(days = 0, tzone = "") {
6469
#'
6570
#' @export this_month
6671
#' @param tzone a character vector specifying which time zone you would like to
67-
#' find the current month of. tzone defaults to the system time zone set on your
68-
#' computer.
72+
#' find the current month of. tzone defaults to the system time zone set on
73+
#' your computer.
6974
#' @return the current month as a Date object
7075
this_month <- function(tzone = "") {
7176
floor_date(x = today(tzone = tzone), unit = "month")
@@ -75,8 +80,8 @@ this_month <- function(tzone = "") {
7580
#'
7681
#' @export last_month
7782
#' @param tzone a character vector specifying which time zone you would like to
78-
#' find the previous month of. tzone defaults to the system time zone set on your
79-
#' computer.
83+
#' find the previous month of. tzone defaults to the system time zone set on
84+
#' your computer.
8085
#' @return the previous month as a Date object
8186
last_month <- function(tzone = "") {
8287
floor_date(x = today(tzone = tzone), unit = "month") - months(1)
@@ -93,6 +98,39 @@ next_month <- function(tzone = "") {
9398
floor_date(x = today(tzone = tzone), unit = "month") + months(1)
9499
}
95100

101+
#' The current week
102+
#'
103+
#' @export this_week
104+
#' @param tzone a character vector specifying which time zone you would like to
105+
#' find the current week of. tzone defaults to the system time zone set on
106+
#' your computer.
107+
#' @return the current week as a Date object
108+
this_week <- function(tzone = "") {
109+
floor_date(x = today(tzone = tzone), unit = "week")
110+
}
111+
112+
#' The previous week
113+
#'
114+
#' @export last_week
115+
#' @param tzone a character vector specifying which time zone you would like to
116+
#' find the previous week of. tzone defaults to the system time zone set on
117+
#' your computer.
118+
#' @return the previous week as a Date object
119+
last_week <- function(tzone = "") {
120+
floor_date(x = today(tzone = tzone), unit = "week") - weeks(1)
121+
}
122+
123+
#' The next week
124+
#'
125+
#' @export next_week
126+
#' @param tzone a character vector specifying which time zone you would like to
127+
#' find the next week of. tzone defaults to the system time zone set on your
128+
#' computer.
129+
#' @return the next month as a Date object
130+
next_week <- function(tzone = "") {
131+
floor_date(x = today(tzone = tzone), unit = "week") + weeks(1)
132+
}
133+
96134
#' Is x a weekend?
97135
#'
98136
#' @export is.weekend
@@ -130,5 +168,5 @@ is.weekday <- function(x) {
130168
#' @examples
131169
#' hms("2017-10-22 15:01:00")
132170
hms <- function(x) {
133-
hms::as.hms(strftime(x, format="%H:%M:%S"))
171+
hms::as.hms(strftime(x, format = "%H:%M:%S"))
134172
}

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11

22
<!-- README.md is generated from README.Rmd. Please edit that file -->
3-
lubridateExtras <img src="man/figures/logo.svg" align="right" height="120" width="139" />
4-
=========================================================================================
3+
4+
# lubridateExtras <img src="man/figures/logo.svg" align="right" height="120" width="139" />
55

66
Convenience functions for the lubridate package
77

88
<!-- Placeholder for build status, CRAN status, and coverage status -->
9-
Overview
10-
--------
119

12-
Lubridate makes it easier to work with date-time data in R and provides new capabilities. LubridateExtras builds on top of lubridate to provide a number of convenience functions, primarily focused on abstracting patterns in ways that improve code readability and reduce copying and pasting code.
10+
## Overview
11+
12+
Lubridate makes it easier to work with date-time data in R and provides
13+
new capabilities. LubridateExtras builds on top of lubridate to provide
14+
a number of convenience functions, primarily focused on abstracting
15+
patterns in ways that improve code readability and reduce copying and
16+
pasting code.
1317

14-
Installation
15-
------------
18+
## Installation
1619

1720
``` r
1821
# lubridateExtras is not currently on CRAN
@@ -21,33 +24,35 @@ Installation
2124
devtools::install_github("ellisvalentiner/lubridateExtras")
2225
```
2326

24-
If you encounter a clear bug, please file a minimal reproducible example on [github](https://github.com/ellisvalentiner/lubridateExtras/issues).
27+
If you encounter a clear bug, please file a minimal reproducible example
28+
on [github](https://github.com/ellisvalentiner/lubridateExtras/issues).
2529

26-
Usage
27-
-----
30+
## Usage
2831

2932
``` r
3033
library(lubridateExtras)
3134

3235
yesterday()
33-
#> [1] "2017-10-21"
36+
#> [1] "2018-02-20"
3437

3538
tomorrow()
36-
#> [1] "2017-10-23"
39+
#> [1] "2018-02-22"
3740

3841
days_ago(7) # equivalent to lubridate::today() - lubridate::days(7)
39-
#> [1] "2017-10-15"
42+
#> [1] "2018-02-14"
4043

4144
days_hence(7) # equivalent to lubridate::today() + lubridate::days(7)
42-
#> [1] "2017-10-29"
45+
#> [1] "2018-02-28"
4346

4447
hms("2017-10-22 15:33:00") # extracts the time-of-day component
4548
#> 15:33:00
4649
```
4750

48-
Why lubridateExtras?
49-
--------------------
51+
## Why lubridateExtras?
5052

5153
Some people are probably asking the question: why lubridateExtras?
5254

53-
lubridateExtras does not do anything that you cannot do with lubridate but similarly you don't need lubridate at all to work with date/times in R! If you like the syntactic sugar of lubridateExtras then use it, otherwise stick with what works for you.
55+
lubridateExtras does not do anything that you cannot do with lubridate
56+
but similarly you don’t need lubridate at all to work with date/times in
57+
R\! If you like the syntactic sugar of lubridateExtras then use it,
58+
otherwise stick with what works for you.

_pkgdown.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ navbar:
1919
right:
2020
- icon: fa-github fa-lg
2121
href: https://github.com/ellisvalentiner/lubridateExtras
22+
23+
reference:
24+
- title: similar functions
25+
contents:
26+
- yesterday
27+
- tomorrow

docs/articles/intro.html

Lines changed: 6 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.html

Lines changed: 26 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/news/index.html

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)